Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single connection throttling #661

Closed
kivvi3412 opened this issue Aug 8, 2024 · 8 comments
Closed

Single connection throttling #661

kivvi3412 opened this issue Aug 8, 2024 · 8 comments

Comments

@kivvi3412
Copy link

kivvi3412 commented Aug 8, 2024

我记得naive是单线程的,理论上来说单线程和多线程速度是一致的
理论上iperf3单线程速度已经达到了700Mbps, 但是naiveproxy实际测速单线程大约在188Mbps, 多线程在500Mbps, 如下所示
我应该如何修改参数?

配置信息

  • 服务端客户端版本信息

    服务端
    /usr/bin/caddy -v
    v2.7.5 h1:HoysvZkLcN2xJExEepaFHK92Qgs7xAiCFydN5x5Hs6Q=
    uname -r
    5.15.0-113-generic
    
    客户端
    ./naive --version
    naive 123.0.6312.40
    uname -r
    5.15.0-117-generic
    
  • 客户端naive配置(没有使用insecure-concurrency=)

    {
      "listen": "socks://127.0.0.1:1080",
      "proxy": "https://user:password@example.com",
      "log": ""
    }
    
  • 服务端和客户端 cat /etc/sysctl.conf 参数计算参考 Google-BDP

    net.ipv4.tcp_window_scaling=1
    net.ipv4.tcp_adv_win_scale=1
    net.ipv4.tcp_moderate_rcvbuf=1
    net.core.rmem_max = 42187500
    net.core.wmem_max = 42187500
    net.ipv4.tcp_rmem = 4096 131072 42187500
    net.ipv4.tcp_wmem = 4096 131072 42187500
    net.core.default_qdisc=fq
    net.ipv4.tcp_congestion_control=bbr
    

速度测试

  • iperf3单线程测试

    user@ubuntu:~$ iperf3 -c example.com -R -P 1
    Connecting to host example.com, port 5201
    Reverse mode, remote host example.com is sending
    [  5] local 192.168.2.7 port 51340 connected to 64.64.64.64 port 5201
    [ ID] Interval           Transfer     Bitrate
    [  5]   0.00-1.00   sec  1.62 MBytes  13.6 Mbits/sec                  
    [  5]   1.00-2.00   sec  57.3 MBytes   481 Mbits/sec                  
    [  5]   2.00-3.00   sec  74.6 MBytes   626 Mbits/sec                  
    [  5]   3.00-4.00   sec  92.2 MBytes   773 Mbits/sec                  
    [  5]   4.00-5.00   sec  92.9 MBytes   779 Mbits/sec                  
    [  5]   5.00-6.00   sec  91.9 MBytes   771 Mbits/sec                  
    [  5]   6.00-7.00   sec  92.6 MBytes   777 Mbits/sec                  
    [  5]   7.00-8.00   sec  91.9 MBytes   771 Mbits/sec                  
    [  5]   8.00-9.00   sec  92.6 MBytes   777 Mbits/sec                  
    [  5]   9.00-10.00  sec  93.1 MBytes   781 Mbits/sec                  
    - - - - - - - - - - - - - - - - - - - - - - - - -
    [ ID] Interval           Transfer     Bitrate         Retr
    [  5]   0.00-10.14  sec   807 MBytes   668 Mbits/sec  27613             sender
    [  5]   0.00-10.00  sec   781 MBytes   655 Mbits/sec                  receiver
    
    iperf Done.
    
  • wget 单线程测试 (大约500Mbps)

    user@ubuntu:~$ wget https://example.com/testfile
    --2024-08-08 10:18:57--  https://example.com/testfile
    Resolving example.com (example.com)... 64.64.64.64
    Connecting to example.com (example.com)|64.64.64.64|:443... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 1073741824 (1.0G)
    Saving to: ‘testfile’
    
    testfile.1          100%[===================>]   1.00G  59.0MB/s    in 16s     
    
    2024-08-08 10:19:14 (62.9 MB/s) - ‘testfile’ saved [1073741824/1073741824]
    
  • 单线程
    iShot_2024-08-08_14 14 59

  • 多线程
    iShot_2024-08-08_14 16 11

TCP吞吐瓶颈分析

使用wireshark分析TCP吞吐量瓶颈,不太清楚是哪里的配置问题, iperf看起来还行,不过有部分包没收到(红色)降低tcp_wmem可以减少
如果客户端的windowsize不加以调整则,单线程和多线程,iperf最高(单线程多线程)速度为188Mbps

  • iperf3_single.pcap
    iShot_2024-08-08_14 30 43

  • naive_single.pcap
    image

  • naive_multi.pcap
    image

  • 作为对比,健康TCP连接如图所示:
    iShot_2024-08-08_14 50 40

@klzgrad
Copy link
Owner

klzgrad commented Aug 8, 2024

如果客户端的windowsize不加以调整则,单线程和多线程,iperf最高(单线程多线程)速度为188Mbps

这句话是什么意思?不通顺,看不懂。

你应该首先解释iperf3和wget的性能差异来自哪里。

然后看服务端和客户端是否有CPU bound的形况。

naiveproxy只是用一个普通TCP socket,并无特殊处理。

@kivvi3412
Copy link
Author

如果客户端的windowsize不加以调整则,单线程和多线程,iperf最高(单线程多线程)速度为188Mbps

这句话是什么意思?不通顺,看不懂。

你应该首先解释iperf3和wget的性能差异来自哪里。

然后看服务端和客户端是否有CPU bound的形况。

naiveproxy只是用一个普通TCP socket,并无特殊处理。

当/etc/sysctl.conf客户端和服务端没修改的时候,wget和iperf3,以及naive单线程/多线程都在188Mbps
当/etc/sysctl.conf修改为上述后,iperf和wget单线程都可以达到最高600~700Mbps,但是naive单线程仍然是188Mbps,多线程可以达到480Mbps(speedtest.net)
我觉得很奇怪,并且找不出是什么原因

@klzgrad
Copy link
Owner

klzgrad commented Aug 8, 2024

你应该自己去查具体socket运行时的内核配置差异。

我没有重现,没做任何内核设置,wget通过直连和通过naiveproxy单线程都可以运行到1000Mbps以上。只是接近1000Mbps时naive的CPU占用较高。

@klzgrad
Copy link
Owner

klzgrad commented Aug 17, 2024

我可以重现,只有在高BDP链路可以重现。

与naive_single.pcap的图例反映类似的问题,netlog可以看到naive运行过程中有停顿。

@kivvi3412
Copy link
Author

我可以重现,只有在高BDP链路可以重现。

与naive_single.pcap的图例反映类似的问题,netlog可以看到naive运行过程中有停顿。

是的,现在就是无法排查出停顿的原因,不知道是否和窗口大小有关

@klzgrad klzgrad changed the title Naiveproxy性能问题_(单线程无法充分利用) Single connection throttling Aug 17, 2024
@klzgrad
Copy link
Owner

klzgrad commented Aug 18, 2024

https://github.com/klzgrad/naiveproxy/releases/tag/v127.0.6533.64-3

@kivvi3412
Copy link
Author

kivvi3412 commented Aug 18, 2024

  • 同样的机器,效果显著
  • image

@klzgrad klzgrad closed this as completed Aug 18, 2024
@Chilledheart
Copy link
Contributor

The local window size can be larger.

Yass is using the same size with curl, aka 1000 MiB for reference curl/curl@de4b016 curl/curl#11043

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants