GoLang 开发HTTP服务器及并发测试

  Go语言主打高并发,这里就编写一个简单的HTTP服务器,然后用ab测试不加Nginx的Golang并发能力。

编译Linux固件:CGO_ENABLED=0;GOOS=linux;设置到GOENV中,set GOENV=C:\Users\gaochaowei\AppData\Roaming\go\env;

Aliyun服务器本地,ab -n 10000 -c 1000 http://localhost:6500/

15 Server Software:        
16 Server Hostname:        localhost
17 Server Port:            6500
18 
19 Document Path:          /
20 Document Length:        14 bytes
21 
22 Concurrency Level:      1000
23 Time taken for tests:   0.416 seconds
24 Complete requests:      10000
25 Failed requests:        0
26 Total transferred:      1310000 bytes
27 HTML transferred:       140000 bytes
28 Requests per second:    24033.44 [#/sec] (mean)
29 Time per request:       41.609 [ms] (mean)
30 Time per request:       0.042 [ms] (mean, across all concurrent requests)
31 Transfer rate:          3074.59 [Kbytes/sec] received
32 
33 Connection Times (ms)
34               min  mean[+/-sd] median   max
35 Connect:        0    2   2.5      1      15
36 Processing:     0    6   4.1      5      27
37 Waiting:        0    5   3.5      4      25
38 Total:          0    8   5.4      6      34
39 
40 Percentage of the requests served within a certain time (ms)
41   50%      6
42   66%      8
43   75%      9
44   80%     10
45   90%     13
46   95%     19
47   98%     28
48   99%     29
49  100%     34 (longest request)

当设置并发5000时,出现问题:socket: Too many open files (24)

提示文件描述符打开过多。这样的话就搞他,用ulimit -a查看一下:

 确实默认的最大文件打开数是1024,ulimit -n 102400可以修改一下,但是这个只能临时修改,具体永久修改方法不在这里说明,文件是/etc/security/limits.conf。

并发性能果然出色,有空具体分析吧。

猜你喜欢

转载自www.cnblogs.com/gaochaoweino/p/12531705.html