Skip to content

A platform for community discussion. Free, open, simple.

PERF: Stop copying the shared heap into the supervised Sidekiq (#44152)

Alan Guo Xiang Tana2d47f00483f
diff --git a/config/pitchfork.conf.rb b/config/pitchfork.conf.rb
index ea856268d89..9e79758f1bd 100644
--- a/config/pitchfork.conf.rb
+++ b/config/pitchfork.conf.rb
@@ -81,6 +81,7 @@ after_mold_fork do |server, mold|
Discourse.redis.close
DiscourseVips::Client.use_shared_worker
Discourse.before_fork
+ Process.warmup
end
oob_gc_enabled = ENV["DISCOURSE_DISABLE_MAJOR_GC_DURING_REQUESTS"] && RUBY_VERSION >= "3.4"
diff --git a/lib/demon/sidekiq.rb b/lib/demon/sidekiq.rb
index 938f055ab3b..8b26047c722 100644
--- a/lib/demon/sidekiq.rb
+++ b/lib/demon/sidekiq.rb
@@ -134,7 +134,10 @@ class Demon::Sidekiq < ::Demon::Base
cli.parse(options)
load Rails.root + "config/initializers/100-sidekiq.rb"
- cli.run
+
+ # This process inherits the heap warmed by the mold.
+ # Warming it again compacts it, copying every page shared with the parent.
+ cli.run(warmup: false)
rescue => error
log(
"Error encountered while starting Sidekiq: [#{error.class}] #{error.message}\n#{error.backtrace.join("\n")}",
diff --git a/lib/discourse.rb b/lib/discourse.rb
index ae47f57d0cc..7a9c22e9bea 100644
--- a/lib/discourse.rb
+++ b/lib/discourse.rb
@@ -1060,9 +1060,6 @@ module Discourse
# V8 does not support forking, make sure all contexts are disposed
ObjectSpace.each_object(MiniRacer::Context) { |c| c.dispose }
end
-
- # get rid of rubbish so we don't share it
- Process.warmup
end
# Called in web worker processes after fork to apply worker-specific
diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake
index a7e93bcb163..a8a0a2ba2cd 100644
--- a/lib/tasks/db.rake
+++ b/lib/tasks/db.rake
@@ -196,6 +196,7 @@ task "multisite:migrate" => %w[
database_shards = databases.each_slice(database_shard_size).to_a
Discourse.before_fork
+ Process.warmup
pids =
database_shards.map do |database_shard|