Giter VIP home page Giter VIP logo

Comments (6)

divmain avatar divmain commented on July 3, 2024

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.

divmain avatar divmain commented on July 3, 2024

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.

tptee avatar tptee commented on July 3, 2024

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.

andrasq avatar andrasq commented on July 3, 2024

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.

divmain avatar divmain commented on July 3, 2024

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.

divmain avatar divmain commented on July 3, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.