I cant explain why you test is so slow. But usually, we use socket in
non-blocking mode.
On server side, you should watch whether the listening socket is
readable,. when it's readable, you can non-blocking accept().
On client side, you should watch write event on the connecting socket.
when socket is writeable, it means connect() finished.
I write a simple client side app in blocking mode which connecting to my
server(using libev) in a for loop. result shows that performance is
much better than yours.
client side source code:
int total_count = 1024, connected_count=0, connect_error_count=0;
struct sockaddr_in s_in_;
if(SOCKET_FAIL(util_sock_set_addr(&s_in_, "127.0.0.1", 1080)))
return -1;
double start_time = util_precise_time();
int left_count = total_count;
while(left_count>0)
{
SOCKET fd = util_tcp_sock();
if(INVALID_SOCKET!=fd)
{
if(SOCKET_SUCCESS(util_sock_connect(fd, &s_in_)))
{
++connected_count;
std::cout << "No." << connected_count << "
connected" << std::endl;
}
else
{
++connect_error_count;
std::cout << util_strerr(util_errno()) << std::endl;
}
close(fd);
}
--left_count;
}
double end_time = util_precise_time();
std::cout << "connected count : " << connected_count << std::endl;
std::cout << "connect_error count : " << connect_error_count <<
std::endl;
std::cout << "total time used : " << end_time-start_time <<
std::endl;
std::cout << "avg: " << (end_time-start_time)/total_count <<
std::endl;
Output:
connected count : 1024
connect_error count : 0
total time used : 0.052923
avg: 5.16826e-05
_______________________________________________
libev mailing list
[email protected]
http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev