Comments (6)
Related: nodejs/node#3145
Did some further digging to see where the bottlenecks were in our use case. Grabbed the AST for lodash.js
(roughly 16MB JSON) and measured the full round-trip to pass over IPC to a child process and back. Also measured (de)serialization times using both JSON
and `BSON.
The results:
Stringify took 2.004831594 seconds.
Parse took 0.681263825 seconds.
BSON serialize took 0.976388723 seconds.
BSON unserialize took 0.814068171 seconds.
Starting IPC...
Child received message.
IPC round-trip took 51.384239773 seconds.
from interlock.
Further measurements are warranted, especially of Babel's parse
and generate
, to determine whether the gains from parallelizing the tasks is worth the cost of (de)serialization. In particular, since the (de)serialization CPU burden is equally shared between the parent and child processes, we're looking at ~1s blocking operations that will interfere (to an unknown extent) with the parent's delegation of tasks to the worker pool.
from interlock.
Would something like https://github.com/dominictarr/JSONStream help? At least this way, parsing won't block and you can spread out the streaming over the parent's event loop.
from interlock.
sending large ipc messages seems to be O(n^2) in the message length (see my comment in the related issue #3145). I've seen O(n^2) delays slip in during message reassembly, maybe worth a check.
from interlock.
Thanks @andrasq. I noticed the same thing. For now, I created a workaround using Unix sockets and BSON (de)serialization. Performance appears to scale linearly with the message size, and is likely good enough for our use case.
Stringify took 1.650871098 seconds.
Parse took 0.629973014 seconds.
BSON serialize took 0.962255679 seconds.
BSON unserialize took 0.775885246 seconds.
====== Starting Native IPC... ======
Child received message.
IPC took 50.578393824 seconds.
====== Starting BSON IPC... ======
Server bound on /tmp/interlock-ipc.sock...
Server has received connection from child process.
Child is connected to server.
Child received message.
BSON-IPC took 3.852710589 seconds.
from interlock.
Looks like the performance gains from farming out work to multiple processes is mostly cancelled out by all the serialization overhead. Going to close this for now, and pursue native extensions for performance improvements instead.
from interlock.
Related Issues (20)
- Require.js Interop Plug-in
- Rip out streams HOT 2
- interlock-signed HOT 4
- Tree Shaking plugin HOT 1
- Webpack loader compatibility layer HOT 1
- UMD plugin HOT 1
- Browserify transform compatibility layer HOT 1
- Publish divmain-scoped babel packages
- Move all official plugins into single repository
- Per-file babel config HOT 1
- Simplify entry-point config HOT 1
- Re-add sourcemaps output
- Support presets
- Add flow infrastructure HOT 1
- AST caching
- PoC Native replacement for `updateRequires` step
- Support generic commands
- babelConfig function
- Server should console.log a url
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 interlock.