node.js - How to process queue in "parallel" to keep process saturated? -
I want to process a queue as follows:
- Continued in Koi Mongodybi (Possibly with the npm package "mongodb-queue")
- Several node processes can work on the same queue
- The task consists of various I / O zeros each
- Each node process should work on concurrent tasks
Node processes are also a simple web site Race) provide services. But there will be very few requests from the site. Most work will be done for processing on the queue
The goal can be better understood by each process if each process can only pop one task at a time. Since there is a lot to wait for external services in the works, I think it will be wasted to not process them in "undefined" (I know that is not actually in parallel). I am thinking that there will be five or five boundaries, but after some time it should be touched.
Rude pseudo-code:
LoopArror {popNextTaskFromQueue (function) (task & concurrentTasks & lt; = boundary) {concurrent task ++; , Work (error) {concurrentTasks -;})})}} How should I solve it?
Thanks in advance // Michael
Edit:
I will expand some more about Paul's suggestions on async.parallelLimit async.queue With an effort I hope this is fine by editing my own question.
async.parallelLimit:
Actually, I do not think how it will be okay Bill. But I'm starting a kind of node and javascript and I can remember something.
I do not know how I can keep saturated process (i.e. full of 5 works) without providing all available before, work from queue in MongoDB but if I get all the work, then all five But only one node will be waiting for process rather than being processed.
async.queue:
What do you think about this?
q = async.queue .., 5) // Creating a queue with the dialog box 5 dbQ = some quiththatomyostorage .. while (true) {nextTick (function () {if ( ! Q.saturated) {dbQ.getTask (function (error, work) {if (function) q.push (task)}}}}} - this is a bit Is it OK to use late (true) loop?
- Or should it be recursive?
- Do I have to go next? Click here? I am worried that loop incident queue otherwise .
- The problem is that when database db If the Q is empty then I will hit the database too much. Should I add a timeout when the DBQ is empty?
I went off and tried async the concept. I will use the solution (type) below to tell me and tell me if I'm stupid something, that means something is locking up. DBQ is empty when I hit every other DB, but it is with me Is.
var limit = 5; Var q = async.queue (function (work, callback) {console.log ( 'processing' + task.payload.task); SetTimeout (function () (dbQ.ack (task.ack, function) {console log ('end' + task.id); callback ();})}}, 1000);}, border); Function Enqueves Task () {console.log ('queueLength:' + q.length () + ', running function:' + q.running ()); If (q.length () & lt; limit) {dbQ.get (function (error, work) {if (task) {console.log ('encryving task' + task.id) q.push (function, function) {}); EnqueueTasks ();} else {console.log ('DBQ is empty, 1 second taking naps') setTimeout (function () {enqueueTasks ();}, 1000);}}); } Else {console.log ('Qi hits length limit, taking 1 second NAP') setTimeout (function () {enqueueTasks ();}, 1000); }} Enqueu Task ();
Comments
Post a Comment