Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Killing multiple workers on each iteration of reaper, if needed #104

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jeffsaremi
Copy link

Current reap() method picks only one single puma worker and terminates that to free memory. However, in many cases, this would not be sufficient to bring the total memory to under max_ram. And then the system would have to wait for the subsequent cycles for this to happen.

This is not very optimal. In this proposed change, in each cycle, enough workers will be selected and terminated until the total consumed memory by puma is below the desired threshold.

The log outputs have slightly changed to indicate this. Example:

[5447] PumaWorkerKiller: Out of memory. 10 workers consuming total: 6500.63671875 mb out of max: 1980.0 mb. Releasing 4729.95703125 mb from 8 workers.
        Sending TERM to pid 5469 consuming 591.75390625 mb.
        Sending TERM to pid 5478 consuming 591.63671875 mb.
        Sending TERM to pid 5473 consuming 591.59375 mb.
        Sending TERM to pid 5471 consuming 591.3515625 mb.
        Sending TERM to pid 5547 consuming 591.171875 mb.
        Sending TERM to pid 5545 consuming 590.98046875 mb.
        Sending TERM to pid 5549 consuming 590.88671875 mb.
        Sending TERM to pid 5623 consuming 590.58203125 mb.

@schneems
Copy link
Member

Seems like a good idea. Is this original code tested? I would like to encode this expected behavior in a test.

@jeffsaremi
Copy link
Author

Seems like a good idea. Is this original code tested? I would like to encode this expected behavior in a test.

Hi, thank you! I have tested this on my desktop. I added a simple grep test to one of the tests. I also debug printed the spawn log and I could see that it was killing multiple workers at a time. I wasn't able to write a more comprehensive test. Sorry I'm still new to ruby.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants