hmgle / graftcp

A flexible tool for redirecting a given program's TCP traffic to SOCKS5 or HTTP proxy.
GNU General Public License v3.0
2.07k stars 174 forks source link

Feature request: splice() support #52

Closed phantomcraft closed 1 year ago

phantomcraft commented 1 year ago

When I test graftcp (0.4.0) in direct mode with iperf3 I get the following speed:

graftcp --not-ignore-local iperf3 -c 127.0.0.1
Connecting to host 127.0.0.1, port 5201
[  6] local 127.0.0.1 port 49714 connected to 127.0.0.1 port 2233
[ ID] Interval           Transfer     Bitrate         Retr  Cwnd
[  6]   0.00-1.00   sec  2.31 GBytes  19.9 Gbits/sec    0   1.31 MBytes       
[  6]   1.00-2.00   sec  2.33 GBytes  20.0 Gbits/sec    0   1.31 MBytes       
[  6]   2.00-3.00   sec  2.25 GBytes  19.4 Gbits/sec    0   1.31 MBytes       
[  6]   3.00-4.00   sec  2.26 GBytes  19.4 Gbits/sec    0   1.31 MBytes       
[  6]   4.00-5.00   sec  2.44 GBytes  21.0 Gbits/sec    0   1.31 MBytes       
[  6]   5.00-6.00   sec  2.19 GBytes  18.8 Gbits/sec    0   1.31 MBytes       
[  6]   6.00-7.00   sec  2.20 GBytes  18.9 Gbits/sec    0   1.31 MBytes       
[  6]   7.00-8.00   sec  2.25 GBytes  19.3 Gbits/sec    0   1.31 MBytes       
[  6]   8.00-9.00   sec  2.19 GBytes  18.8 Gbits/sec    0   1.31 MBytes       
[  6]   9.00-10.00  sec  2.11 GBytes  18.1 Gbits/sec    0   1.31 MBytes       
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Retr
[  6]   0.00-10.00  sec  22.5 GBytes  19.4 Gbits/sec    0             sender
[  6]   0.00-10.00  sec  22.5 GBytes  19.4 Gbits/sec                  receiver

iperf Done.

When testing with a SOCKS5 server with splice() support and proxychains-ng I get this:

proxychains4 -q iperf3 -c 127.0.0.1
Connecting to host 127.0.0.1, port 5201
[  9] local 127.0.0.1 port 56922 connected to 127.0.0.1 port 1081
[ ID] Interval           Transfer     Bitrate         Retr  Cwnd
[  9]   0.00-1.00   sec  2.99 GBytes  25.6 Gbits/sec    0    512 KBytes       
[  9]   1.00-2.00   sec  3.25 GBytes  27.9 Gbits/sec    5    320 KBytes       
[  9]   2.00-3.00   sec  3.02 GBytes  25.9 Gbits/sec    0    512 KBytes       
[  9]   3.00-4.00   sec  3.23 GBytes  27.7 Gbits/sec    0    512 KBytes       
[  9]   4.00-5.00   sec  3.10 GBytes  26.6 Gbits/sec    1    512 KBytes       
[  9]   5.00-6.00   sec  2.93 GBytes  25.2 Gbits/sec    5    512 KBytes       
[  9]   6.00-7.00   sec  3.03 GBytes  26.0 Gbits/sec    2    512 KBytes       
[  9]   7.00-8.00   sec  3.02 GBytes  26.0 Gbits/sec   11    320 KBytes       
[  9]   8.00-9.00   sec  3.04 GBytes  26.2 Gbits/sec    4    320 KBytes       
[  9]   9.00-10.00  sec  3.04 GBytes  26.1 Gbits/sec    7    512 KBytes       
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Retr
[  9]   0.00-10.00  sec  30.7 GBytes  26.3 Gbits/sec   35             sender
[  9]   0.00-10.00  sec  30.6 GBytes  26.3 Gbits/sec                  receiver

iperf Done.

===============================

Looking in graftcp code and its performance, I can see that it doesn't use splice().

It would be a good idea to implement it and take a little more advantage.

My suggestion.

hmgle commented 1 year ago

It has nothing to do with splice(2). graftcp uses the ptrace(2) resulting in worse performance than proxychains-ng. It can use BPF and prctl to improve performance, see issue #37.