DEV: Add performance warning message when running `rails s` (#12912)

DEV: Add performance warning message when running rails s (#12912)

In Discourse, rails s ultimately launches the bin/unicorn script. However, the overhead of rails launching bin/rails, and then in turn bin/unicorn can be non-trivial. Therefore it is much better to run bin/unicorn directly.

This commit prints a warning message to STDERR when rails s is used. Functionality is unchanged.

diff --git a/bin/rails b/bin/rails
index cdc2c4c..f95c528 100755
--- a/bin/rails
+++ b/bin/rails
@@ -9,6 +9,18 @@ if !ENV["RAILS_ENV"] && (ARGV[0] == "s" || ARGV[0] == "server")
+    --------
+    WARNING: Discourse uses `bin/unicorn` to start the web server.
+    For backwards compatibility, `rails s` will do this automatically.
+    For improved performance you should run `bin/unicorn` directly.
+    Running:
+    --------
   exec File.expand_path("unicorn", __dir__)

GitHub sha: 0188d53f

1 Like

This commit appears in #12912 which was approved by CvX. It was merged by davidtaylorhq.

Will this change print a message unconditionally? I don’t think rails s or even rails server should be considered deprecated at all when the commands are used extensively in the Rails guide.

1 Like

Yes it will print the warning unconditionally, but everything will still work as before. I don’t think I would consider it “deprecated” - we’re not planning to remove rails s support. We’re just recommending a better alternative.

rails s is at least 1 second slower to boot than /bin/unicorn. So I think, for Discourse, it’s good to let people know so that they can switch to the faster command.

Hmm any idea why it is one second slower? I still prefer to run rails s and having a message print o it every time is not ideal IMO.

rails s will launch bin/rails, which then launches bin/unicorn. That means we have to wait for Ruby/bundled to start from scratch 3 times. On my machine it takes 0.5s to boot Ruby/Bundler, so doing that twice gives us the 1s slowdown.

Hmm how does rails s launch bin/rails? I thought we were always calling the bin/rails ruby script directly.

Many people have been doing bundle exec rails. This will then launch bin/rails