-
Notifications
You must be signed in to change notification settings - Fork 120
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
Added default value to maximumUsage in Scheduler #507
Added default value to maximumUsage in Scheduler #507
Conversation
Added default value to maximumUsage Fixes: piscinajs#497
Also, |
@@ -66,10 +67,14 @@ class DefaultTaskScheduler extends TaskScheduler { | |||
#maximumUsage: number; | |||
#onAvailableListeners: ((item: PiscinaWorker) => void)[]; | |||
|
|||
constructor (maximumUsage: number) { | |||
constructor (maximumUsage: number = os.availableParallelism()) { |
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.
Although we do not have the matrix anymore, we still officially support v16; so feel free to do a check over the Node version running and only get the value if the os.availableParallelism
is available.
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.
So in case the version is less than 16, what should this default to? There is os.cpus()
that almost does the same, do we default to the length of that, or some other number?
super(maximumUsage); | ||
this.#maximumUsage = maximumUsage; | ||
this.#onAvailableListeners = []; | ||
|
||
if (maximumUsage > os.availableParallelism()) { | ||
console.warn(`Warning: maximumUsage (${maximumUsage}) is greater than available CPU cores (${os.availableParallelism()}).`); |
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.
Feel free to use https://www.npmjs.com/package/process-warning instead, has better ergonomics for these kind of situations
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.
Sure.
Let's also add a note in the documentation about this 👍 |
Oh, my bad, I didn't notice you were working on top of my PR; let's aim first for the So, for the current version, we should seek to use it whenever we want to get the max amount of threads if this option has not been passed through the constructor; so we can change it here: Line 33 in a7042ea
If the function is not available because it's being run under The The warning, let's keep it but just port it to how is used within the current version of Piscina 👍 |
Right, got it! |
This issue has been marked as stale because it has been opened 45 days without activity. Remove stale label or comment or this will be closed in 10 days. |
This PR was closed because it has been stalled for 10 days with no activity. |
Added default value to maximumUsage
Fixes: #497
Something to do:
What if
maximumUsage > os.availableParallelism()
?