-
Notifications
You must be signed in to change notification settings - Fork 33
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
Let the user choose worker implementation #64
Conversation
This one is failing in a few configurations, but does not reproduce locally so far:
need to look into it... |
That is because minWorkers default is 0, so pool is immieadtly ready, but test passes in thread scenario becuase the uptime is coming from parent process.
I think I should bring the Transport from v1, I will work on it later today. |
it seems that only windows is affected ;) |
nice! |
We can't assume it's started immediately availible for work. Also the lazy init test used a noop which can execute quickly on 2 workers without the need to start more, depending on the impl. By using a longer task we force the pool to start more workers.
Because node's spawn() implementation is broken on windows Ref: nodejs/node#14046 https://github.com/mcollina/autocannon/pull/145/files
package.json
Outdated
@@ -1,5 +1,6 @@ | |||
{ | |||
"name": "worker-nodes", | |||
"version": "2.5.0-alpha", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this version before releasing new one ;) for testing npm link should use 0.0.0 version - if that was the matter ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm running that on our project's CI, so I'm installing it via yarn like so:
yarn add worker-nodes@yurynix/node-worker-nodes#8010dc0fbc322c2022a057f758fa9207363ebceb
and then pushing to github for the CI to run.
yarn add
from github fails if there is no version
field unfortunately, due npm pack
failing behind the scenes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I'll think how to handle this
ready for review? :) |
@bgalek soon 🙏 I'll comment here, ok? |
|
||
const EXIT_WAIT_TIME_MS = 200; | ||
|
||
const execArgsProcessor = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comes from v1, haven't wrote that myself.
} | ||
}; | ||
|
||
function createChannel(workerId, onConnect) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's adaptation from:
https://github.com/mcollina/autocannon/pull/145/files
because of
nodejs/node#14046
To make Windows work.
const BUFFER_INITIAL_SIZE = 1024 * 1024; // 1MB | ||
const BUFFER_GROW_RATIO = 1.5; | ||
|
||
class Transport extends EventEmitter { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's from v1 as well
Identify workers by their apropriate identifier
@@ -252,28 +252,15 @@ class WorkerNodes extends EventEmitter { | |||
* @returns {Worker} | |||
*/ | |||
pickWorker() { | |||
if (this.options.lazyStart) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell, lazyStart
only matters for startup,
i.e. do we start up to minWorkers
or maxWorkers
, so IMO this block can be simplified.
Also previous code would break if the worker took time to startup, that is because the called of pickWorker()
in the lazyStart
option would receive a worker that was not yet isProcessAlive
(line 259 & 263) and would try to dispatch work to it in processQueue
:
const worker = this.pickWorker();
if (worker) {
this.dispatchTaskTo(worker);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, that wasn't entirely true, but it still can be simplified to:
if (this.canStartWorker() && (!this.options.lazyStart || !worker)) {
this.startWorker();
}
@bgalek now I think it's ready for review 🙃 I've also ran E2Es with it on our project ( |
Hey @bgalek 👋 |
@yurynix LGTM, do You want to release it today so you can update it before your vacation? :) |
Thank you for taking the time to review that 🙏 |
Hi 👋
In this PR, we let the user choose worker implementation, either default
thread
(usingworker_threads
) orprocess
(usingchild_process.fork()
). Closes #63Other notable changes:
workerType
argument, so the tests will run for both implementations, all theUint8Array
tests are hard-coded tothread
implementation, so areresource-limits
tests, which is a worker_threads concept.exit
message, since it's event loop was busy with thewhile(true);
, I've added a timer to handle that.I chose the value 2 (don't have a reason why 2 🙃 )concurrency 1 seems more stable on CI.Let me know what you think 🙃