Question regarding netpoller framework implementation

80 views
Skip to first unread message

Tathagata

unread,
Jun 29, 2016, 6:35:31 PM6/29/16
to golang-nuts
Hello all,

I'm measuring the context switch overhead for go routines and I have a question regarding the netpoller mechanism. I read online that the netpoller lives in its own thread, and responds to IO events. I thought this meant that there's a separate machine thread that keeps polling the set of FDs and requeues go routines whose IO has completed.

But looking at the source code, it looks like the netpoller is only explicitly invoked by the runtime scheduler, when it has nothing else in its local runqueue. So does a go routine which was initially waiting for IO, will not be moved to the runqueue until the next time the scheduler is run?


Ian Lance Taylor

unread,
Jun 29, 2016, 9:21:52 PM6/29/16
to Tathagata, golang-nuts
On Wed, Jun 29, 2016 at 1:28 PM, Tathagata <event...@gmail.com> wrote:
>
> I'm measuring the context switch overhead for go routines and I have a
> question regarding the netpoller mechanism. I read online that the netpoller
> lives in its own thread, and responds to IO events. I thought this meant
> that there's a separate machine thread that keeps polling the set of FDs and
> requeues go routines whose IO has completed.

That is not how it works.

> But looking at the source code, it looks like the netpoller is only
> explicitly invoked by the runtime scheduler, when it has nothing else in its
> local runqueue. So does a go routine which was initially waiting for IO,
> will not be moved to the runqueue until the next time the scheduler is run?

That is roughly correct. Note that the scheduler is run every time a
goroutine blocks. And note that the sysmon thread ensures that the
network is polled at least every 10ms.

Ian
Reply all
Reply to author
Forward
0 new messages