TIME-WAIT Hack For High Performance Ephemeral Connection in Linux TCP Stack
TIME-WAIT Hack For High Performance Ephemeral Connection in Linux TCP Stack
$ whoami
Engku Ahmad Faisal
github.com/efaisal
twitter.com/efaisal
facebook.com/eafaisal
plus.google.com/u/0/+EAFaisal
$ whoami
Worked with Nexo Prima Sdn Bhd
Open Source Cloud Infrastructure
Virtualisation: oVirt/OpenStack
Storage: Gluster/Ceph
Linux-based solutions
ESTABLISHED
close()/fin
CLOSING
FIN_WAIT_1
fin+a
ck/ac
ack/-
fin/ack
ack/-
TIME_WAIT
Active Close
fin/ack
FIN_WAIT_2
2MSL Timeout
CLOSED
MS Windows - 4 minutes
Linux - 1 minute (hard coded)
ESTABLISHED
fin/ack
close
()/fin
LAST_ACK
ack/-
CLOSED
Passive Close
CLOSE_WAIT
WARNING!
Some resources on the Web wrongly informed their readers to tweak
tcp_fin_timeout to tune TIME-WAIT
Cache
Database
MQ
REST
API
If we have more supporting services (MQ, REST API, etc), there might be more open/close
operations for each request
HTTP is considered ephemeral by nature
SOLUTION 1: tcp_tw_reuse
From Linux doc:
Allow to reuse TIME-WAIT sockets for new connections when it is safe from
protocol viewpoint. Default value is 0. It should not be changed without
advice/request of technical experts.
Commonly recommended to be enabled
$ echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse
Dependent on another kernel param to be enabled: net.ipv4.tcp_timestamps
Does it really work?
INTRODUCING LINUXTCPTW
LINUXTCPTW
Implementation of an old idea
THE PROJECT
Project lives at https://github.com/efaisal/linuxtcptw/
Binary release available for CentOS 6 and 7 at https://github.
com/efaisal/linuxtcptw/releases
Unfortunately not battle tested in production environment yet - any volunteer?
Currently working on Ubuntu 14.04 LTS kernel
THANK YOU