长时间运行的 goroutines

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

Long Running goroutines

问题

我在我的应用程序中有12到13个长时间运行的goroutine,它们负责一些数千个短暂存在的goroutine的创建和销毁。

除了定期调用runtime.Gosched()之外,我需要考虑其他事情来处理长时间运行的goroutine吗?

注意:目前这些长时间运行的goroutine每15到30秒执行一次对资源集合的监督(有些每几分钟执行一次),然后它们会休眠。

英文:

I have 12 to 13 long running goroutines in my app and they are responsible for some thousand short-lived goroutines come and go.

Other than calling runtime.Gosched() periodically, do I need to consider other things to do in long-running ones?

Note: Currently those long-running ones perform some supervisions on collections of resource every 15 to 30 seconds (and some every some minutes) and then they sleep.

答案1

得分: 2

不,goroutine不需要进行持续维护。它们由Go运行时管理,并且会一直运行直到它们返回或者主goroutine退出。你甚至不应该调用runtime.Gosched(),因为它只在一个例程不会主动让出时才需要使用,而你的例程大部分时间都在睡眠。

英文:

No, there's no ongoing maintenance needed for goroutines. They're managed by the go runtime, and will continue to run until they return, or the main goroutine exits. You shouldn't even be calling runtime.Gosched() as it's only needed when a routine won't yield itself, but yours spend most of their time sleeping.

huangapple
  • 本文由 发表于 2013年3月14日 01:04:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/15391804.html
匿名

发表评论

匿名网友

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

确定