Resource and / or memory leaks and fragmentation are common problems in all programming languages. It doesn't matter if there is a garbage collector there or not, a compiled language or an interpreted one. Ruby is no exception, and today we will talk a little about these problems, options for solving them, and even write our own.
The problem can and does appear when we have a process running for a long time and doing a lot of different work. Most of these problems are related to errors in the code, whereby the code continues to perform its business function quite correctly. They are not always easy to find and fix. But memory fragmentation awaits us a little from the other side, and even correct code can gradually accumulate fragmented memory. In the world of Rails processes that fall under the category of "long-playing" are, in fact, a web server and various management background / pending tasks -β DelayedJob
, Sidekiq
etc. That's about them and then we'll talk..
Web server
ββ . /, (puma, unicorn), Phusion Passenger . ββ -, Rails-. , :
https://about.gitlab.com/blog/2015/06/05/how-gitlab-uses-unicorn-and-unicorn-worker-killer/
https://github.com/schneems/puma_worker_killer
https://docs.gitlab.com/ee/administration/operations/sidekiq_memory_killer.html
, ββ βββ . βββ βββ. βββ Passenger Enterprise .
- , DelayedJob
, ActiveJob
( β β ). βββ βββ . Sidekiq
, DelayedJob
!
- DelayedJob
WorkerKiller
βββ!
?
middleware
, , .
CPU, . βββ , , , β"βββ Limiter
.
βββ Killer
. unicornβ
ββ SIGTERM. βββ , Passenger Master Process . , , βinflightβ . , :
passenger-config detach-process <PID>
, 500 , 100. Passenger βββ -, , .
!
-, , , - DelayedJob
. , , .
!
? WorkerKiller ? , . βββ , , , . βββ , .
, :
-
-
-
How to count memory in Linux β- only for real men
Killer for unicorn β- he was the first!
-