Nodejs HTTP服务器连接memcache

时间:2014-01-08 03:35:46

标签: node.js

我使用nodejs构建一个http服务器。每个请求收入,http服务器连接到memcache,检查并返回数据或做其他事情。当我使用Apache Benchmark测试性能时,如:-n 1000.输出显示它刚刚完成了大约900个请求,然后http服务器不能再服务了。 我究竟做错了什么?你能解释一下会发生什么吗?

这里是我的代码:

http.createServer(function(req, res) {
    var client = new mc.Client(ip, mc.Adapter.binary);
    client.connect(function() {
    client.get(key, function(err, response) {
    if(err) { //not exist
        ..
        res.end(result)
    ..
    }
    else {  //exist in memcache
        var result = response[key];   
        res.end(result);
    }
});   

}); }); 这是Benchmarch之后的结果:

This is ApacheBench, Version 2.4.1 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
apr_poll: The timeout specified has expired (70007)
Total of 896 requests completed

更新:我发现我没有断开每个请求的memcached。问题解决!!!

1 个答案:

答案 0 :(得分:0)

nodejs应用程序的一个棘手问题是内存容量为1.4GB。如果您的服务器使用超过允许的限制,它将挂起或崩溃。您可以自定义构建nodejs应用程序以增加此值。

如果不使用,请确保垃圾收集varibles(比如将某些模块范围varibles设置为null)。

我没有足够的信息告诉你出了什么问题。我建议查看服务器日志。

相关问题