On Mon, 2008-03-10 at 16:49 -0700, Sophie Hu wrote:
> I know port_getn is more efficient that select() because when some
> event happens on the port, port_getn simply return it; while by using
> select(), when some event happens, select() tries to get the socket of
> this event, and then tries to find which bit is related to the socket,
> then mask that bit, and then return, is it correct? Can anybody
> explain more? 

If you're waiting for any of N events to happen, your application has to
check up to N bits on every return from select().  And the kernel has to
look at all nfds bits in each fd_set.  

That's not a big deal if you're waiting for any of a dozen events to
happen.  It's really painful if you're waiting for any of 1000 or 10000
events, or even if you're waiting for one or two of a sparse set of
descriptors..

In other words, with select(), the system has to do O(N) work for each
event, where "N" is based on the largest file descriptor number in use.

with poll(), the system has to do O(N) work for each event, where "N" is
based on the number of events (which may, or may not, be much smaller
than the N for select()).

With port_*, you have to do only O(1) work for each event.

see: http://en.wikipedia.org/wiki/Big_O_notation

                                        - Bill









_______________________________________________
perf-discuss mailing list
perf-discuss@opensolaris.org

Reply via email to