the performance of server written by libev, when the client just do "connect" and "close"

debuguo wateraworld at gmail.com
Thu Nov 24 07:28:01 CET 2011


Hello, everyone:
I am wonderring the performance of server written by libev, when the client
just do "connect" and "close".
the result is so special that I could not explain why.
here is the pseudocode for test.

*SERVER*:

> static void acceptcallback(...)

{

clientfd = accept(...);
>
ev_io_stop();
>
ev_io_init(watcher, readcallback, clientfd, EV_READ);
>
ev_io_start(loop, watcher);
>
}

static void readcallback(...)

{

int ret = recv(...);
>
if (ret == 0) {
>
ev_io_init(watcher, acceptcallback, serverfd, EV_READ);
>
ev_io_start(loop, watcher);
>
}
>
}

int main()

{

serverfd = socket(...);
>
bind(...);
>
listen(...);
>
ev_io_init(watcher, acceptcallback, serverfd, EV_READ);
>
ev_io_start(loop, watcher);
>
ev_run(loop, 0);
>
}

*
*
*CLIENT:*

> int main()

{

int count = 1024;
>
gettimeofday(t1, NULL);
>
while(count) {
>
fd = socket(...);
>
connect(...);
>
close(fd);
>
}
>
gettimeofday(t2, NULL);
>
//get the value of t1, t2 and store it in double
>
printf("%f", t2todouble - t1todouble);
>
}

*
*
*RESULT:*
I ran the client for several times, got the result that is almost *0.4
second* at the most of the time, but sometimes it would be *3 sec*.
I cannot explain why got such a big difference when client visit the
server(127.0.0.1) and just do "connect" and "close".

Thank you, everyone.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.schmorp.de/pipermail/libev/attachments/20111124/f4f3c01e/attachment.html>


More information about the libev mailing list