简体   繁体   English

NodeJS-HTTP请求的并行执行

[英]NodeJS - parallel execution of http requests

I need to simulate a user scenario of parallel and sequential executions of http request (invoke a web service and measure time to deliver the response) 我需要模拟HTTP请求的并行和顺序执行的用户场景(调用Web服务并测量传递响应的时间)

                function 1
 function2  |   function3      | function4

So function1 execute first as soon as it's done I need to perform parallel execution of functions 2, 3 and 4 所以function1一旦完成就首先执行,我需要并行执行功能2、3和4
How do I control the execution of function 2,3 and 5 and force parallel execution? 如何控制功能2,3和5的执行并强制并行执行? is this possible with nodejs? nodejs有可能吗? does async.parallel provide this result? async.parallel提供此结果吗? is there any valid multi-threading in NodeJS to allow real parallel execution? NodeJS中是否有任何有效的多线程来允许真正的并行执行?

Create async functions: 创建异步函数:

var function2 = function(callback){
    process.nextTick(function(){
        callback();
    });
};
var function3 = function(callback){
    process.nextTick(function(){
        callback();
    });
};
var function4 = function(callback){
        process.nextTick(function(){
            callback();
        });
    };

Call: 呼叫:

function1(); //sync
function2(function(){}); //async
function3(function(){}); //async
function4(function(){}); //async

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM