jetty用的n线程,在高并发下表现并不好,jdk7开始提供了fork/join技术通过工作窃取方式来提升高并发下下的性能,我修改了
org.eclipse.jetty.util.thread.QueuedThreadPool
从线程改用fork/join,性能提升了2.7倍,测试环境是我个人电脑,4核的thinkpad
主要是修改startThread方法
// Thread thread=newThread(_runnable); // thread.setDaemon(_daemon); // thread.setPriority(_priority); // thread.setName(_name+"-"+thread.getId()); // _threads.add(thread); // thread.start(); ForkJoinTask action=RecursiveAction.adapt(_runnable); _threads.add(action); action.fork(); started=true;
go-wrk压测命令(4线程,6000并发,1百万次,4个cpu都能泡满)
go-wrk -t 4 -n 1000000 -c 6000 http://localhost:8080/ho2
修改之前压测结果
==========================BENCHMARK==========================
URL: http://localhost:8080/ho2
Used Connections: 6000
Used Threads: 4
Total number of calls: 1000000
===========================TIMINGS===========================
Total time passed: 324.69s
Avg time per request: 736.70ms
Requests per second: 3079.89
Median time per request: 420.89ms
99th percentile time: 3284.82ms
Slowest time for request: 107943.00ms
=============================DATA=============================
Total response body sizes: 19115540
Avg response body per request: 19.12 Byte
Transfer rate per second: 58873.69 Byte/s (0.06 MByte/s)
==========================RESPONSES==========================
20X Responses: 955777 (95.58%)
30X Responses: 0 (0.00%)
40X Responses: 0 (0.00%)
50X Responses: 0 (0.00%)
Errors: 44223 (4.42%)之后压测结果
==========================BENCHMARK========================== URL: http://localhost:8080/ho2 Used Connections: 6000 Used Threads: 4 Total number of calls: 1000000 ===========================TIMINGS=========================== Avg time per request: 691.81ms Median time per request: 586.96ms 99th percentile time: 3068.40ms Slowest time for request: 4745.00ms =============================DATA============================= Total response body sizes: 19769760 Avg response body per request: 19.77 Byte Transfer rate per second: 169618.76 Byte/s (0.17 MByte/s) ==========================RESPONSES========================== 20X Responses: 988488 (98.85%) 30X Responses: 0 (0.00%) 40X Responses: 0 (0.00%) 50X Responses: 0 (0.00%) Errors: 11512 (1.15%)虽然还没有用于生产环境,但就测试结果来看还是不错的
Avg time per request: 688.11ms
Requests per second: 8550.77
Median time per request: 568.11ms
99th percentile time: 3084.42ms
Slowest time for request: 8607.00ms