Use poll() instead of select()
Jaime Torres
kde-optimize@mail.kde.org
Thu, 30 Jan 2003 11:15:43 +0100
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_001_01C2C848.8C2E4BC0
Content-Type: text/plain;
charset="iso-8859-1"
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);
------_=_NextPart_001_01C2C848.8C2E4BC0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2653.12">
<TITLE>Use poll() instead of select()</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=3D2>Hello,</FONT>
</P>
<P><FONT SIZE=3D2> 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=3D2> I have readed in <A =
HREF=3D"http://www.kegel.com/dkftpbench/Poller_bench.html" =
TARGET=3D"_blank">http://www.kegel.com/dkftpbench/Poller_bench.html</A><=
/FONT>
<BR><FONT SIZE=3D2> 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=3D2> 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=3D2> I have count the number of selects and there =
are more than 33 only in kdelibs.</FONT>
</P>
<P><FONT SIZE=3D2>Regards.</FONT>
</P>
<P><FONT SIZE=3D2>The diffs are:</FONT>
</P>
<P><FONT SIZE=3D2>39d38</FONT>
<BR><FONT SIZE=3D2>< #include <poll.h></FONT>
<BR><FONT SIZE=3D2>1604,1616c1603,1609</FONT>
<BR><FONT SIZE=3D2>< =
</FONT>
<BR><FONT SIZE=3D2>< =
// * // Convert to poll</FONT>
<BR><FONT SIZE=3D2>< struct pollfd =
fds;</FONT>
<BR><FONT SIZE=3D2>< =
fds.fd=3Dsocket();</FONT>
<BR><FONT SIZE=3D2>< =
fds.events=3DPOLLIN;</FONT>
<BR><FONT SIZE=3D2>< // fd_set =
fds;</FONT>
<BR><FONT SIZE=3D2>< // struct =
timeval tv;</FONT>
<BR><FONT SIZE=3D2>< // =
FD_ZERO( &fds );</FONT>
<BR><FONT SIZE=3D2>< // FD_SET( =
socket(), &fds );</FONT>
<BR><FONT SIZE=3D2>< // =
tv.tv_sec =3D msecs / 1000;</FONT>
<BR><FONT SIZE=3D2>< // =
tv.tv_usec =3D (msecs % 1000) * 1000;</FONT>
<BR><FONT SIZE=3D2>< if (poll =
(&fds,1,msecs)<=3D0) {</FONT>
<BR><FONT SIZE=3D2>< // if ( =
select( socket() + 1, &fds, 0, 0, &tv ) <=3D 0 ) {</FONT>
<BR><FONT SIZE=3D2>---</FONT>
<BR><FONT SIZE=3D2>> =
fd_set fds;</FONT>
<BR><FONT SIZE=3D2>> =
struct timeval tv;</FONT>
<BR><FONT SIZE=3D2>> =
FD_ZERO( &fds );</FONT>
<BR><FONT SIZE=3D2>> =
FD_SET( socket(), &fds );</FONT>
<BR><FONT SIZE=3D2>> =
tv.tv_sec =3D msecs / 1000;</FONT>
<BR><FONT SIZE=3D2>> =
tv.tv_usec =3D (msecs % 1000) * 1000;</FONT>
<BR><FONT SIZE=3D2>> =
if ( select( socket() + 1, &fds, 0, 0, &tv ) =
<=3D 0 ) {</FONT>
<BR><FONT SIZE=3D2>1652,1665c1645,1651</FONT>
<BR><FONT SIZE=3D2>< </FONT>
<BR><FONT SIZE=3D2>< // * // Convert it to =
poll</FONT>
<BR><FONT SIZE=3D2>< //fd_set fds;</FONT>
<BR><FONT SIZE=3D2>< struct pollfd =
fds;</FONT>
<BR><FONT SIZE=3D2>< fds.fd=3Dfd;</FONT>
<BR><FONT SIZE=3D2>< =
fds.events=3DPOLLIN;</FONT>
<BR><FONT SIZE=3D2>< </FONT>
<BR><FONT SIZE=3D2>< // timeval timeout;</FONT>
<BR><FONT SIZE=3D2>< // timeout.tv_sec =3D =
0;</FONT>
<BR><FONT SIZE=3D2>< // timeout.tv_usec =3D =
0;</FONT>
<BR><FONT SIZE=3D2>< // FD_ZERO(&fds);</FONT>
<BR><FONT SIZE=3D2>< // FD_SET(fd, =
&fds);</FONT>
<BR><FONT SIZE=3D2>< int =
result=3Dpoll(&fds,1,0);</FONT>
<BR><FONT SIZE=3D2>< // int result =3D =
select(fd+1, &fds, 0, 0, &timeout);</FONT>
<BR><FONT SIZE=3D2>---</FONT>
<BR><FONT SIZE=3D2>> fd_set fds;</FONT>
<BR><FONT SIZE=3D2>> timeval timeout;</FONT>
<BR><FONT SIZE=3D2>> timeout.tv_sec =3D =
0;</FONT>
<BR><FONT SIZE=3D2>> timeout.tv_usec =3D =
0;</FONT>
<BR><FONT SIZE=3D2>> =
FD_ZERO(&fds);</FONT>
<BR><FONT SIZE=3D2>> FD_SET(fd, =
&fds);</FONT>
<BR><FONT SIZE=3D2>> int result =3D =
select(fd+1, &fds, 0, 0, &timeout);</FONT>
</P>
</BODY>
</HTML>
------_=_NextPart_001_01C2C848.8C2E4BC0--