jfinal内置的jetty用forkjoin改造,性能提升2.7倍

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%)

虽然还没有用于生产环境,但就测试结果来看还是不错的

评论区

g7167760@trbvm.com

2018-04-21 11:35

Total time passed: 116.95s
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

JFinal

2018-04-21 15:50

jetty 9 是否需要这个改造?

jfinal 3.5 会升级到 jetty 9,jetty 9 需要 java 8,但要照顾到 java 6、java 7 用户,所以一直还没升到 jetty 9

jfinal 3.4 会在近几天发布,感谢你的分享

JFinal

2018-04-21 15:55

改进后的压测结果中下面两项测试数据没有:
Total time passed
Requests per second

jim19770812

2018-04-24 19:55

文章发出去没法修改,我改了颜色,结果Total time passed和 Requests per second没有了,我发到评论里了

jim19770812

2018-04-24 19:56

改造之后,在并发超过1000的时候失败率会比jetty默认的实现要高一点,但也只是首次,经过预热之后就稳定多了

jim19770812

2018-04-24 19:57

另外用go-wrk压测,-t 3 的话,服务器性能要比 -t 4还要好很多

JFinal

2018-04-24 21:02

@jim19770812 进入个人空间,再点击我的分享,再点一下右侧列表中的修改就可以修改了

热门分享

扫码入社