Hey, everybody!
I have a side project of getting my first proper Rails app up to date. The last time I touched the project was about six years ago. Ruby, Rails, and all the other gems are out of date. I'm trying to be sensible and "safe" in my approach to each upgrade. This is more of an exercise in approach than anything else. The repo is public for folks who want to have a look.
After a chat with Will at the previous NWRUG, I decided to fix any warnings before moving on. This is a sensible and logical plan. The latest thing on my list is this list of warnings from Puma.
07:33:22 web.1 | [25567] ! WARNING: Detected 5 Thread(s) started in app boot:
07:33:22 web.1 | [25567] ! #<Thread:0x000000013acd2090@/Users/purinkle/.asdf/installs/ruby/2.5.9/lib/ruby/gems/2.5.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:300 sleep> - /Users/purinkle/.asdf/installs/ruby/2.5.9/lib/ruby/gems/2.5.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:302:in `sleep'
07:33:22 web.1 | [25567] ! #<Thread:0x000000013d392360@listen-wait_thread@/Users/purinkle/.asdf/installs/ruby/2.5.9/lib/ruby/gems/2.5.0/gems/listen-3.8.0/lib/listen/thread.rb:17 sleep_forever> - /Users/purinkle/.asdf/installs/ruby/2.5.9/lib/ruby/2.5.0/forwardable.rb:229:in `pop'
07:33:22 web.1 | [25567] ! #<Thread:0x000000013b7d1ba8@listen-worker_thread@/Users/purinkle/.asdf/installs/ruby/2.5.9/lib/ruby/gems/2.5.0/gems/listen-3.8.0/lib/listen/thread.rb:17 sleep> - /Users/purinkle/.asdf/installs/ruby/2.5.9/lib/ruby/gems/2.5.0/gems/rb-fsevent-0.11.2/lib/rb-fsevent/fsevent.rb:44:in `select'
07:33:22 web.1 | [25567] ! #<Thread:0x000000013bef6b90@listen-run_thread@/Users/purinkle/.asdf/installs/ruby/2.5.9/lib/ruby/gems/2.5.0/gems/listen-3.8.0/lib/listen/thread.rb:17 sleep> - /Users/purinkle/.asdf/installs/ruby/2.5.9/lib/ruby/gems/2.5.0/gems/listen-3.8.0/lib/listen/record/entry.rb:44:in `realpath'
07:33:22 web.1 | [25567] ! #<Thread:0x000000013bef46b0@listen-wait_thread@/Users/purinkle/.asdf/installs/ruby/2.5.9/lib/ruby/gems/2.5.0/gems/listen-3.8.0/lib/listen/thread.rb:17 sleep_forever> - /Users/purinkle/.asdf/installs/ruby/2.5.9/lib/ruby/2.5.0/forwardable.rb:229:in `pop'
I only see these warnings when I start the server using heroku local. If I start the server using rails s, then everything is okay.
There is no pressure here; I want to use this repo as a learning space. I want to understand the problem more than anything else. Is this something that I can fix? Is it something that a future gem bump will fix? How would you approach debugging this problem?
—Rob
WARNING: Detected 5 Thread(s) started in app boot:
--
You received this message because you are subscribed to the Google Groups "North West Ruby User Group (NWRUG)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nwrug-member...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/nwrug-members/eb3ea539-eee2-49ce-a378-e9eb6e74ccb5n%40googlegroups.com.
Thank you both for your comments.
Much of what Lee said went over my head and made me realise how little I know about Puma. I have always accepted that it's the tool to use since it gained popularity. Some stuff went in, but now I want to learn more.
After Tekin's comments about rails s, I did some more investigating and was wrong. Running rails s produces no warnings. Running bundle exec puma as per the Procfile gives warnings, though.
Puma loads the config/puma.rb file by default. I combed through that file and commented out lines until the warnings disappeared. The offending line has something to do with workers. If I set the value to zero, then the warnings disappear.
I set the number of workers from environment variables. When we have no value set, it defaults to two workers. I have this value set to zero in my .env file. I thought it might be that I was using 0, and the environment saw this as no value set. I tried setting it to "0", but still no dice. It was time for a trusty raise. No matter what value I put in .env, there was nothing in my error. Weird.
Then, I found this question on Stack Overflow. It makes sense that we load dotenv after Puma. The gem is part of the Rails stack, after all. What could I do?
My next step was to create a separate Procfile.dev with the following line and a bin/dev wrapper.
web: WEB_CONCURRENCY=0 bundle exec puma -p $PORT -C ./config/puma.rb
This approach seems like it could be better. I'll have to duplicate the commands between my two files and now use bin/dev to start my server. With the extra information I've provided, can anybody give a better solution?
You make some excellent points, Will. Your approach is something I will consider over the longer term. I plan to pinch these lines from Rails' default Puma config. People more intelligent than me have already solved the problem.
In all Unix and Unix-like systems, as well as on Windows, each process has its own separate set of environment variables. By default, when a process is created, it inherits a duplicate run-time environment of its parent process, except for explicit changes made by the parent when it creates the child. At the API level, these changes must be done between runningfork
andexec
. Alternatively, from command shells such as bash, a user can change environment variables for a particular command invocation by indirectly invoking it viaenv
or using theENVIRONMENT_VARIABLE=VALUE <command>
notation. A running program can access the values of environment variables for configuration purposes.
-- https://en.wikipedia.org/wiki/Environment_variable
--
You received this message because you are subscribed to the Google Groups "North West Ruby User Group (NWRUG)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nwrug-member...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/nwrug-members/32bb2225-1a24-43ca-803b-52173fe2649fn%40googlegroups.com.
It may be the Baader-Meinhof effect, but I've seen more mentions of direnv over the last day than I have ever before. I've added a card to my backlog to investigate swapping out dotenv.
Thank you all for all your help. You've pointed me in the right direction.
If any of you wanted to give a talk at NWRUG about Puma I would love it. If you wanted to explain Puma to me, I would love to give that talk to aid my learning.