The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
xiaojay

怎样在运行中实时监控goroutine的个数?

  •  
  •   xiaojay ·
    xiaojay · Jun 27, 2013 · 3146 views
    This topic created in 4701 days ago, the information mentioned may be changed or developed.
    go新手,在用go写个server,基本方式就是客户过来一个连接,生成一个goroutine处理。
    这样实时goroutine的个数,应该就等于并发数?
    那么如何实时监控goroutine的个数?有什么好用的工具?

    还是要自己维护一个 buffer chan,每次生成goroutine push个消息(chan <- 1),这个goroutine退出读一个消息(<- chan)

    cc @cyfdecyf @clowwindy
    7 replies    1970-01-01 08:00:00 +08:00
    bluntblade
        1
    bluntblade  
       Jun 27, 2013   ❤️ 1
    查看runtime包。

    func NumGoroutine

    func NumGoroutine() int
    NumGoroutine returns the number of goroutines that currently exist.
    xiaojay
        2
    xiaojay  
    OP
       Jun 27, 2013
    ok,搞定了,谢谢
    顺便分享下demo,请指教 :)
    https://gist.github.com/xiaojay/5873816
    https://gist.github.com/xiaojay/5873821

    ps:七牛的么,呵呵
    dontwanttologin
        3
    dontwanttologin  
       Jun 27, 2013
    @xiaojay 只有七牛的搞Go?
    cyfdecyf
        4
    cyfdecyf  
       Jun 28, 2013
    @bluntblade 长知识了。偷窥了下 id,发现你是昨天刚刚注册 v2ex 的。
    xiaojay
        5
    xiaojay  
    OP
       Jun 28, 2013
    @cyfdecyf
    用cow,出现这个错误

    是什么原因?
    cyfdecyf
        6
    cyfdecyf  
       Jun 30, 2013
    @xiaojay 目测你用的是 Mac 上的 Firefox 吧?同时创建的 socket 数量过多导致的,OS X 进程打开的文件数上限默认是 256,调大一些即可。

    以后会考虑在遇到这个错误时关闭一些 keep alive 的 socket,本机使用的话应该可以解决一些问题。
    bluntblade
        7
    bluntblade  
       Jul 2, 2013
    我是七牛的运维主管。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3311 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 00:31 · PVG 08:31 · LAX 17:31 · JFK 20:31
    ♥ Do have faith in what you're doing.