mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 03:41:12 +08:00
DEV: add debugging scripts for memory leaks
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.
This commit is contained in:
36
script/biggest_objects.rb
Normal file
36
script/biggest_objects.rb
Normal file
@ -0,0 +1,36 @@
|
||||
# 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
|
Reference in New Issue
Block a user