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

golang 协程调度 帮忙翻译理解下

  •  
  •   helloworld12 · Oct 24, 2018 · 3064 views
    This topic created in 2804 days ago, the information mentioned may be changed or developed.

    if you run any tight loops that are not making function calls, you will cause latencies within the scheduler and garbage collection

    是说,如果你循环中没有进行函数调用,那么调度或者垃圾回收时,会有延时 ?

    看了上下文,说当函数调用的时候,有协程调度的埋点,这样的话,如果循环中没有函数调用,就不会有调度的延时啊?

    It ’ s critically important that function calls happen within reasonable timeframes.

    是说,如果函数调用频度要合理,不要过多,也不要过少吗?

    5 replies    2018-10-25 00:27:53 +08:00
    hsiafan
        1
    hsiafan  
       Oct 24, 2018   ❤️ 1
    没有埋点一个协程就会一直占了 P 啊,P 队列上其他的协程就没机会执行了
    Leigg
        2
    Leigg  
       Oct 24, 2018 via iPhone   ❤️ 1
    gc 本就是针对变量,函数一类对象的,gc 是有开销的,不会很频繁的执行,字面意思你没翻译错。
    TheCure
        3
    TheCure  
       Oct 24, 2018   ❤️ 1
    调度器发现一个 routine 运行了很久需要暂停的时候, 会给这个 routine 设置一个 flag. 在 function call 的时候, 会去检查这个 flag, 然后决定是否暂停运行.
    像 java 里的 GC Pause, 也需要执行到 safepoint 的时候,停止运行, 虽然 go 用的是协程, 但是和这个 GC Pause 也类似
    TheCure
        4
    TheCure  
       Oct 24, 2018   ❤️ 1
    所以给的建议是, 如果很蠢的写了一个 for 循环, 里面都是 i++这种没有发生函数调用, 也不可能阻塞的代码, 这个 routine 会一直跑下去.
    reus
        5
    reus  
       Oct 25, 2018
    https://github.com/golang/proposal/blob/master/design/24543-non-cooperative-preemption.md

    Proposal: Non-cooperative goroutine preemption

    很可能 1.12 就会实现,所以探讨这些没什么意义,这些知识很快就会过时。
    goroutine 不是协程。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5175 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 48ms · UTC 01:10 · PVG 09:10 · LAX 18:10 · JFK 21:10
    ♥ Do have faith in what you're doing.