-
Notifications
You must be signed in to change notification settings - Fork 364
Pool and re-use web workers #782
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
Conversation
Make them long running
|
This is a huge improvement and saves a lot of disk space |
Since it’s general purpose and not bolt specific
|
For future reference: I've rewritten the original (PoC) implementation to a full blown web worker pool and focus the api on the work that are to be done rather than the web workers themselves. const createWorker = () => /* ... your create worker function */
const maxWorkers = 10
const pool = new WorkPool(createWorker, maxWorkers)
const payload = {type: 'TEST', data: {x: 1}}
const work = pool.doWork({id: 1, payload, onmessage: (msg) => {
// Handle response
work.finish() // You need to manually finish the work to release the worker
}})
// additional tricks
const work = pool.getWorkById(1) // Get access to work
work.finish() // cancels if it's in queue
work.onFinish(() => { console.log('finishing now') }) // Set a function to be called once worker is done
work.execute({type: 'SECOND_MESSAGE', data: {x: 2}}) // Post additional message to the worker that's doing the `work` |
| let connectionProperties = null | ||
| let boltWorkerRegister = {} | ||
| let cancellationRegister = {} | ||
| let boltWorkPool = new WorkPool(() => new BoltWorkerModule(), 10) |
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.
FYI if we choose to surface the worker pool as :config in the future we will probably need to only allow worker pools > 0 as a pool of 0 is always in a BUSY state
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.
Yeah, 0 would be infinite imo.
New ones won't be recreated as long as there are existing free ones anyway.
Pool and re-use web workers
This introduces a web worker pool (generic so it can be used for other expensive computations as well).
Currently the pool size for cypher queries is hard coded in https://github.com/neo4j/neo4j-browser/pull/782/files#diff-046ce42896ad79b95a44f41c7faa1f94R39
This could possibly be a user config in the future, if we see the need to for it.
If no worker is free, the jobs are queued and executed in order.
This can be tested by setting the max pool size to 1 and execute a long running query (this takes about 10 secs), like
on the movie data set and directly afterwards execute a few more. These will then wait with a spinner.
In the blob directory you'll only see one ww blob.
I've set the hard coded pool size to 10 for no particular reason. I've never hit that limit if I'm not hammering the keyboard with queries.
Try it
Open browser, open devtools ->
Application.Expand
OtherunderFrames.See all the uuid named blobs. That's ww (to verify, right click and show in network tab).
Before
After
changelog: Fix issue where neo4j-browser kept allocating more and more disk space