klzgrad / naiveproxy

Make a fortune quietly
BSD 3-Clause "New" or "Revised" License
6.68k stars 885 forks source link

是否支持单端口复用? #629

Closed sophauer closed 8 months ago

sophauer commented 8 months ago

我想把旁路由的CPU效能发挥起来,每个Core执行一个naiveproxy线程,全listen在同一个1080端口 但貌似naiveproxy的usage文档里找不到关于port reuse的描述

请问是否不支持单端口复用? 如果是,有没有其他路线可以实现?

5l2 commented 8 months ago

每个Core执行一个naiveproxy线程,全listen在同一个1080端口

Why for that?

sophauer commented 8 months ago

每个Core执行一个naiveproxy线程,全listen在同一个1080端口

Why for that?

旁路由支撑一百多台电脑翻墙,单一个naiveproxy只用一个CPU Core,负载太高., 所以用4个线程.,listten在同一个端口.可以发挥软路由最大性能

5l2 commented 8 months ago

No possible. Different processes cannot use the same TCP port.

sophauer commented 8 months ago

No possible. Different processes cannot use the same TCP port.

ss-libev,xray.v2ray,都有这个功能

5l2 commented 8 months ago

Because naiveproxy does not support the SO_REUSEPORT option. Oh, it looks like the option has been added to support in the latest commit.

sophauer commented 8 months ago

~Because naiveproxy does not support the SO_REUSEPORT option.~ Oh, it looks like the option has been added to support in the latest commit.

yes,我也是刚看到,但是似乎还没更新下载.只能自己compile

klzgrad commented 8 months ago

https://github.com/klzgrad/naiveproxy/releases/tag/v122.0.6261.43-2

ArcCal commented 8 months ago

https://github.com/klzgrad/naiveproxy/releases/tag/v122.0.6261.43-2

这个版本咋用呢

klzgrad commented 8 months ago

Run 8 workers for port 1080:

for i in $(seq 8); do
  ./naive --listen=socks://0.0.0.0:1080 &
done
Chilledheart commented 8 months ago

It might be better if you pin the process to a specific core such as:

for i in $(seq 8); do
  taskset -c $i ./naive --listen=socks://0.0.0.0:1080 &
done

Ref: https://stackoverflow.com/questions/33994983/assigning-a-cpu-core-to-a-process-linux

zedifen commented 8 months ago

I'm wondering if it would be better (or possible) to harness multiple CPU core by multi-threading within naiveproxy?

Edit: I found https://github.com/valyala/fasthttp/issues/23. Looks like this fork & port reusing approach should be a good practice.