【发布时间】:2015-03-17 17:31:06
【问题描述】:
我正在运行一项测试,试图从 Node HTTP 服务器中获取最大传输速度。这是一个简单的服务器。 在我的测试中,我有 50K 虚拟客户端与服务器建立永久连接(我之前运行 ulimit -n 99999)。然后,根据另一个事件,即到不同端口的 HTTP 连接,服务器向每个虚拟客户端发送一条消息。最后,所有客户端都会收到相应的消息。 在我的测试中,发送所有消息需要几分钟时间。是否有任何建议可以帮助我改进这些测量,以便我可以在几秒钟而不是几分钟内发送 50K 条消息? 服务器在 m1.medium AWS 实例中运行。这个想法是在同一平台上提高性能。
复制服务器代码:
var http = require("http");
var connectionResponse = [];
var connectionIndex = 0;
http.createServer(function(request, response) {
console.log("Received connection " + connectionIndex);
response.setTimeout(1200000, function() {
console.log("Socket timeout");
});
connectionResponse[connectionIndex] = response;
connectionIndex++;
}).listen(8888);
http.createServer(function(request, response) {
console.log("8887 connected - Will respond");
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Triggered all responses");
response.end();
console.log("Begin notifications:" + new Date().toISOString());
for(var i = 0; i < connectionIndex; i++) {
connectionResponse[i].writeHead(200, {"Content-Type": "text/plain", "Content-Length": 4, "transfer-encoding" : ""});
connectionResponse[i].write("CAFE");
connectionResponse[i].end();
}
console.log("End notifications" + new Date().toISOString());
}).listen(8887);
【问题讨论】:
标签: node.js performance http network-programming server