Reducing select() usage under load

Erik Rozendaal erik at deler.org
Fri May 12 17:24:26 UTC 2006


Aaron Hopkins wrote:
> NSD currently only processes one UDP packet per socket per select().  Since
> select() is kind of expensive, under load this means it burns a lot of CPU
> unnecessarily.
> 
> There's a simple trick to avoid this.  Make the UDP socket non-blocking, and
> loop on recvfrom() until it returns -1, ignoring any EAGAIN errors.  Under
> light load, this results in an extra recvfrom() every packet.  But under
> heavy load, this avoids select() until the input buffer is drained.

But you will have to be careful not to starve other sockets that may 
have incoming requests waiting.  Since NSD will usually run with 
multiple sockets (UDP, TCP, IPv4, IPv6, multiple interfaces) this can 
become quite hard and/or expensive.  That's why NSD currently uses a 
select and processes all readable sockets (not just the first!) every 
iteration.

Regards,
Erik



More information about the nsd-users mailing list