epoll_wait has bigger delay

15 views Asked by At

client and server run on same machine, client connect to server via 127.0.0.1
cient send a msg via two send() call (header and body),
server epoll_wait() and recv() the data,

the problem is that the second wait() has a 40ms delay, which leads to low throughput about 11kB/s.

client log with timestamp

[ 1585038.0005] start send 56  
[ 1585038.0006] end send 56  
[ 1585038.0006] start send 512  
[ 1585038.0006] end send 512  

the server timestamps

[ 1585038.0002] epoll_wait 
[ 1585038.0006] start recv 56
[ 1585038.0006] recv return 56
[ 1585038.0006] start recv 512
[ 1585038.0006] recv return -1
[ 1585038.0006] epoll_wait
[ 1585038.0442] epoll_wait return 1
[ 1585038.0443] start recv 512
[ 1585038.0443] recv return 512

the second epoll_wait() return at 0.442 has an 40ms delay

1

There are 1 answers

1
yuanjianpeng On

I have to disable the nagle algorithm

int socket_set_nagle(int sock, int enable)
{
        int ret;

        ret = setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &enable, sizeof(int));
        if (ret < 0)
                ERROR("set socket nodelay option failed: %m\n");

        return ret;
}