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

Add workers lifetime option #372

Merged
merged 2 commits into from
Aug 31, 2024
Merged

Add workers lifetime option #372

merged 2 commits into from
Aug 31, 2024

Conversation

gi0baro
Copy link
Member

@gi0baro gi0baro commented Aug 4, 2024

No description provided.

@gi0baro gi0baro added this to the 1.6 milestone Aug 4, 2024
@Zerotask
Copy link

That's a really nice addition. If I may suggest, could you also add another option for The maximum amount of requests a worker will be kept alive before respawn (#34)

@gi0baro gi0baro marked this pull request as ready for review August 31, 2024 16:26
@gi0baro gi0baro merged commit 2c98230 into master Aug 31, 2024
18 of 19 checks passed
@gi0baro gi0baro deleted the workers-lifetime branch August 31, 2024 16:28
@mikeckennedy
Copy link

mikeckennedy commented Sep 4, 2024

Hey @gi0baro this is great. I've been waiting for this feature.

One enhancement that I think would be really good, would be to add a jitter across workers.

Suppose you have 8 workers and set the restart time to 86,400 (1 day). After one day, as far as I can see, it will stop and restart all 8 workers at roughly the same time. I would much rather have a little bit of time between them to avoid the jarring effect of a complete restart happening all at once.

Could we get something like a --workers-lifetime-jitter which would allow us to specify an interval to vary the restart across.

For example: --workers-lifetime-jitter 60 would have the workers restart across 60 seconds rather than all at once or just each one restart based on random(0, 60) seconds from when it started.

Anything like this would be good I think (unless there is a default I didn't see in there somewhere).

@gi0baro
Copy link
Member Author

gi0baro commented Sep 4, 2024

Hey @mikeckennedy 👋

The --workers-lifetime uses the respawn strategy, so it will respawn all the expired workers sequentially (starting the new one) respecting the --respawn-interval option (then shutting down the old one).
So if you just want to wait for a certain amount of time between the workers respawn, you can tune the --respawn-interval option. Eg: setting --workers-lifetime 86400 --respawn-interval 30 will effectively make Granian wait 30 seconds before shutting down the old worker and thus proceed with the respawn of the next one.

Does this work for your use-case?

@mikeckennedy
Copy link

@gi0baro Perfect, that's more than enough for me. Thanks!

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.

3 participants