Created
May 27, 2015 14:05
-
-
Save ronin13/e4f00da7c11e897383aa to your computer and use it in GitHub Desktop.
Socat SO_REUSEPORT test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For server: | |
===== | |
for x in {1..10};do detach ./socat -u TCP-LISTEN:50000,reuseport,fork GOPEN:/tmp/socat-$x.log; done | |
For client: | |
====== | |
for x in {1..10};do date +%r | ./socat -u stdio TCP:0.0.0.0:50000; sleep 2s; done | |
Results: | |
/tmp/socat-1.log:07:16:18 PM | |
/tmp/socat-1.log:07:16:24 PM | |
/tmp/socat-10.log:07:16:08 PM | |
/tmp/socat-4.log:07:16:14 PM | |
/tmp/socat-6.log:07:16:06 PM | |
/tmp/socat-7.log:07:16:16 PM | |
/tmp/socat-7.log:07:16:22 PM | |
/tmp/socat-8.log:07:16:10 PM | |
/tmp/socat-8.log:07:16:12 PM | |
/tmp/socat-9.log:07:16:20 PM |
The algorithm used for hashing
net_get_random_once(&inet_ehash_secret, sizeof(inet_ehash_secret));
return __inet_ehashfn(laddr, lport, faddr, fport,
inet_ehash_secret + net_hash_mix(net));
static inline unsigned int __inet_ehashfn(const __be32 laddr,
const __u16 lport,
const __be32 faddr,
const __be16 fport,
u32 initval)
{
return jhash_3words((__force __u32) laddr,
(__force __u32) faddr,
((__u32) lport) << 16 | (__force __u32)fport,
initval);
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With hundred concurrent requests (the earlier ones were serialized), you can see
grep . /tmp/socat*.log | cut -d: -f1 | sort | uniq -c
13 /tmp/socat-1.log
11 /tmp/socat-10.log
17 /tmp/socat-2.log
12 /tmp/socat-3.log
9 /tmp/socat-4.log
9 /tmp/socat-5.log
7 /tmp/socat-6.log
15 /tmp/socat-7.log
10 /tmp/socat-8.log
7 /tmp/socat-9.log