Baldinof / roadrunner-bundle

A RoadRunner worker integrated in your Symfony app
MIT License
255 stars 46 forks source link

[FEATURE REQUEST] Add MaxJobsRebootStrategy reboot strategy #90

Closed iborysenko closed 1 year ago

iborysenko commented 1 year ago

Sometimes our application had memory-leaks, so we are tried to used native RR reboot strategy.

http:
  pool:
    max_jobs: 10000

But in loads RR rebooted all workers simultaneously, and first "warming requests" was too slow. So we implemented MaxJobsRebootStrategy to solve this issue

class MaxJobsRebootStrategy implements KernelRebootStrategyInterface
{
    private int $jobsCount = 0;
    private int $maxJobs;

    public function __construct(int $maxJobs, float $dispersion = 0.2)
    {
        $minJobs = $maxJobs - (int) round($maxJobs * $dispersion);
        $this->maxJobs = \random_int($minJobs, $maxJobs);
    }

    public function shouldReboot(): bool
    {
        if ($this->jobsCount < $this->maxJobs) {
            $this->jobsCount++;
            return false;
        }

        return true;
    }

    public function clear(): void
    {
    }
}
iborysenko commented 1 year ago

Hi @Baldinof Look like you abandoned this project?

Baldinof commented 1 year ago

Hey there!

Sorry, this issue totallty slipped of my inbox. I did not had a lot of time the last couple of mounth but this project is not abandonned.

In fact I have some ongoing work to add features, like Symfony Messenger integration with RR jobs ;)

For this issue, I think I would accept a PR adding this strategy, this seems to be a legit concern as you may want to clear the container while not stopping the PHP process.

iborysenko commented 1 year ago

@Baldinof Im working with RR jobs too, but without Symfony Messenger and partially refactored part of these package with Workers (JobsWorker, HttpWorker, GrpcWorker) i can create MR for this part maybe it will be useful for you

iborysenko commented 1 year ago

Added https://github.com/Baldinof/roadrunner-bundle/pull/92