[PATCH] Check half-closed descriptors at most once per second.

From: Alex Rousskov <rousskov_at_measurement-factory.com>
Date: Wed, 24 Sep 2008 17:22:51 -0600

Performance fix: Check half-closed descriptors at most once per second.

A few revisions back, comm checked half-closed descriptors once per
second, but the code was buggy. I replaced it with a simpler code that
checked each half-closed descriptor whenever the OS would mark it as
ready for reading. That was a bad idea: The checks wasted a lot of CPU
cycles because half-closed descriptors are usually ready for reading all
the time.

This revision resurrects 1 check/sec limit, but hopefully with fewer
bugs. In my limited tests, CPU usage seems to be back to normal.

Added a DescriptorSet class to manage an unordered collection of unique
descriptors. The class might be useful for deferred reads as well, but
that remains to be seen.

The DescriptorSet class has O(1) complexity for search, insertion,
and deletion. It uses about 2*sizeof(int)*MaxFD bytes. Splay tree that
used to store half-closed descriptors previously uses less RAM for small
number of descriptors but has O(log n) complexity.

The DescriptorSet code should probably get its own .h and .cc files,
especially if it is going to be used by deferred reads.

Thank you,

Alex.

Received on Wed Sep 24 2008 - 23:22:57 MDT

This archive was generated by hypermail 2.2.0 : Thu Sep 25 2008 - 12:00:06 MDT