Windows GoogleGo:为什么http服务器包不能同时满足5个以上的请求?

Windows GoogleGo:为什么http服务器包不能同时满足5个以上的请求?,windows,http,go,httpserver,Windows,Http,Go,Httpserver,我正在尝试编写一个小型http服务器,以便以后使用Google的Go语言进行扩展。我使用的是Go on Windows(MinGw编译版) 这在这种语言中非常容易,因为它已经有了必要的包: package main import ( "http" "io" "os" "fmt" "strconv" ) func FileTest(w http.ResponseWriter, req *http.Request) { w.Header().

我正在尝试编写一个小型http服务器,以便以后使用Google的Go语言进行扩展。我使用的是Go on Windows(MinGw编译版)

这在这种语言中非常容易,因为它已经有了必要的包:

package main

import (
    "http"
    "io"
    "os"
    "fmt"
    "strconv"
)  


func FileTest(w http.ResponseWriter, req *http.Request) {
    w.Header().Add("Content-Type", "image/jpeg")
    w.Header().Add("Content-Disposition", "inline; filename=image.jpg")
    inName := "d:\\googlego\\somepic.jpg";
    inFile, inErr := os.OpenFile(inName, os.O_RDONLY, 0666);
    if inErr == nil {
        inBufLen := 16;
        inBuf := make([]byte, inBufLen);

        _, inErr := inFile.Read(inBuf);
        for inErr == nil {
            w.Write(inBuf)
            _, inErr = inFile.Read(inBuf);
        } 
    }
    inErr = inFile.Close(); 

}

func MainPage(w http.ResponseWriter, req *http.Request) {
    io.WriteString(w, "Hi, download here: <a href=\"/FileTest\">HERE</a>")

}


func main() {
    fmt.Print("Port: ")
    var hi int 
    fmt.Scanf("%d", &hi)
    http.HandleFunc("/FileTest", FileTest)
    http.HandleFunc("/", MainPage)

    err := http.ListenAndServe("0.0.0.0:" + strconv.Itoa(hi), nil)

    if err != nil {
        fmt.Print(err) 
        fmt.Print((hi))
    }
}
当并发级别设置得更高时,会发生以下情况:

>ab -n 1000 -c 7 http://localhost:8080/
Concurrency Level:      7
Time taken for tests:   10.239586 seconds
Complete requests:      1000

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      2
  75%      2
  80%      3
  90%    499
  95%    505
  98%    507
  99%    507
 100%    510 (longest request)
请注意,这次我只提出了1000个请求,但仍然花费了差不多6倍的时间

两个基准测试甚至还没有请求该文件

我对Go还不太了解,但是Go运行时似乎没有创建足够的OS线程来安装goroutines,或者类似的东西

编辑:我从2011年10月7日下载了新的r60.2

现在情况更糟了:


截至今天(2011年9月),Windows Go端口正在进行中。它在一些重要指标上落后于其他受支持的平台(Linux等),包括稳定性和性能(尽管它每天都在改进)。我建议您在64位Linux平台上尝试您的测试,看看它有什么不同,然后也许您可以开始解构Windows下出现的问题

我刚刚用Go 64位测试了这个基准测试,得到了以下结果(在核心2 Duo 2GHz、Windows 7 x64上):


我正在尝试使用它,因为它看起来非常棒。我已经在虚拟Linux系统上测试了完全相同的代码(这里的6g 64位编译器,在Windows上只有8g可用,32位),即使同时并发1000个请求也不会显著降低速度(甚至更快)。10000个请求的时间大约为3.6秒,这是理所当然的,因为它是一个虚拟系统。看来Windows上的多线程实现还不如Linux实现。。。我想。但它至少排除了我这边的实现错误。。。现在,使用64位?我从哪里得到这些二进制文件?你愿意分享吗?我想要他们!我还不能在64位模式下编译它,甚至不能使用Mingw64…你能构建386版本吗?如果是这样,假设您正在使用,只需将gcc.exe和ar.exe替换为64位版本,设置GOARCH=amd64,然后就可以了。我以前只替换了gcc.exe,现在正在尝试使用ar.exe。我现在使用64位版本编译了我的测试应用程序,它运行得很好。谢谢我不得不使用“hg up weekly”,因为这个版本没有编译。
>ab -n 1000 -c 7 http://localhost:8080/
Concurrency Level:      7
Time taken for tests:   10.239586 seconds
Complete requests:      1000

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      2
  75%      2
  80%      3
  90%    499
  95%    505
  98%    507
  99%    507
 100%    510 (longest request)
>ab -c 7 -n 1000 http://localhost:8080/
Concurrency Level:      7
Time taken for tests:   12.622722 seconds
Complete requests:      1000
Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      2
  80%      2
  90%    496
  95%    503
  98%    506
  99%    506
 100%    507 (longest request)
C:\Program Files (x86)\Apache Software Foundation\Apache2.2\bin>ab -c 7 -n 1000 http://localhost:8080/
Concurrency Level:      7
Time taken for tests:   0.458 seconds
Complete requests:      1000
Percentage of the requests served within a certain time (ms)
  50%      3
  66%      3
  75%      3
  80%      3
  90%      4
  95%      5
  98%      7
  99%      8
 100%      9 (longest request)