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

feat: Custom Balancer #590

Merged
merged 98 commits into from
Nov 5, 2024
Merged

feat: Custom Balancer #590

merged 98 commits into from
Nov 5, 2024

Conversation

metcoder95
Copy link
Member

@metcoder95 metcoder95 commented Jun 12, 2024

metcoder95 and others added 30 commits September 13, 2023 12:59
Co-authored-by: Robert Nagy <ronagy@icloud.com>
… 6.12.0 (#453)

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@@ -87,12 +89,25 @@ export class TaskInfo extends AsyncResource implements Task {

this.filename = filename;
this.name = name;
// TODO: This should not be global

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it should a UUID to avoid overflow.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, do you see a need for universal uniqueness?

My first idea was to provide a simple counter that limits to the SMI optimization and re-starts; maybe in combination with the Worker ID; and if need for enabling more complex use-cases ask the caller to provide an ID generator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High rate tasks submission workload could overflow it if no restart is done since months. Isn't the task execution counting already done via histogram?
Can it also overflow?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, but do we would need to track down every task individually for more than 30 days? I imagine that maybe you'll like it for debugging purposes, but not sure how much after that.

For that, caller should implement a custom solution that fits its use case; I'd like to provide a good defaults with less overhead and allow extensibility.

Isn't the task execution counting already done via histogram?
Can it also overflow?

Noup. I imagine the task id just for debugging purposes, beyond that I don't see much of a use for it.

src/index.ts Outdated
// We spawn if possible
// TODO: scheduler will intercept this.
if (this.workers.size < this.options.maxThreads) {
this._addNewWorker();
Copy link

@jerome-benoit jerome-benoit Oct 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is the worker histogram initialized in that case?
If a balancer query the runtime and that is initialized to zero, the balancer will wrongly pickup only new workers.
The same goes for worker recreation in the error case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For each new worker, the histogram is instantiated to zero, but the whole WorkerPool has a global histogram that can be queried.

Nevertheless, to query it, you need to have a reference to the Worker Pool (Piscina instance). Maybe worth it to pass a reference to the global Piscina instance so it can query this data

Copy link

@jerome-benoit jerome-benoit Oct 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe. Or you can initialize to the pool one if it's not a cumulative histogram.
On poolifier, each entries init to the min of worker matching entries.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be useful, I'll follow that path; thanks!

@@ -424,9 +498,9 @@ class ThreadPool {
filename = maybeFileURLToPath(filename);

let signal: AbortSignalAny | null;
if (this.closingUp) {
if (this.closingUp || this.destroying) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference between closingUp and destroying flag? I think the two can be merged.

src/index.ts Outdated Show resolved Hide resolved
src/index.ts Outdated Show resolved Hide resolved
src/worker.ts Outdated Show resolved Hide resolved
src/worker.ts Outdated Show resolved Hide resolved
src/worker.ts Outdated Show resolved Hide resolved
@metcoder95
Copy link
Member Author

Thanks for the feedback @jerome-benoit, I'll kick-off the second round along the week

@metcoder95
Copy link
Member Author

@ronag I've updated the docs, feel free to take a look now 👍

@metcoder95 metcoder95 linked an issue Oct 30, 2024 that may be closed by this pull request
@metcoder95 metcoder95 force-pushed the feat/custom_balancer branch from 48b898e to 4093dfa Compare October 30, 2024 09:12
@jerome-benoit
Copy link

jerome-benoit commented Oct 30, 2024

@ronag I've updated the docs, feel free to take a look now 👍

If you are sure that no regressions are introduced by that PR, you should merge it and flag load balancer feature as experimental. Then do an alpha or beta or ... release and communicate about it to allow people to play with it and do feedbacks.

@metcoder95
Copy link
Member Author

metcoder95 commented Oct 31, 2024

Agree, that's the plan. After this is merged, I'll start issuing alpha of the new version of the library to start gathering feedback and allow people use it.

I'll reflect this in the documentation of this PR

@metcoder95
Copy link
Member Author

I'm merging now, if there's more feedback please write it here, I'll be iterating over it in upcoming PRs

Let's land and release some alpha release of the new version to get some feedback; once the Atomics implementation is also merged, I'll release the version.

@metcoder95 metcoder95 merged commit 5c42b28 into current Nov 5, 2024
10 checks passed
@metcoder95 metcoder95 deleted the feat/custom_balancer branch November 5, 2024 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

More customisable scheduling
9 participants