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 resourceLimits support #21

Merged
merged 2 commits into from
May 1, 2020
Merged

Add resourceLimits support #21

merged 2 commits into from
May 1, 2020

Conversation

jasnell
Copy link
Collaborator

@jasnell jasnell commented May 1, 2020

Fixes: #20

@jasnell
Copy link
Collaborator Author

jasnell commented May 1, 2020

@addaleax ... not entirely sure why but the resource limits are being rather flaky on macos here. Sometimes they run fine, next run they fail inconsistently across versions.

https://github.com/jasnell/piscina/pull/21/checks?check_run_id=637470841

@jasnell jasnell requested a review from addaleax May 1, 2020 20:33
README.md Outdated Show resolved Hide resolved
src/index.ts Show resolved Hide resolved
src/index.ts Outdated Show resolved Hide resolved
test/fixtures/resource-limits.js Outdated Show resolved Hide resolved
@addaleax
Copy link
Collaborator

addaleax commented May 1, 2020

@addaleax ... not entirely sure why but the resource limits are being rather flaky on macos here. Sometimes they run fine, next run they fail inconsistently across versions.

https://github.com/jasnell/piscina/pull/21/checks?check_run_id=637470841

Hm, odd … I’ll try to take a look at that, thanks for letting me know

@jasnell
Copy link
Collaborator Author

jasnell commented May 1, 2020

Ok, updated to use the resourceLimits object as suggested. The only thing now is that npm test is failing consistently now on the new test and really not sure why because the worker is triggering the error.

test/tsconfig.json Outdated Show resolved Hide resolved
@jasnell
Copy link
Collaborator Author

jasnell commented May 1, 2020

On that flaky failure, what it is looking like is that, at least sometimes, the error that's terminating the worker is not getting properly caught and routed to the task Promise.

README.md Outdated Show resolved Hide resolved
test/fixtures/resource-limits.js Outdated Show resolved Hide resolved
test/test-resourcelimits.ts Outdated Show resolved Hide resolved
examples/resourceLimits/worker.js Outdated Show resolved Hide resolved
@addaleax
Copy link
Collaborator

addaleax commented May 1, 2020

On that flaky failure, what it is looking like is that, at least sometimes, the error that's terminating the worker is not getting properly caught and routed to the task Promise.

I don’t think that’s what’s happening – the Promise is rejected, but because there was an 'error' event on the Worker, a new Worker is started, which also OOMs immediately, and then generates an 'error' event on the Piscina instance itself because there is no task associated with that second worker

@jasnell
Copy link
Collaborator Author

jasnell commented May 1, 2020

hmm.. ok, that's fun lol

@addaleax
Copy link
Collaborator

addaleax commented May 1, 2020

Right. We could probably try to detect this in some way, but given that rejected Promises and an 'error' event on the Piscina instance are probably the right results for this kind of situation, I think we don’t need to. The only thing we could do is add the thread id to the error message to indicate that the errors come from different Worker instances

@jasnell
Copy link
Collaborator Author

jasnell commented May 1, 2020

and for this particular case, attach an 'error' handler to the Piscina instance...?

@addaleax
Copy link
Collaborator

addaleax commented May 1, 2020

@jasnell For the test, I’d just increase the limits. Alternatively, we could also enable forwarding things like env and execArgv to the Worker constructor – setting execArgv: [] should also fix this (because it removes the TS hook from the list of preloaded modules).

@jasnell
Copy link
Collaborator Author

jasnell commented May 1, 2020

For now, I'll just add the error event handler rather than trying to hunt for limit values that will work consistently. Having the ability to set env and execArgv on the piscina constructor and having those forward on would be good in a separate PR.

@jasnell
Copy link
Collaborator Author

jasnell commented May 1, 2020

This is good to go 👍

@addaleax
Copy link
Collaborator

addaleax commented May 1, 2020

@jasnell There’s #21 (review) but if you want you can merge this and I’ll push those changes separately

@jasnell
Copy link
Collaborator Author

jasnell commented May 1, 2020

Yeah, I had just spotted those :-)

@jasnell jasnell merged commit 0f07f07 into master May 1, 2020
@jasnell jasnell deleted the resource-limits branch May 1, 2020 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: Worker Thread resource limits
2 participants