The first answers of unicorn workers are slower by a few seconds

I can't figure out how I can get my unicorns to accept only connections when they are really β€œready” to process the request. I find that the first few queries are slow, then they speed up dramatically (from a few seconds to a hundred or so). This problem seems to be compounded by the fact that the unicorn seems to be killing workers after a certain time, which means that I constantly run into the performance hit of the slow first request. Has anyone else seen this or had an idea of ​​what I can do?

+4
source share
1 answer

It turns out that our iML yml files, which are lazily loaded in views on first request, cause performance issues. Just adding the following to my config / unicorn.rb seems to fix the problem:

before_fork do |server, worker| # The following is highly recomended for Rails + "preload_app true" as # there no need for the master process to hold a connection. defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect! # No need to disconnect from Redis servers--they are connected to lazily. # Force translations to be loaded into memory. I18n.t('activerecord') end 
+6
source

Source: https://habr.com/ru/post/1443588/


All Articles