Skip to content

Add resourceLimits support#21

Merged
jasnell merged 2 commits intomasterfrom
resource-limits
May 1, 2020
Merged

Add resourceLimits support#21
jasnell merged 2 commits intomasterfrom
resource-limits

Conversation

@jasnell
Copy link
Copy Markdown
Collaborator

@jasnell jasnell commented May 1, 2020

Fixes: #20

@jasnell
Copy link
Copy Markdown
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
Comment thread README.md Outdated
Comment thread src/index.ts
Comment thread src/index.ts Outdated
Comment thread test/fixtures/resource-limits.js Outdated
@addaleax
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread test/tsconfig.json Outdated
@jasnell
Copy link
Copy Markdown
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.

Comment thread README.md Outdated
Comment thread test/fixtures/resource-limits.js Outdated
Comment thread test/test-resourcelimits.ts Outdated
Comment thread examples/resourceLimits/worker.js Outdated
@addaleax
Copy link
Copy Markdown
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
Copy Markdown
Collaborator Author

jasnell commented May 1, 2020

hmm.. ok, that's fun lol

@addaleax
Copy link
Copy Markdown
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
Copy Markdown
Collaborator Author

jasnell commented May 1, 2020

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

@addaleax
Copy link
Copy Markdown
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
Copy Markdown
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 jasnell force-pushed the resource-limits branch from 7f98196 to eaea467 Compare May 1, 2020 22:16
@jasnell
Copy link
Copy Markdown
Collaborator Author

jasnell commented May 1, 2020

This is good to go 👍

@addaleax
Copy link
Copy Markdown
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
Copy Markdown
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