twemproxy icon indicating copy to clipboard operation
twemproxy copied to clipboard

Reduce one syscal for fcntl

Open theidexisted opened this issue 2 years ago • 2 comments

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.

theidexisted avatar Dec 09 '21 03:12 theidexisted