It really depends on how complex the calculations for 3/4 are. If you need/want to scale beyond one system, you should really consider utilizing a Message Queue system for serializing these requests to worker nodes.
In general, complex calculations should definitely be handled outside node’s main event loop. If you must handle these calculations in-band (without a separate queue), your best option would be a native node module that utilizes the thread pool within node. Second would be to have an external process do your calculations, this *could* be in node.js or a compiled module in C, C++, GoLang etc. I would recommend that if you aren’t going to create a native node module for this, that you at *least* wrap it in a module that uses a generic-pool in order to limit the number of processes you launch for the calculations. From: Andy Zelinski Sent: Sunday, March 16, 2014 10:47 AM To: [email protected] Subject: [nodejs] Heavy computation best practices I am hoping for someone to point me in the right direction (examples, info) on how best to handle the need for some processor heavy computations that might best be executed with C++ math libraries. example scenario pseudocode: 1. application user clicks "give me 10 movies to watch" button after entering age, iq, time of day, and how much time he/she has to watch. (some post data needed as calculation parameters) 2. application pulls some historical data from database: an array of [person id, age, iq, movie watched, time watched, movie length, rating user gave] -- say a million data points in an array 3. application then needs to apply a sophisticated math model to all data points and includes other hard-coded parameters. 4. assume after watching one movie, all the hard-coded parameters change as a side effect, so the algorithm should rank all movies in likelihood loved from 1 to n, choose the top ranked movie for user, and then iterate for the next 9, re-applying the math model is this best handled by forking a child_process? use node-ffi? wrap a c++ object that can handle the math and pass the parameters? thanks a million -- -- 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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout. -- -- 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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
