2011-06-13 3 views
1

약 10,000 명의 사용자가 실시간으로 서버를 제공해야하는 node.js 응용 프로그램에서 작업하고 있습니다. 내 목표는 첫 번째 수신자와 마지막 수신자 사이의 시간차를 최소화하는 것입니다. 지금 당장은 내 컴퓨터에서 로컬로 개발 중입니다.node.js를 사용하여 동시에 10,000 개의 동시 요청 처리

루프를 사용하여 요청을 생성 한 다음 10,0000 개의 요청에 도달 할 때까지 서버 응답을 보류합니다. 한 번에 모든 요청에 ​​서버를 브로드 캐스트하고 차이를 측정하고 싶습니다.

request.js

var http = require('http') 
, a = http.getAgent('127.0.0.1', 9202); 

var util = require('util'); 
var connections = []; 
var NUM_CONCURR = 1000; 

// Max and Min 
Array.prototype.max = function(){ 
    var max = this[0]; 
    var len = this.length; 
    for(var i=0; i<len;i++) 
    if(this[i]>max) 
    max = this[i]; 
    return max; 
}; 

Array.prototype.min = function(){ 
    var min = this[0]; 
    var len = this.length; 
    for(var i=0; i<len; i++) 
    if(this[i]<min) 
     min = this[i]; 
    return min; 
}; 

// Number of socket tested 
a.maxSockets = Infinity; 

for(var i =0; i<NUM_CONCURR; i++){ 
    http.get({ 
    agent: a, 
    path: '/', 
    port: 9202, 
    host: '127.0.0.1' 
    },function(res){ 
    connections.push(microtime(true)); 

    }); 

    util.log("Connected Clients: "+i); 
} 

util.log("Server running at port 9202"); 


setInterval(function(){ 
    util.log("Total Diff Time = "+(connections.max()-connections.min())); 
    connections =[]; 
}, 1000*10); 

// Time function 
function microtime(get_as_float) { 
    var now = new Date().getTime()/1000; 
    var s = parseInt(now); 
    return (get_as_float) ? now : (Math.round((now - s) * 1000)/1000) + ' ' + s; 
} 

server.js

var http = require('http'), 
    HOST = 'localhost', 
    PORT = '9202'; 

var connections = [], i; 
var server = http.createServer(function(req, res){ 
    connections[connections.length] = {req:req, res:res}; 
    console.log('established connections: '+ ++i); 
}); 

// Send msg to stored connections 

function message(){ 
    var i = connections.length, 
     connection; 

    while(i--){ 
    connection = connections[i]; 
    connection.res.writeHead(200); 
    connection.res.write('weeeee'); 
    } 
}; 

//Broadcast after 40 sec 

setTimeout(function(){ 
    message(); 
}, 1000*40); 

server.listen(PORT); 
console.log('listening on 9202'); 

이 나를 위해 작동하지 않았다 몇 가지 이유. 더 나은 접근 방법이 있습니까? 누구든지 자신의 아이디어를 공유 할 수 있습니까? 당신과 어떤 시간차가 있니? 감사.

+0

그것이 당신에게 효과가 없다고 말할 때 무엇을 의미합니까? 어떤 결과를 기대합니까? 그리고 무엇을 받았습니까? – BCG

답변

0

모든 종류의 것들에 달려 있습니다. 실제 perf를 위해 동일한 상자에서 이와 같이 요청/클라이언트 및 서버 측 코드를 테스트하지 않으려합니다. 당신은 또한 쉽게 소켓 밖으로 실행할 수 있습니다. 예를 들어 맥 오에스 (MacOS)는 인위적인 한계가있다. 클라이언트 측에 관해서 또한

은 내가 내장 동시성 및 프로파일을 가지고 아파치 벤치, 같은 도구를 사용하는 거라고 생각합니다. http://httpd.apache.org/docs/2.0/programs/ab.html

+0

Mac 소켓 제한을 늘리는 방법은 무엇입니까? – Cristian

0

당신은 조쉬 제안 AB 벤치 마크를 사용하거나 npmjs 갈 수 .org, 노드에 작성된로드 테스트 도구가 있습니다. 그렇지 않으면 JMeter를 사용할 수 있습니다.

관련 문제