Comments (5)
I don't believe you can pass a function to the worker, however I'd happily be proven wrong by a PR as this seems a useful addition :-) Upon review we can decide if it makes sense to be part of it or outside of it. Good plan?
from readdir-cluster.
Yep, the documentation mentions JSON, and I can confirm that functions do not survive transit:
https://nodejs.org/api/child_process.html#child_process_event_message
a parsed JSON object or primitive value
I'm playing with some other ideas...
from readdir-cluster.
Okay, so eval()
is obviously a non-starter, but I found that I can pass a filePath, and have the worker require()
it on the other side. If there is valid JavaScript in the content found at that filePath, and it exports a function, then the worker has no trouble executing it.
I'm not sure this makes sense for your project, and it might even be valuable turning it into a generic cluster-powered iterator. Thanks for the rubber-duck debugging, anyhow. :)
I'll close this unless you really want a PR for this idea.
Side note: you may not necessarily need to use the cluster module, as you don't need port-level load-balancing for this (as you don't even open ports). I wonder if just using the childProcess built-in instead would be faster?
from readdir-cluster.
. If there is valid JavaScript in the content found at that filePath, and it exports a function, then the worker has no trouble executing it.
I was suspecting this, perhaps the worker file path can be provided as an option. Such that the user can copy the worker template and modify the stat action to their desire which would more or less accomplish this as needed. It's a bit hacky, but would work.
I'd be more inclined to just boot up another set of workers with the generated file list at the end or on the fly.
I'm not sure this makes sense for your project, and it might even be valuable turning it into a generic cluster-powered iterator. Thanks for the rubber-duck debugging, anyhow. :)
Hehe, no worries.
from readdir-cluster.
In case you were curious, here's what I came up with so far for loading in callbacks via paths:
https://github.com/jokeyrhyme/child-process-async.js
It's missing error handling and worker clean ups, so it's not production-ready, but the concept is there.
from readdir-cluster.
Related Issues (8)
- Figure out if batch work for the cluster workers is even faster
- See if just using spawn is faster than clusters
- TypeError: cluster.setupMaster is not a function HOT 2
- Fallback to non-cluster readdir if not in master process
- Evaluate if SIGINT to the parent is also sent to the children
- Your .dependabot/config.yml contained invalid details HOT 1
- is fdir faster? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from readdir-cluster.