0

I have a bizarre issue with my Rails 4.1.4 app running on multiple Puma instances. The app has an API that is hit by other systems in an SOA architecture. We have a high-traffic system and it receives many calls. If, when starting the app, we have clients calling one of our endpoints (called track), then it seems like some of the Puma workers don't load classes into memory properly and we start getting errors like:

FATAL -- :  
AbstractController::ActionNotFound (The action 'track' could not be found for ArticlesController):
  vendor/bundle/ruby/1.9.1/gems/actionpack-4.1.4/lib/abstract_controller/base.rb:131:in `process'
  vendor/bundle/ruby/1.9.1/gems/actionview-4.1.4/lib/action_view/rendering.rb:30:in `process'

and...

FATAL -- : 
AbstractController::ActionNotFound (The action 'find' could not be found for MatchesController):
  vendor/bundle/ruby/1.9.1/gems/actionpack-4.1.4/lib/abstract_controller/base.rb:131:in `process'
  vendor/bundle/ruby/1.9.1/gems/actionview-4.1.4/lib/action_view/rendering.rb:30:in `process'

Note that the track event is only on the ArticlesController, but something is happening to where it can't make requests against any controller once we get into this situation.

If I disable calls to the track endpoint from the clients and I bounce my app, everything works fine. If I wait until the system comes up and turn on the track calls again, then everything is still fine.

The problem only occurs when the track calls are being made during app boot time.

I don't know what info to provide to help diagnose this problem. I'll add more details to the question if anybody has a hunch on how to approach debugging this.

Javid Jamae
  • 8,741
  • 4
  • 47
  • 62
  • 1
    Just a hunch, maybe try eager loading your controllers: http://blog.plataformatec.com.br/2012/08/eager-loading-for-greater-good/ – DiegoSalazar Dec 22 '14 at 22:33

1 Answers1

0

I'm not sure what the underlying problem is, but it seems to have something to do with lack of thread safety during application boot strapping. The bandaid solution to avoid these error is to configure Puma to use 1 thread per worker.

Here are the contents of my config/puma.rb:

Before

...
threads 1,2
workers 6
preload_app!

After -

...
threads 1,1
workers 12
preload_app!

This works, but unfortunately, it kinda defeats the purpose of using a server that supports threading.

Javid Jamae
  • 8,741
  • 4
  • 47
  • 62