http客户端-性能比较系列-第二篇-多线程
系列文章:
单线程性能测试:https://www.cnblogs.com/victor2302/p/11077208.html
多线程性能测试:https://www.cnblogs.com/victor2302/p/11080965.html
github代码:https://github.com/victorsheng/benchmark-anything
背景
本文从上一篇中的单线程性能测试,改为了4个线程,然后比较这几个http客户端的性能表现
结果
4线程
http://jmh.morethan.io/?source=https://gist.githubusercontent.com/victorsheng/434f55b77ddb332eaa99b9d52b9f781e/raw/b0f666b8d557338c57192aaa60f277d8c0a25621/1561372480772-result.csv
16线程
http://jmh.morethan.io/?source=https://gist.githubusercontent.com/victorsheng/15ad35710787d4940107ca5d476a365b/raw/cfde3d1c34a231c38b258339cc95986ae322ee0b/1561430754195-result.csv
get方法接口立刻返回
okhttpclient和Unirest性能最好,都在0.2ms以下
get方法等待5ms接口
ApacheHttpShareClient性能最差,猜测是由于默认配置原因
文件上传接口
在210kb和420kb下
ApacheHttpShareClient性能最差,JdkHttpClient和Unirest性能最好
文件下载接口
1M情境下:
ApacheHttpShareClient和SpringHttpClient性能最好
420kb情景下
ApacheHttpShareClient,OkhttpClient和SpringHttpClient性能最好
210kb情境下:
OkhttpClient性能最好
验证
在设置org.apache.http.impl.client.CloseableHttpClient多连接后,性能与其他组件无明显差别
代码:
private CloseableHttpClient httpclient = HttpClientBuilder.create().setMaxConnTotal(16)
.setMaxConnPerRoute(16).build();
结果:
Benchmark (className) (diffFeature) Mode Cnt Score Error Units
ClientBenchMarkGET.get_return_now cn.victor123.benchmark.client.ApacheHttpShareClient NULL avgt 3 0.333 ± 0.051 ms/op
ClientBenchMarkGET.get_return_now cn.victor123.benchmark.client.JdkHttpClient NULL avgt 3 0.520 ± 0.475 ms/op
ClientBenchMarkGET.get_return_now cn.victor123.benchmark.client.OkHttpClientt NULL avgt 3 0.473 ± 0.133 ms/op
ClientBenchMarkGET.get_return_now cn.victor123.benchmark.client.SpringHttpClient NULL avgt 3 0.599 ± 0.781 ms/op
ClientBenchMarkGET.get_return_now cn.victor123.benchmark.client.UnirestHttpClient NULL avgt 3 0.446 ± 0.201 ms/op
ClientBenchMarkGET.get_return_sleep5ms cn.victor123.benchmark.client.ApacheHttpShareClient NULL avgt 3 6.379 ± 4.317 ms/op
ClientBenchMarkGET.get_return_sleep5ms cn.victor123.benchmark.client.JdkHttpClient NULL avgt 3 6.794 ± 0.885 ms/op
ClientBenchMarkGET.get_return_sleep5ms cn.victor123.benchmark.client.OkHttpClientt NULL avgt 3 6.663 ± 1.792 ms/op
ClientBenchMarkGET.get_return_sleep5ms cn.victor123.benchmark.client.SpringHttpClient NULL avgt 3 6.572 ± 0.964 ms/op
ClientBenchMarkGET.get_return_sleep5ms cn.victor123.benchmark.client.UnirestHttpClient NULL avgt 3 6.745 ± 1.163 ms/op