wrk icon indicating copy to clipboard operation
wrk copied to clipboard

Add support for specifying source IPs for outgoing connections

Open defanator opened this issue 8 years ago • 2 comments

Introduced the -b (or --bind-ip) command line option, that can accept either single IP address, or CIDR mask, e.g.:

wrk -b 127.0.0.2 http://localhost/
wrk -b 127.0.0.1/28 http://localhost/

In addition, the IP_BIND_ADDRESS_NO_PORT socket option is being used on supported systems (Linux >= 4.2, glibc >= 2.23) in order to get even more concurrent connections due to an ability to share source port (see [1], [2]).

Also, EADDRNOTAVAIL from connect() is now treated as a critical error, leading wrk to quit immediately.

[1] https://kernelnewbies.org/Linux_4.2#head-8ccffc90738ffcb0c20caa96bae6799694b8ba3a [2] https://git.kernel.org/torvalds/c/90c337da1524863838658078ec34241f45d8394d

defanator avatar Mar 03 '17 17:03 defanator

Long time no see! It turned out that using CIDRs with relatively large number of free IPs with multiple threads on fast platforms might trigger race condition in connect_socket() while choosing next src ip. It was fixed by moving the cidr_range config struct to thread's context instead of using the initial one from shared configuration context:

https://github.com/wg/wrk/pull/262/commits/7eeb706a023c277cdbeaaccb2a14cae8a3ac5fd2

(Tagging @centminmod as I see that this PR was applied to their fork previously.)

(Tagging @wg just in case if 4 years was enough period for this patch to have a thorough rest before being accepted. Maybe.)

defanator avatar Mar 18 '21 13:03 defanator

not work.

faicker avatar Feb 04 '24 11:02 faicker