[erlang-questions] Why does an idle erlang process (couchdb, to be precise) call epoll_wait so often?

Lukas Larsson lukas@REDACTED
Mon May 27 10:34:07 CEST 2013


On Fri, May 24, 2013 at 4:41 PM, Jann Horn <jann@REDACTED> wrote:

> On Thu, May 23, 2013 at 11:13:15AM +0200, Lukas Larsson wrote:
> > On Thu, May 23, 2013 at 10:56 AM, Jann Horn <jann@REDACTED> wrote:
> >
> > > On Wed, May 22, 2013 at 06:42:59PM +0200, Lukas Larsson wrote:
> > > > You have to poll like that because fd's are not the only thing which
> can
> > > > trigger load on the system. Timeouts for instance are triggered by
> > > calling
> > > > gettimeofday which means you have to break out of epoll_wait before
> the
> > > > next timeout happens.
> > >
> > > Why not by specifying a timeout in the epoll_wait call?
> > >
> >
> > If you look closely to the strace you can see that for every n:th call
> > there is a small timeout given to epoll_wait. This timeout is calculated
> by
> > looking at the next timeout and a number of other factors.
>
> Does that mean that the couchdb code has set some timer that fires with a
> high frequency?
> Because even when epoll_wait is called with a timeout, the timeout is
> below one second.
>
>
It could mean that there is a timer, there is also a bunch of other
internal emulator events which have to be taken care of which could cause
the low timeout.


>
> > >
> > > > Also the spinning is done to make the system respond
> > > > faster to events by delaying sleeping in the kernel.
> > >
> > > Ah, ok... and that brings a performance gain?
> > >
> >
> > It brings a latency gain, which in turn can bring a performance gain.
> > Sleeping in the kernel is a (relatively) expensive thing to do and by
> > spinning before sleeping the schedulers stay more responsive. You can
> > configure this behaviour through the runtime flags +sbwt, +sws, +swt. See
> > http://www.erlang.org/doc/man/erl.html for some more details.
>
> But e.g. on a single-core machine, spinning before sleeping makes no
> sense, right?
> So for single-core machines (VMs/mobile devices), this should be turned
> off?
>

I'd assume so, but I haven't made any measurements for it.


> Btw, what's so expensive about sleeping in the kernel? The context
> switches?
> Trashing the cache?
>
It varies depending on OS and HW combination, but those are the main
things.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130527/126af72e/attachment.htm>


More information about the erlang-questions mailing list