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。

並發性能果然出色,有空具體分析吧。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM