mirror of
https://github.com/discourse/discourse.git
synced 2024-11-28 01:54:04 +08:00
038a38ae1c
These scripts are somewhat rough but I needed them to help debug a memory leak we have noticed in rails 6. The biggest object script finds all the biggest objects we have in memory after boot. The test memory leak runs a very simple iteration through all multisites and observed memory.
37 lines
1009 B
Ruby
37 lines
1009 B
Ruby
# frozen_string_literal: true
|
|
|
|
# simple script to measure largest objects in memory post boot
|
|
|
|
if ENV['RAILS_ENV'] != "production"
|
|
exec "RAILS_ENV=production ruby #{__FILE__}"
|
|
end
|
|
|
|
require 'objspace'
|
|
|
|
ObjectSpace.trace_object_allocations do
|
|
|
|
require File.expand_path("../../config/environment", __FILE__)
|
|
|
|
Rails.application.routes.recognize_path('abc') rescue nil
|
|
|
|
# load up the yaml for the localization bits, in master process
|
|
I18n.t(:posts)
|
|
|
|
RailsMultisite::ConnectionManagement.each_connection do
|
|
(ActiveRecord::Base.connection.tables - %w[schema_migrations versions]).each do |table|
|
|
table.classify.constantize.first rescue nil
|
|
end
|
|
end
|
|
|
|
end
|
|
|
|
5.times do
|
|
GC.start(full_mark: true, immediate_sweep: true)
|
|
end
|
|
|
|
[String, Array, Hash].each do |klass|
|
|
ObjectSpace.each_object(klass).sort { |a, b| b.length <=> a.length }.first(50).each do |obj|
|
|
puts "#{klass} size: #{obj.length} #{ObjectSpace.allocation_sourcefile(obj)} #{ObjectSpace.allocation_sourceline(obj)}"
|
|
end
|
|
end
|