2

後でGoogleのGo言語で拡張するために小さなhttpサーバーをコーディングしようとしています。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(Apacheベンチマーク)から最大6つの同時スレッドで非常に良い結果が得られます。

> ab -n 10000 -c 6 http://localhost:8080/
Concurrency Level:      6
Time taken for tests:   1.678096 seconds
Complete requests:      10000

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      1
  80%      1
  90%      2
  95%      2
  98%      2
  99%      2
 100%      3 (longest request)

同時実行レベルを高く設定すると、次のようになります。

>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)

今回は1,000件のリクエストしか行わなかったのに、それでも6倍近くの時間がかかったことに注意してください。

どちらのベンチマークも、まだファイルを要求していません。

Goについてはまだよくわかりませんが、Goランタイムでは、ゴルーチンを配置するのに十分なOSスレッドが作成されていないようです。

編集:2011年7月10日から新しいr60.2をダウンロードしました。

今ではさらに悪化しました:

>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)
4

2 に答える 2

4

本日(2011年9月)現在、GoのWindowsポートは進行中です。安定性やパフォーマンスなど、いくつかの重要な点で、サポートされている他のプラットフォーム(Linuxなど)に遅れをとっています(ただし、毎日改善されています)。64ビットLinuxプラットフォームでテストを試して、その違いを確認することをお勧めします。そうすれば、Windowsで何が問題になっているのかを解体し始めることができます。

于 2011-09-28T16:37:12.753 に答える
2

このベンチマークをGo64ビットで試してみたところ、次の結果が得られました(Core 2 Duo 2GHz、Windows 7 x64で)。

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)
于 2011-10-12T08:08:18.290 に答える