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 a way to recycle workers when heap limit is reached #56

Closed
sheremet-va opened this issue May 10, 2023 · 6 comments · Fixed by #58
Closed

Add a way to recycle workers when heap limit is reached #56

sheremet-va opened this issue May 10, 2023 · 6 comments · Fixed by #58
Labels
enhancement New feature or request

Comments

@sheremet-va
Copy link
Member

To implement vitest-dev/vitest#3203 we need a way to terminate a worker and start a new one in its place when the worker reached its memory limit. It's already possible to pass down resource limits to workers (this is a native feature), but they will fail the pool instead of recycling the worker.

@Aslemammad
Copy link
Member

Nice, Any example you got or a reproduction?

@sheremet-va
Copy link
Member Author

Nice, Any example you got or a reproduction?

This is a feature request. An example would be:

  • There is a pool of 5 workers
  • One of the workers gets to the maximum heap used
  • This worker is terminated and another one started to fill the gap

@Aslemammad
Copy link
Member

Ok, That's informative, thank you.

@Aslemammad Aslemammad added the enhancement New feature or request label May 10, 2023
@AriPerkkio
Copy link
Member

@sheremet-va have you thought about what kind of API Tinypool would provide for this option?

I'm just thinking that should there be a callback that is called when worker has finished the current task, and there user could do their own decisions whether a worker should be recycled or not. The API option would not mention heap or anything other as specific at all.

@sheremet-va
Copy link
Member Author

@sheremet-va have you thought about what kind of API Tinypool would provide for this option?

What I thought was just an option like maxMemoryLimitBeforeRecycle.

I'm just thinking that should there be a callback that is called when worker has finished the current task, and there user could do their own decisions whether a worker should be recycled or not. The API option would not mention heap or anything other as specific at all.

Sure, it does sound useful for some other cases, where you want to control when it happens, but the callback would be called in the main thread. This is a bit inconvenient because we will have to tell the main thread some additional information before deciding if worker should be recycled, since the memory information is available only inside the worker (which can create race conditions). The solution with maxMemoryLimitBeforeRecycle can be implemented simpler, I think.

@AriPerkkio
Copy link
Member

AriPerkkio commented May 25, 2023

but the callback would be called in the main thread

Right, and we cannot pass non-serializable data (functions) to workers. The maxMemoryLimitBeforeRecycle sounds simple and should be easy to implement. I'll take a look at this task.

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

Successfully merging a pull request may close this issue.

3 participants