Thanks Jorge!
Fantastic information, it sounds like threads-a-gogo is the way to go.
I'll use it and let you all know of my results.
Thanks again!
Jeremy
On 4/11/2012 3:05 PM, Jorge wrote:
On Apr 11, 2012, at 9:40 AM, Jeremy Rudd wrote:
On 4/10/2012 6:09 PM, Jorge wrote:
That's exactly what threads_a_gogo is for:
<https://github.com/xk/node-threads-a-gogo>
It lets you run these calculations in parallel, in javascript, in threads, and
using all the available CPU cores. Then the main thread will receive the
results in a callback or via an event.
Hi all,
Hi Jeremy,
threads_a_gogo sounds cool, but what are the technical details of using it?
1. What does it use in the back-end to schedule / manage tasks? child_process?
It creates p-threads and runs v8 isolates in them.
2. child_process takes some 30 ms to spawn a child thread. How much time does
GoGo take?
When I run this:
$ time node -e "require('threads_a_gogo').createPool(100).destroy()"
I get:
real 0m0.387s
user 0m0.390s
sys 0m0.286s
That's 3.87 ms per thread
But note that these 0.387s include as well the time to start node, the time to
require('threads_a_gogo'), and the time to destroy the 100 threads, so it must
be a bit less than 3.87 ms per thread.
3. How does it internally work? Are there constantly running threads +
scheduler? Or does it spawn a new thread per task?
You could create/destroy the threads on demand, but I would rather create a
thread pool of twice or 3x the number of cores and install in them only once
the functions that do the calculations, then reuse them again and again via a
pool.any.eval(program, cb). Each thread takes only ~2MB, and when idle it uses
exactly 0% cpu.
4. Is it recommended for 1-10 ms tasks as well? Do you have any idea / stats to
show performance with / without GoGo?
Threads_a_gogo lets you
-run these blocking calls in parallel so
-they won't block node's main thread
-you'll be exploiting all the cpu cores in the machine
With an n cores machine, you'll be serving results n times faster, but even in
a single core machine, you should use threads_a_gogo simply to avoid blocking
node.
WRT to performance, a fibonacci(40) in a thread_a_gogo runs about twice as fast as in
node's main thread, see:<https://gist.github.com/2018811> it's also a good
example because it's very similar to your use case, istm.
Thanks,
Jeremy Rudd
Cheers,
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en