douhuan1950 2013-05-22 21:35
浏览 34

测试Go语言时性能下降

I've been testing out a simple web server written in Go with http_load. When running the test for 1 second with 100 parallel I've seen 16k requests completed. However, running the test for 10 seconds results in a similar number of requests being completed at around 1/10th of the rate of the 1 second test.

Additionally, if I run several 1 second test close together, the first test will complete 16k requests and the subsequent tests will complete just 100-200 requests.

package main

import "net/http"

func main() {
    bytes := make([]byte, 1024)
    for i := 0; i < len(bytes); i++ {
        bytes[i] = 100
    }

    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        w.Write(bytes)
    })
    http.ListenAndServe(":8000", nil)
}

I'm wondering whether there is any reason as to why the performance would hit a ceiling whilst dealing with this number of requests and whether there is something I have missed in the implementation of the above web server.

  • 写回答

1条回答 默认 最新

  • duanhunlou7051 2013-05-24 03:54
    关注

    This is probably a limitation on your own system rather than the go server. The same kind of degradation happens if you try hitting something like google with http_load:

    $> http_load -parallel 100 -seconds 10 google.txt
    1000 fetches, 100 max parallel, 219000 bytes, in 10.0006 seconds
    219 mean bytes/connection
    99.9944 fetches/sec, 21898.8 bytes/sec
    msecs/connect: 410.409 mean, 4584.36 max, 16.949 min
    msecs/first-response: 279.595 mean, 3647.74 max, 35.539 min
    HTTP response codes:
      code 301 -- 1000
    
    $> http_load -parallel 100 -seconds 50 google.txt
    729 fetches, 100 max parallel, 159213 bytes, in 50.0008 seconds
    218.399 mean bytes/connection
    14.5798 fetches/sec, 3184.21 bytes/sec
    msecs/connect: 1588.57 mean, 36192.6 max, 17.944 min
    msecs/first-response: 237.376 mean, 33816.7 max, 33.092 min
    2 bad byte counts
    HTTP response codes:
      code 301 -- 727
    
    $> http_load -parallel 100 -seconds 100 google.txt
    1091 fetches, 100 max parallel, 223161 bytes, in 100 seconds
    204.547 mean bytes/connection
    10.91 fetches/sec, 2231.61 bytes/sec
    msecs/connect: 1652.16 mean, 35860.4 max, 17.825 min
    msecs/first-response: 319.259 mean, 35482.1 max, 31.892 min
    HTTP response codes:
      code 301 -- 1019
    

    As you can see, the rate goes down quite a bit the longer you hit google (google.txt contains the single url "http://google.com"). This is most likely due to limitations in your system (the maximum num of open connections your programs can have, memory, cpu, etc...).

    评论

报告相同问题?

悬赏问题

  • ¥15 html5+css有人可以帮吗?
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?