Subscribed unsubscribe Subscribe Subscribe

Hateburo: kazeburo hatenablog

Operations Engineer / Site Reliability / 運用系小姑 / Perl Monger

Monoceros supports accept4(2)

tokuhirom released Linux::Socket::Accept4 that provides accept4(2)
Monoceros-0.25 uses accept4 if Linux::Socket::Accept4 is avaliable.

accept4(2) can set FD_CLOEXEC and O_NONBLOCK in one system call.

Monoceros-0.24

select(16, [4 10], NULL, NULL, {1, 0})  = 1 (in [4], left {0, 999997})
accept(4, {sa_family=AF_INET, sin_port=htons(41296), sin_addr=inet_addr("127.0.0.1")}, [16]) = 6
ioctl(6, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fffc03016c0) = -1 EINVAL (Invalid argument)
lseek(6, 0, SEEK_CUR)                   = -1 ESPIPE (Illegal seek)
ioctl(6, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fffc03016c0) = -1 EINVAL (Invalid argument)
lseek(6, 0, SEEK_CUR)                   = -1 ESPIPE (Illegal seek)
fcntl(6, F_SETFD, FD_CLOEXEC)           = 0
fcntl(6, F_SETFL, O_RDONLY|O_NONBLOCK)  = 0
setsockopt(6, SOL_TCP, TCP_NODELAY, [1], 4) = 0
read(6, "GET / HTTP/1.0\r\nHost: localhost:"..., 131072) = 82
gettimeofday({1381121587, 895814}, NULL) = 0
write(6, "HTTP/1.1 200 OK\r\nDate: Mon, 07 O"..., 112) = 112
close(6)                                = 0

Monoceros-0.25

select(16, [4 10], NULL, NULL, {1, 0})  = 1 (in [4], left {0, 999997})
accept4(4, {sa_family=AF_INET, sin_port=htons(42605), sin_addr=inet_addr("127.0.0.1")}, [16], SOCK_CLOEXEC|SOCK_NONBLOCK) = 6
setsockopt(6, SOL_TCP, TCP_NODELAY, [1], 4) = 0
read(6, "GET / HTTP/1.0\r\nHost: localhost:"..., 131072) = 82
gettimeofday({1381121654, 200708}, NULL) = 0
write(6, "HTTP/1.1 200 OK\r\nDate: Mon, 07 O"..., 112) = 112
close(6)                                = 0

Monoceros-0.25 also skips lseek and ioctl system calls. Perlio layer add these system calls. so I added "use open IO => :unix" before accept().

In my benchmarking, there are no performance effects with accept4. hmmm