Goroutine在IO等待状态中停留了很长时间。

huangapple go评论85阅读模式
英文:

Goroutine in IO wait state for long time

问题

我有一个高流量的服务器(超过800K qps),使用的是go1.7版本。

从http://urltoserver:debugport/debug/pprof/goroutine?debug=2这个链接中,我看到有8K个goroutine,其中大约有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

有人遇到过这个问题吗?
感谢任何指点。

英文:

I have a heavy traffic server(more than 800K qps) with go1.7.

From http://urltoserver:debugport/debug/pprof/goroutine?debug=2 I see 8K goroutines out of which almost 1800 are in IO wait for minutes. One of such goroutine stack is as below.

    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

Anyone have faced this issue ?
Any pointer is appreciated.

答案1

得分: 2

这些可能是发起请求但从未完成的客户端,或者是慢速客户端等。

你应该配置服务器的读取/写入超时时间(server.ReadTimeoutserver.WriteTimeout):

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

These could easily be clients the initiated a request but never completed it, or slow clients etc.

You should configure the Read/Write timeouts of your server (server.ReadTimeout and server.WriteTimeout respectively):

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

huangapple
  • 本文由 发表于 2017年2月15日 08:25:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/42238695.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定