nginx配置文件
user www-data;worker_processes 4;pid /run/nginx.pid;events { use epoll; worker_connections 10000; multi_accept on;}http { access_log off; #记录日志会导致性能下降 #因为有buffered cache的原因,重复读取小文件并不会受disk io影响 server { listen 8080; location / { root /; } } }
jetty测试
package jetty.performance;import java.io.IOException;import java.net.InetSocketAddress;import javax.servlet.ServletException;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.eclipse.jetty.server.Request;import org.eclipse.jetty.server.Server;import org.eclipse.jetty.server.handler.AbstractHandler;public class TestJetty extends AbstractHandler { @Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.getWriter().write("hello world"); baseRequest.setHandled(true); } public static void main(String[] args) throws Exception { InetSocketAddress listen_addr = new InetSocketAddress("127.0.0.1", 9000); Server server = new Server(listen_addr); server.setHandler(new TestJetty()); server.start(); server.join(); }}
测试环境是阿里云的服务器,型号是ecs.n1.large,4核8G内存,ubuntu 14.04,java是oralce官方的
首先是不使用keepalive,会频繁建立连接的方式
ab -n 100000 -c 100 http://127.0.0.1:8080/index.htmlThis is ApacheBench, Version 2.3 <$Revision: 1528965 $>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 10000 requestsCompleted 20000 requestsCompleted 30000 requestsCompleted 40000 requestsCompleted 50000 requestsCompleted 60000 requestsCompleted 70000 requestsCompleted 80000 requestsCompleted 90000 requestsCompleted 100000 requestsFinished 100000 requestsServer Software: nginx/1.4.6Server Hostname: 127.0.0.1Server Port: 8080Document Path: /index.htmlDocument Length: 12 bytesConcurrency Level: 100Time taken for tests: 4.387 secondsComplete requests: 100000Failed requests: 0Total transferred: 25000000 bytesHTML transferred: 1200000 bytesRequests per second: 22795.74 [#/sec] (mean)Time per request: 4.387 [ms] (mean)Time per request: 0.044 [ms] (mean, across all concurrent requests)Transfer rate: 5565.37 [Kbytes/sec] receivedConnection Times (ms) min mean[+/-sd] median maxConnect: 0 2 0.3 2 4Processing: 1 3 0.5 3 5Waiting: 0 2 0.5 2 4Total: 2 4 0.5 4 8Percentage of the requests served within a certain time (ms) 50% 4 66% 4 75% 5 80% 5 90% 5 95% 6 98% 6 99% 7 100% 8 (longest request)
ab -n 100000 -c 100 http://127.0.0.1:9000/This is ApacheBench, Version 2.3 <$Revision: 1528965 $>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 10000 requestsCompleted 20000 requestsCompleted 30000 requestsCompleted 40000 requestsCompleted 50000 requestsCompleted 60000 requestsCompleted 70000 requestsCompleted 80000 requestsCompleted 90000 requestsCompleted 100000 requestsFinished 100000 requestsServer Software: Jetty(9.3.z-SNAPSHOT)Server Hostname: 127.0.0.1Server Port: 9000Document Path: /Document Length: 11 bytesConcurrency Level: 100Time taken for tests: 4.346 secondsComplete requests: 100000Failed requests: 0Total transferred: 11800000 bytesHTML transferred: 1100000 bytesRequests per second: 23009.02 [#/sec] (mean)Time per request: 4.346 [ms] (mean)Time per request: 0.043 [ms] (mean, across all concurrent requests)Transfer rate: 2651.43 [Kbytes/sec] receivedConnection Times (ms) min mean[+/-sd] median maxConnect: 0 2 41.4 1 1002Processing: 0 2 4.2 1 400Waiting: 0 1 4.2 1 399Total: 0 4 41.6 2 1007Percentage of the requests served within a certain time (ms) 50% 2 66% 2 75% 2 80% 3 90% 3 95% 4 98% 5 99% 6 100% 1007 (longest request)
然后是带keep alive参数的结果
ab -n 100000 -c 100 -k http://127.0.0.1:8080/index.htmlThis is ApacheBench, Version 2.3 <$Revision: 1528965 $>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 10000 requestsCompleted 20000 requestsCompleted 30000 requestsCompleted 40000 requestsCompleted 50000 requestsCompleted 60000 requestsCompleted 70000 requestsCompleted 80000 requestsCompleted 90000 requestsCompleted 100000 requestsFinished 100000 requestsServer Software: nginx/1.4.6Server Hostname: 127.0.0.1Server Port: 8080Document Path: /index.htmlDocument Length: 12 bytesConcurrency Level: 100Time taken for tests: 0.905 secondsComplete requests: 100000Failed requests: 0Keep-Alive requests: 99049Total transferred: 25495245 bytesHTML transferred: 1200000 bytesRequests per second: 110440.74 [#/sec] (mean)Time per request: 0.905 [ms] (mean)Time per request: 0.009 [ms] (mean, across all concurrent requests)Transfer rate: 27497.20 [Kbytes/sec] receivedConnection Times (ms) min mean[+/-sd] median maxConnect: 0 0 0.1 0 3Processing: 0 1 0.7 1 10Waiting: 0 1 0.7 1 10Total: 0 1 0.7 1 10Percentage of the requests served within a certain time (ms) 50% 1 66% 1 75% 1 80% 1 90% 2 95% 3 98% 3 99% 4 100% 10 (longest request)
ab -n 100000 -c 100 -k http://127.0.0.1:9000/This is ApacheBench, Version 2.3 <$Revision: 1528965 $>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 10000 requestsCompleted 20000 requestsCompleted 30000 requestsCompleted 40000 requestsCompleted 50000 requestsCompleted 60000 requestsCompleted 70000 requestsCompleted 80000 requestsCompleted 90000 requestsCompleted 100000 requestsFinished 100000 requestsServer Software: Jetty(9.3.z-SNAPSHOT)Server Hostname: 127.0.0.1Server Port: 9000Document Path: /Document Length: 11 bytesConcurrency Level: 100Time taken for tests: 1.297 secondsComplete requests: 100000Failed requests: 0Keep-Alive requests: 100000Total transferred: 14200000 bytesHTML transferred: 1100000 bytesRequests per second: 77092.32 [#/sec] (mean)Time per request: 1.297 [ms] (mean)Time per request: 0.013 [ms] (mean, across all concurrent requests)Transfer rate: 10690.54 [Kbytes/sec] receivedConnection Times (ms) min mean[+/-sd] median maxConnect: 0 0 0.1 0 3Processing: 0 1 4.2 0 53Waiting: 0 1 4.2 0 53Total: 0 1 4.2 0 53Percentage of the requests served within a certain time (ms) 50% 0 66% 0 75% 0 80% 0 90% 1 95% 12 98% 17 99% 20 100% 53 (longest request)