簡體   English   中英

測試 golang http/1 服務器發送超大幀,但不應該

[英]Test golang http/1 server sending oversized frames, but shouldn't

我正在編寫一個非常簡單的 golang http 服務器應用程序來生成 http 流量以進行一些性能測試。 有 4 個文件包含 static 內容,每個文件大小約為 1mb,以響應來自同一網絡上的客戶端的 http 請求。
為了保持服務器發送的響應數據包 < 1500 字節,在設置過程中,我將文件分成 1420 字節的塊,並將塊數組放置在具有 4 個元素的 map 中,由文件鍵入。 請求處理程序使用此 map 來構造響應。
從文檔來看,似乎可以使用 http.Flusher 來強制發送數據包。 執行此操作的代碼如下。

我看到預期的行為 > 99% 的時間,但少數數據包超過 1500 字節。 超大幀總是緊跟在客戶端 ACK 數據包之后,並且只有一個超大數據包。 那么,我搞砸了還是可能看到了錯誤?

func createHttpServer(cfg common.Config, dir string, port int, cmap *map[string][][]byte) *http.Server {

    mux := http.NewServeMux()

    // for each of the 4 static content files, iterate over the chunks and send a packet for each
    for i := 0; i < len(cfg.Content); i++ {
        location := cfg.Content[i].Location
        mux.HandleFunc(location, func(w http.ResponseWriter, req *http.Request) {
            flusher, ok := w.(http.Flusher)
            if !ok {
                panic("createHttpServer(): expected http.ResponseWriter to be an http.Flusher")
            }

            w.Header().Add("From: joeblow@test.com", "Date: "+utcNow())
            w.WriteHeader(200)
            flusher.Flush()

            for _, chunk := range (*cmap)[location] {
                if len(chunk) > 1420 {
                    panic("unexpected oversized chunk")
                }
                w.Write(chunk)
                flusher.Flush()
            }
        })

    }
    srv := &http.Server{
        Addr:    ":" + strconv.Itoa(port),
        Handler: mux,
    }

    return srv
}

附加信息:原始問題適用於在 windows 上進行的測試。 linux(同碼)下有很多大包。 文檔說默認情況下 Nagle 在 golang 中被禁用,並且我已經驗證 mtu 設置為 1500。為了弄清楚為什么 Flush() 的結果被合並到巨型數據包中,還有什么要檢查的?

根據 Cerise Limon 和 JimB 的有用評論,無法像我嘗試的那樣控制 TCP 數據包大小,所以問題是基於錯誤的假設

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM