adam k <adam.ffa at gmail.com> wrote:> I''m running unicorn behind nginx. If the site isn''t
accessed for a
> long period of time, the next access of the site is loads very slowly,
> sometimes even a 404 error shows. Subsequent requests have a normal
> loading time until the site isn''t accessed for a long period of
time
> again. How do I stop this behavior?
unicorn is likely getting swapped out or a backend connection
(e.g. database connection) is getting timed out due to
inactivity.
* How much memory (RSS) is each worker using when the site is active?
* Is RSS noticeably lower when the site''s been idle for a long time?
* How many unicorn worker processes?
(the above 3 questions also apply to nginx, but nginx usually uses
much less memory than unicorn)
* How much physical RAM do you have?
* What is the timeout value of unicorn? (default is 60s)
* What else is running on the machine?
* Anything mentioned in the unicorn stderr logs, or your application logs?
The updatedb cronjob is one major culprit of causing apps to swap out,
but it could be any number of things (backup jobs, rootkit scanners,
prelink, ...).
Try setting up a cronjob run curl to hit an endpoint of your app
every few minutes. Make sure that endpoint exercises whatever
non-local dependencies (hits the DB, etc...) your app has.
> I looked at the code for unicorn and it seems to happen when unicorn
> is looking to kill "lazy" workers and then if it chooses not to,
it
> creates a sleep period based on a timeout + 1. I also read the
> documentation and searched the mailing list starting from 2011.
I think you''re looking at the master process, which shouldn''t
affect performance of the workers. The workers wake up whenever
there''s socket activity, but it can take longer if they''re
swapped
out.