[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-optimize
Subject: Use poll() instead of select()
From: Jaime Torres <jtorres () sia ! es>
Date: 2003-01-30 10:15:43
[Download RAW message or body]
Hello,
I have done a small test with the very recent kde 3.1 on a
linux-i686-2.4.20.
I have readed in http://www.kegel.com/dkftpbench/Poller_bench.html
that poll() is faster than select() on Linux,*BSD and I thinked that also
in comercial unixes, but I know that poll() is simpler to use than select().
I have only changed select by poll in the dcop server, resulting in a dcop
library of 258 bytes less and less memory normaly implies less swap and
better performance.
I have count the number of selects and there are more than 33 only in
kdelibs.
Regards.
The diffs are:
39d38
< #include <poll.h>
1604,1616c1603,1609
<
< // * // Convert to poll
< struct pollfd fds;
< fds.fd=socket();
< fds.events=POLLIN;
< // fd_set fds;
< // struct timeval tv;
< // FD_ZERO( &fds );
< // FD_SET( socket(), &fds );
< // tv.tv_sec = msecs / 1000;
< // tv.tv_usec = (msecs % 1000) * 1000;
< if (poll (&fds,1,msecs)<=0) {
< // if ( select( socket() + 1, &fds, 0, 0, &tv ) <= 0 ) {
---
> fd_set fds;
> struct timeval tv;
> FD_ZERO( &fds );
> FD_SET( socket(), &fds );
> tv.tv_sec = msecs / 1000;
> tv.tv_usec = (msecs % 1000) * 1000;
> if ( select( socket() + 1, &fds, 0, 0, &tv ) <= 0 ) {
1652,1665c1645,1651
<
< // * // Convert it to poll
< //fd_set fds;
< struct pollfd fds;
< fds.fd=fd;
< fds.events=POLLIN;
<
< // timeval timeout;
< // timeout.tv_sec = 0;
< // timeout.tv_usec = 0;
< // FD_ZERO(&fds);
< // FD_SET(fd, &fds);
< int result=poll(&fds,1,0);
< // int result = select(fd+1, &fds, 0, 0, &timeout);
---
> fd_set fds;
> timeval timeout;
> timeout.tv_sec = 0;
> timeout.tv_usec = 0;
> FD_ZERO(&fds);
> FD_SET(fd, &fds);
> int result = select(fd+1, &fds, 0, 0, &timeout);
[Attachment #3 (text/html)]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2653.12">
<TITLE>Use poll() instead of select()</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=2>Hello,</FONT>
</P>
<P><FONT SIZE=2> I have done a small test with the very recent kde 3.1 on a \
linux-i686-2.4.20.</FONT> </P>
<P><FONT SIZE=2> I have readed in <A \
HREF="http://www.kegel.com/dkftpbench/Poller_bench.html" \
TARGET="_blank">http://www.kegel.com/dkftpbench/Poller_bench.html</A></FONT> \
<BR><FONT SIZE=2> that poll() is faster than select() on Linux,*BSD and I \
thinked that also in comercial unixes, but I know that poll() is simpler to use than \
select().</FONT></P>
<P><FONT SIZE=2> I have only changed select by poll in the dcop server, \
resulting in a dcop library of 258 bytes less and less memory normaly implies less \
swap and better performance.</FONT></P>
<P><FONT SIZE=2> I have count the number of selects and there are more than 33 \
only in kdelibs.</FONT> </P>
<P><FONT SIZE=2>Regards.</FONT>
</P>
<P><FONT SIZE=2>The diffs are:</FONT>
</P>
<P><FONT SIZE=2>39d38</FONT>
<BR><FONT SIZE=2>< #include <poll.h></FONT>
<BR><FONT SIZE=2>1604,1616c1603,1609</FONT>
<BR><FONT SIZE=2>< </FONT>
<BR><FONT SIZE=2>< // * // \
Convert to poll</FONT> <BR><FONT SIZE=2>< struct pollfd \
fds;</FONT> <BR><FONT SIZE=2>< fds.fd=socket();</FONT>
<BR><FONT SIZE=2>< fds.events=POLLIN;</FONT>
<BR><FONT SIZE=2>< // fd_set fds;</FONT>
<BR><FONT SIZE=2>< // struct timeval \
tv;</FONT> <BR><FONT SIZE=2>< // FD_ZERO( \
&fds );</FONT> <BR><FONT SIZE=2>< // \
FD_SET( socket(), &fds );</FONT> <BR><FONT SIZE=2>< // \
tv.tv_sec = msecs / 1000;</FONT> <BR><FONT SIZE=2>< \
// tv.tv_usec = (msecs % 1000) * 1000;</FONT> \
<BR><FONT SIZE=2>< if (poll \
(&fds,1,msecs)<=0) {</FONT> <BR><FONT SIZE=2>< // \
if ( select( socket() + 1, &fds, 0, 0, &tv ) <= 0 ) \
{</FONT> <BR><FONT SIZE=2>---</FONT>
<BR><FONT SIZE=2>> fd_set \
fds;</FONT> <BR><FONT SIZE=2>> \
struct timeval tv;</FONT> <BR><FONT SIZE=2>> \
FD_ZERO( &fds );</FONT> <BR><FONT SIZE=2>> \
FD_SET( socket(), &fds \
);</FONT> <BR><FONT SIZE=2>> \
tv.tv_sec = msecs / 1000;</FONT> <BR><FONT SIZE=2>> \
tv.tv_usec = (msecs % 1000) * 1000;</FONT> <BR><FONT SIZE=2>> \
if ( select( socket() + 1, \
&fds, 0, 0, &tv ) <= 0 ) {</FONT> <BR><FONT \
SIZE=2>1652,1665c1645,1651</FONT> <BR><FONT SIZE=2>< \
</FONT> <BR><FONT SIZE=2>< // * // Convert it to \
poll</FONT> <BR><FONT SIZE=2>< //fd_set fds;</FONT>
<BR><FONT SIZE=2>< struct pollfd fds;</FONT>
<BR><FONT SIZE=2>< fds.fd=fd;</FONT>
<BR><FONT SIZE=2>< fds.events=POLLIN;</FONT>
<BR><FONT SIZE=2>< </FONT>
<BR><FONT SIZE=2>< // timeval timeout;</FONT>
<BR><FONT SIZE=2>< // timeout.tv_sec = 0;</FONT>
<BR><FONT SIZE=2>< // timeout.tv_usec = 0;</FONT>
<BR><FONT SIZE=2>< // FD_ZERO(&fds);</FONT>
<BR><FONT SIZE=2>< // FD_SET(fd, &fds);</FONT>
<BR><FONT SIZE=2>< int result=poll(&fds,1,0);</FONT>
<BR><FONT SIZE=2>< // int result = select(fd+1, &fds, 0, 0, \
&timeout);</FONT> <BR><FONT SIZE=2>---</FONT>
<BR><FONT SIZE=2>> fd_set fds;</FONT>
<BR><FONT SIZE=2>> timeval timeout;</FONT>
<BR><FONT SIZE=2>> timeout.tv_sec = 0;</FONT>
<BR><FONT SIZE=2>> timeout.tv_usec = 0;</FONT>
<BR><FONT SIZE=2>> FD_ZERO(&fds);</FONT>
<BR><FONT SIZE=2>> FD_SET(fd, &fds);</FONT>
<BR><FONT SIZE=2>> int result = select(fd+1, &fds, 0, \
0, &timeout);</FONT> </P>
</BODY>
</HTML>
_______________________________________________
Kde-optimize mailing list
Kde-optimize@mail.kde.org
http://mail.kde.org/mailman/listinfo/kde-optimize
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic