2017-02-15 76 views
1

我有一個交通繁忙的服務器(超過800K qps)與go1.7。Goroutine長時間處於IO等待狀態

http://urltoserver:debugport/debug/pprof/goroutine?debug=2我看到8K goroutines,其中近1800年在IO等待幾分鐘。其中一個這樣的goroutine堆棧如下。

goroutine 128328653 [IO wait, 54 minutes]: 
    net.runtime_pollWait(0x7f0fcc60c378, 0x72, 0x7cb) 
     /usr/local/go/src/runtime/netpoll.go:160 +0x59 
    net.(*pollDesc).wait(0xc4231d0a00, 0x72, 0xc42479fa20, 0xc42000c048) 
     /usr/local/go/src/net/fd_poll_runtime.go:73 +0x38 
    net.(*pollDesc).waitRead(0xc4231d0a00, 0x92f200, 0xc42000c048) 
     /usr/local/go/src/net/fd_poll_runtime.go:78 +0x34 
    net.(*netFD).Read(0xc4231d09a0, 0xc423109000, 0x1000, 0x1000, 0x0, 0x92f200, 0xc42000c048) 
     /usr/local/go/src/net/fd_unix.go:243 +0x1a1 
    net.(*conn).Read(0xc4234282b8, 0xc423109000, 0x1000, 0x1000, 0x0, 0x0, 0x0) 
     /usr/local/go/src/net/net.go:173 +0x70 
    net/http.(*connReader).Read(0xc420449840, 0xc423109000, 0x1000, 0x1000, 0xc422b38b68, 0x100000000, 0xc421810601) 
     /usr/local/go/src/net/http/server.go:586 +0x144 
    bufio.(*Reader).fill(0xc422e22360) 
     /usr/local/go/src/bufio/bufio.go:97 +0x10c 
    bufio.(*Reader).Peek(0xc422e22360, 0x4, 0x7a066c, 0x4, 0x1, 0x0, 0x0) 
     /usr/local/go/src/bufio/bufio.go:129 +0x62 
    net/http.(*conn).readRequest(0xc422b38b00, 0x931fc0, 0xc424d19440, 0x0, 0x0, 0x0) 
     /usr/local/go/src/net/http/server.go:762 +0xdff 
    net/http.(*conn).serve(0xc422b38b00, 0x931fc0, 0xc424d19440) 
     /usr/local/go/src/net/http/server.go:1532 +0x3d3 
    created by net/http.(*Server).Serve 
     /usr/local/go/src/net/http/server.go:2293 +0x44d 

任何人都遇到過這個問題? 任何指針讚賞。

+0

究竟是什麼問題?你想關閉活動連接嗎?你有沒有超時設置,如此反應遲鈍的客戶端不會連接連接? – JimB

+0

@JimB如何在golang中設置服務器端的連接超時。我知道客戶端。我用http.ListenAndServe啓動我的服務器 –

+0

@VishalKumar複製[ListenAndServe代碼](https://golang.org/src/net/http/server.go#L2349)。修改爲[ReadTimeout](https://godoc.org/net/http#Server.ReadTimeout),WriteTimeout,...設置值。 –

回答

0

這些很容易被客戶發起的請求,但從未完成它或緩慢客戶等

您應該配置(分別server.ReadTimeoutserver.WriteTimeout)服務器的讀/寫超時:

s := new(http.Server) 
// ... 
s.ReadTimeout = 5 * time.Second 
s.WriteTimeout = 5 * time.Second 
// ... 
+1

這應該工作。將在幾個小時內更新。謝謝。 –

+0

它按預期工作。感謝 –

+0

爲了完整性改變http.ListenAndServe( 「:端口」 中,r)爲s:=&http.Server { \t \t地址: 「:端口」, \t \t處理程序:R, \t \t ReadTimeout:somesec *時間。其次, \t \t WriteTimeout:sonesec * time.Second, \t \t MaxHeaderBytes:1個<< somenumber, \t} s.ListenAndServe() –

相關問題