twitter / twemproxy

A fast, light-weight proxy for memcached and redis
Apache License 2.0
12.15k stars 2.06k forks source link

Reduce one syscal for fcntl #660

Open theidexisted opened 2 years ago

theidexisted commented 2 years ago

According to the man page: https://man7.org/linux/man-pages/man2/socket.2.html Since Linux 2.6.27, the type argument serves a second purpose: in addition to specifying a socket type, it may include the bitwise OR of any of the following values, to modify the behavior of socket():

   SOCK_NONBLOCK
          Set the O_NONBLOCK file status flag on the open file
          description (see open(2)) referred to by the new file
          descriptor.  Using this flag saves extra calls to fcntl(2)
          to achieve the same result.

Problem

Minor fix to save one syscall

Solution

Pass the SOCK_NONBLOCK flag via socket

Result

Chances to get better performance.

CLAassistant commented 2 years ago

CLA assistant check
All committers have signed the CLA.

yuerugou54 commented 2 years ago

马晓栋已经收到您的来件,谢谢!