<p>比如: 用 nodejs listen 8888 端口</p>
<p>用ab做测试。</p>
<blockquote> <p>wx@wx:~/Sites/nodejs$ab -n 1000 -c 10 http://localhost:8888/</p>
<p>This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/</p>
<p>Benchmarking localhost (be patient) <strong>apr<em>socket</em>recv: Connection refused (61)</strong></p> </blockquote>
<p>这是什么问题?</p>
就是普通的hello world 都不行。
var http = require(‘http’); http.createServer(function (req, res) { res.writeHead(200, {‘Content-Type’: ‘text/plain’}); res.end(‘Hello World\n’); }).listen(8888);
var http = require(‘http’); http.createServer(function (req, res) { res.writeHead(200, {‘Content-Type’: ‘text/plain’}); res.end(‘Hello World\n’); }).listen(8888);
普通的hello world 都不行。
ab 的一个bug,使用 127.0.0.1 代替 localhost 就行了,参见: http://stackoverflow.com/questions/7938869/ab-is-erroring-out-with-apr-socket-recv-connection-refused-61
执行: ab -n 10 -c 1 http://127.0.0.1:8888/view
还是报错,如下:
This is ApacheBench, Version 2.3 <$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)...Send request failed! Send request failed! apr_socket_recv: Connection reset by peer (54) Total of 3 requests completed