Golang VS Java 在DSP系统对比
Contents
起因
最近一段时间在学Golang,突然间想着,将公司现在的DSP的产品(竞价部分的逻辑),翻译为Golang来试一试它们的性能。
测试的环境:
Golang 1.7
JDK 1.8
Tomcat 7.0
以上都是使用默认配置
i5 CPU 4核心
16 GB内存
下面是AB后的结果
Go
┌─[sky@sky-linux] - [~] - [2016-11-02 12:36:44]
└─[0] <> ab -n 10000 -c 100 -p /tmp/post.data -T 'application/x-www-form-urlencoded' http://localhost:9090/dsp/recbid
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 localhost (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software:
Server Hostname: localhost
Server Port: 9090
Document Path: /dsp/recbid
Document Length: 786 bytes
Concurrency Level: 100
Time taken for tests: 3.713 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 9040000 bytes
Total body sent: 8060000
HTML transferred: 7860000 bytes
Requests per second: 2693.39 [#/sec] (mean)
Time per request: 37.128 [ms] (mean)
Time per request: 0.371 [ms] (mean, across all concurrent requests)
Transfer rate: 2377.75 [Kbytes/sec] received
2119.99 kb/s sent
4497.74 kb/s total
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 1
Processing: 1 37 27.4 31 425
Waiting: 1 37 27.4 31 425
Total: 1 37 27.4 31 425
Percentage of the requests served within a certain time (ms)
50% 31
66% 39
75% 46
80% 50
90% 61
95% 69
98% 79
99% 92
100% 425 (longest request)
Java
┌─[sky@sky-linux] - [~] - [2016-11-02 11:04:09]
└─[0] <> ab -n 10000 -c 100 -p /tmp/post.data -T 'application/x-www-form-urlencoded' http://localhost:8080/dsp/recbid
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 localhost (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software: Apache-Coyote/1.1
Server Hostname: localhost
Server Port: 8080
Document Path: /dsp/recbid
Document Length: 810 bytes
Concurrency Level: 100
Time taken for tests: 1.558 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 9580000 bytes
Total body sent: 8060000
HTML transferred: 8100000 bytes
Requests per second: 6419.10 [#/sec] (mean)
Time per request: 15.579 [ms] (mean)
Time per request: 0.156 [ms] (mean, across all concurrent requests)
Transfer rate: 6005.37 [Kbytes/sec] received
5052.53 kb/s sent
11057.90 kb/s total
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 1
Processing: 1 15 21.7 8 319
Waiting: 1 15 21.7 8 319
Total: 1 15 21.7 8 319
Percentage of the requests served within a certain time (ms)
50% 8
66% 11
75% 16
80% 21
90% 37
95% 56
98% 86
99% 105
100% 319 (longest request)
说明
这个是平均多次执行后对比的最后结果,按照这些数据来看,Golang还是远远比不上Java的性能。
后记
刚开始学Golang时,越发觉得是个好东西,就是感觉很容易上手,语法这些也很容易熟悉。学了半个星期,然后用半个星期将公司的DSP产品翻译为Golang版本。在这过程中,对Golang也渐渐更加了解点。不过,按照目前这情况,Golang的性能,还是比不上Java的。毕竟JVM和JIT的时间都有20多个年头的,这真的不是开玩笑的。Golang未来还是要有很长一段时间要走。
给我最大的感觉,大概就是Golang的非常简洁的语法及丰富的库。写个Web服务,本身并不需要依赖其他第三方库就已经很方便实现了。内置的对JSON的天生支持(encode和decode),非常简单的并发 go function(...)
,以及管道的同步。结构体之间的继承以及接口类型+反射,这些都是个很好的东西,相对于纯OO语言来说,这种实现显得更加优雅点。不过,到目前为至,还没有支持泛型,虽然可以通过反射interface{}
类型来实现,不过,总觉得这种太挫了。