-
Notifications
You must be signed in to change notification settings - Fork 107
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: support Atomics.waitAsync #687
Open
metcoder95
wants to merge
108
commits into
current
Choose a base branch
from
feat/async_atomics
base: current
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
108 commits
Select commit
Hold shift + click to select a range
2cf4b46
refactor: emit `drain` as soon as capacity is available (#367)
metcoder95 7b86105
refactor!: drop runTask method (#363)
metcoder95 b42bb14
chore(deps-dev): Bump @types/node from 20.6.0 to 20.6.2 (#406)
dependabot[bot] 4df0ca4
fix: add signal reason support (#403)
metcoder95 986659a
chore(deps): Bump actions/checkout from 3 to 4 (#413)
dependabot[bot] bf92e5a
chore(deps-dev): Bump @types/node from 20.6.2 to 20.8.2 (#417)
dependabot[bot] 352bc84
chore(deps-dev): Bump @types/node from 20.8.2 to 20.8.3 (#419)
dependabot[bot] a998a69
chore(deps): Bump @babel/traverse (#425)
dependabot[bot] 31f7a2b
fix: do not re-create threads when calling `.destory()` (#430)
alan-agius4 3d67926
chore(deps-dev): Bump @types/node from 20.8.3 to 20.8.7 (#428)
dependabot[bot] 5c2264c
fix: migrate to EventEmitterAsyncResource from core (#433)
groozin 69cae53
chore(deps): Bump actions/setup-node from 3 to 4 (#437)
dependabot[bot] 0cfa8d7
chore(deps-dev): Bump @types/node from 20.8.7 to 20.8.10 (#440)
dependabot[bot] c9e2abc
chore(deps-dev): Bump @typescript-eslint/parser from 6.9.1 to 6.10.0 …
dependabot[bot] ef6e205
chore(deps-dev): Bump @types/node from 20.8.10 to 20.9.0 (#443)
dependabot[bot] 1f85c16
chore(deps-dev): Bump @typescript-eslint/eslint-plugin from 6.9.1 to …
dependabot[bot] b7895b9
chore(release): 4.2.0
metcoder95 cc8fca5
chore(deps-dev): Bump @types/node from 20.9.0 to 20.9.2 (#448)
dependabot[bot] 4260e7e
chore(deps-dev): Bump @typescript-eslint/parser from 6.10.0 to 6.11.0…
dependabot[bot] 99ae84b
chore(deps-dev): Bump @typescript-eslint/eslint-plugin from 6.10.0 to…
dependabot[bot] 27cac34
chore(deps-dev): Bump @typescript-eslint/eslint-plugin from 6.11.0 to…
dependabot[bot] b6e2559
chore(deps-dev): Bump @typescript-eslint/parser from 6.11.0 to 6.12.0…
dependabot[bot] b08a78e
chore(deps-dev): Bump @types/node from 20.9.2 to 20.10.0 (#455)
dependabot[bot] be15076
chore(deps-dev): Bump typescript from 5.1.6 to 5.3.2 (#454)
dependabot[bot] a150938
fix: default minThreads with odd CPU count (#457)
Chocobozzz 6ea35db
chore(deps-dev): Bump @types/node from 20.10.0 to 20.10.4 (#466)
dependabot[bot] 41408c1
chore(deps-dev): Bump ts-node from 9.1.1 to 10.9.2 (#463)
dependabot[bot] 682a931
chore(release): 4.2.1
metcoder95 d30c6b3
chore(deps-dev): Bump @typescript-eslint/parser from 6.12.0 to 6.14.0…
dependabot[bot] 89ee83a
chore(deps-dev): Bump typescript from 5.3.2 to 5.3.3 (#464)
dependabot[bot] 8deb653
chore(deps-dev): Bump @typescript-eslint/eslint-plugin from 6.12.0 to…
dependabot[bot] 88b40d8
chore(deps): Bump @babel/traverse from 7.22.8 to 7.23.2 (#469)
dependabot[bot] 8dadd43
chore(deps-dev): Bump @types/node from 20.10.4 to 20.10.5 (#470)
dependabot[bot] d84adb3
chore(deps-dev): Bump @typescript-eslint/eslint-plugin from 6.14.0 to…
dependabot[bot] c1996d4
chore(deps-dev): Bump @typescript-eslint/parser from 6.14.0 to 6.16.0…
dependabot[bot] cff5414
chore(deps-dev): Bump @types/node from 20.10.5 to 20.10.6 (#476)
dependabot[bot] ef07d02
chore(deps-dev): Bump @typescript-eslint/eslint-plugin from 6.15.0 to…
dependabot[bot] 40b5e6b
chore(deps-dev): Bump @types/node from 20.10.6 to 20.10.7 (#479)
dependabot[bot] a3571fd
feat: use native Node.js histogram support (#482)
clydin e848054
chore(deps-dev): Bump @types/node from 20.11.0 to 20.11.1 (#485)
dependabot[bot] 79d7401
chore(release): 4.3.0
metcoder95 aabaa5b
chore(deps-dev): Bump @typescript-eslint/parser from 6.18.1 to 6.19.0…
dependabot[bot] 177a58d
chore: workflows: drop v16.x (#495)
RafaelGSS 6f4ef50
fix(#491): out of bounds histogram value (#496)
metcoder95 c1f533d
chore(release): 4.3.1
metcoder95 335e406
chore(deps-dev): Bump @typescript-eslint/eslint-plugin from 6.18.1 to…
dependabot[bot] be9e83b
fix(#513): forward errors correctly to Piscina (#514)
metcoder95 86a5b21
chore(release): 4.3.2
metcoder95 e0686f6
chore(deps-dev): Bump @types/node from 20.11.1 to 20.11.19 (#516)
dependabot[bot] 07b03eb
chore(deps): Bump actions/cache from 3 to 4 (#505)
dependabot[bot] 01726c3
feat: add option to disable run/wait time recording (#518)
clydin ff8dee0
feat: allow named import usage (#517)
clydin 683cda4
chore(release): 4.4.0
metcoder95 b2d7e62
chore(deps-dev): Bump @types/node from 20.11.19 to 20.11.24 (#524)
dependabot[bot] eb3008c
feat!: narrow TS types for histograms
metcoder95 2877294
chore: add v21.x to CI
metcoder95 b60d8ba
chore: adjust cache
metcoder95 4b391ac
chore: update package-lock.json
metcoder95 4bb872f
Merge remote-tracking branch 'origin/current' into next
metcoder95 57570c6
refactor: cleanups
metcoder95 6cbc507
fix: lint
metcoder95 7e40e2d
Merge remote-tracking branch 'origin/current' into next
metcoder95 d701046
fix: merge with current
metcoder95 144bd1c
feat!: set FixedQueue as default task queue (#578)
metcoder95 363b5af
docs: remove runtask references (#581)
metcoder95 3729907
feat!: drop v16 (#582)
metcoder95 2f58db9
feat: initial shape
metcoder95 e72310a
Merge branch 'next' into feat/custom_balancer
metcoder95 f9af8a4
feat: implement balancer
metcoder95 f2ad1a3
fix: onclose
metcoder95 22e9642
fix: smaller tweaks
metcoder95 c5946d1
Merge remote-tracking branch 'origin/current' into next
metcoder95 4417fc1
Merge remote-tracking branch 'origin/next' into feat/custom_balancer
metcoder95 93d9c52
test: fix
metcoder95 3634822
feat: add histogram to workers (#619)
metcoder95 176c399
feat: add state properties to worker (#620)
metcoder95 267bde4
Merge remote-tracking branch 'origin/current' into next
metcoder95 53e41f4
chore: reconcile lockfile
metcoder95 bbb684d
docs: update README
metcoder95 a828c8d
Merge remote-tracking branch 'origin/current' into next
metcoder95 a8447c0
fix: bad merge
metcoder95 b2463b7
Merge branch 'next' into feat/custom_balancer
metcoder95 f329b81
feat: pool events for workers (#624)
metcoder95 0dfc689
feat: add worker events to pool (#625)
metcoder95 65c81f8
Merge remote-tracking branch 'origin' into feat/custom_balancer
metcoder95 fe6968d
refactor: drop commands from balancer
metcoder95 93a1504
refactor: cleanup
metcoder95 bb0aceb
chore: fix lockfile
metcoder95 34e3ef2
refactor: Update src/index.ts
metcoder95 d82b8e2
fix: linting
metcoder95 6484ba8
Merge branch 'current' into feat/custom_balancer
metcoder95 d9a7b9f
refactor: use performance.now instead of process.hrtime
metcoder95 8714a6f
refactor: decouple shcheduling from distribution
metcoder95 27b1f84
refactor: small tweaks
metcoder95 750646c
types: adjust types and documentation
metcoder95 86f265e
docs: add documentation
metcoder95 4093dfa
Merge remote-tracking branch 'origin/current' into feat/custom_balancer
metcoder95 05dd04f
feat: Support Atomics.waitAsync
metcoder95 b550f5c
test: add testing
metcoder95 ba71411
fix: linting
metcoder95 bb6de93
chore: benchmarks
metcoder95 3f2d96a
fix: consume messages after wake up
metcoder95 19c7de0
refactor: await upon wake
metcoder95 ccda657
fix: lint
metcoder95 fdbc664
test: scope per platform
metcoder95 c8dd7e2
refactor: drop comments
metcoder95 c3b6fad
Merge remote-tracking branch 'origin/current' into feat/custom_balancer
metcoder95 bf45d08
Merge branch 'feat/custom_balancer' into feat/async_atomics
metcoder95 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict'; | ||
const { Piscina } = require('../dist'); | ||
const { resolve } = require('path'); | ||
|
||
async function simpleBenchmark ({ duration = 10000 } = {}) { | ||
const pool = new Piscina({ filename: resolve(__dirname, 'fixtures/add.js'), atomics: 'async' }); | ||
let done = 0; | ||
|
||
const results = []; | ||
const start = process.hrtime.bigint(); | ||
while (pool.queueSize === 0) { | ||
results.push(scheduleTasks()); | ||
} | ||
|
||
async function scheduleTasks () { | ||
while ((process.hrtime.bigint() - start) / 1_000_000n < duration) { | ||
await pool.run({ a: 4, b: 6 }); | ||
done++; | ||
} | ||
} | ||
|
||
await Promise.all(results); | ||
|
||
return done / duration * 1e3; | ||
} | ||
|
||
simpleBenchmark().then((opsPerSecond) => { | ||
console.log(`opsPerSecond: ${opsPerSecond} (with default taskQueue)`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
id: Custom Load Balancers | ||
sidebar_position: 2 | ||
--- | ||
|
||
[Load Balancers](https://www.cloudflare.com/learning/performance/what-is-load-balancing/) are a crucial part of any distributed workload. | ||
Piscina by default uses a [Resource Based](https://www.cloudflare.com/en-gb/learning/performance/types-of-load-balancing-algorithms/) algorithm (least-busy) | ||
to distribute the load across the different workers set by the pool. | ||
|
||
### Choosing the Load Balancing Algorithm | ||
|
||
Choosing the right algorithm heavily depends on the requirements of each individual problem, and to assess | ||
them by testing the implementation against several variations of workloads. | ||
|
||
The algorithms can be grouped on: | ||
|
||
#### Dynamic | ||
|
||
Focused on taking decision based on heuristics from the workload. | ||
|
||
It aims to balance the work by adapting itself to the environment and distribute the workloads equally across the different workers/nodes attempting to make better use | ||
of resources or to minimize the time to finish each individual workload. | ||
|
||
> Piscina uses a Dynamic algorithm, based on how busy the worker is (least-busy) | ||
|
||
#### Static | ||
|
||
Aims to distribute the workload based on a group of predefined factors. | ||
It does not adapt to the environment, but rather aims to preserve the state of the distribution accordingly | ||
to the values set beforehand. | ||
|
||
This can be helpful under several situations where we want the workload to be distributed evenly or stick to a specific worker/node over time. | ||
|
||
> Round Robin, Ring Hash, are just examples of these algorithms | ||
|
||
It is heavily advised to understand the problem and the workload your pool will be facing, and tests heavily against the different algorithms that matches your | ||
use case with several combinations to better understand its impact and how to manage it. | ||
|
||
### Resources | ||
|
||
- [Load Balancing Algorithms](https://en.wikipedia.org/wiki/Load_balancing_(computing)) | ||
- [Types of Load Balancing Algorithms](https://www.cloudflare.com/en-gb/learning/performance/types-of-load-balancing-algorithms/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can you explain the open handle thing? Why is that an issue with async?
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.
Mostly as we are not doing event loop ticks, these can add some overhead if the workers start doing more than it should.
Even waiting for just the worker to wake up added some ticks that showed a difference of ±5% which is really negligible.
I've not strong opinion in this one; but if we want to make this the default behaviour we should document that it is important to not keep the workers doing too much background tasks as they can face some penalty (as well if using
async
, implementer needs to account for the teardown of the worker when idle, i.e. no more tasks scheduled)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.
If that sounds good, I can adjust the PR for that 👍