shadowsocks / shadowsocks-rust

A Rust port of shadowsocks
https://shadowsocks.org/
MIT License
8.37k stars 1.15k forks source link

shadowsocks android依赖旧于tokio0.3版本编译的sslocal,看youtube会导致手机过热。 #316

Closed dev4u closed 3 years ago

dev4u commented 3 years ago

我没用其他第三方代码的服务端、客户端。 https://github.com/shadowsocks/shadowsocks-android master分支代码 但是当中的rust子模块,对应的也是当前https://github.com/shadowsocks/shadowsocks-rust 的master代码

客户端主要的编译参数都没改过。只是修改只编译arm64架构的代码,其他架构都不编译。

服务端的编译命令: cargo build --release --bin ssserver rust toolchain:nightly,编译前会先做一次rustup update。 操作系统fedora,具体版本没留意。

IMG_20201113_140151.jpg

IMG_20201113_172241.jpg

用youtube app看视频,如果服务端没有开启udp转发,会导致手机发热得厉害。 如果开启了udp转发,则没有这种现象。

Originally posted by @dev4u in https://github.com/shadowsocks/shadowsocks-rust/pull/315#issuecomment-726541560

zonyitoo commented 3 years ago

I recently test local-dns server on my Raspberry Pi series 1, and I found that DNS resolution consumed a lot CPU time.

Specifically, I set DNS address to RPI's port 53 (sslocal --protocol dns was listening on it) on my Nintendo Switch, when connecting to Nintendo Shop, I saw only a few DNS queries, but CPU usage was already over 90%.

What do you think? @madeye @Mygod

madeye commented 3 years ago

I didn't see any high CPU usage before.

On Android, you can check the CPU time usage through the battery settings. You should see very small numbers there.

madeye commented 3 years ago

To dump the battery stats, please use this command:

adb shell dumpsys batterystats --charged com.github.shadowsocks

A typical output looks like this

    Foreground activities: 5s 82ms realtime (1 times)
    Foreground services: 8h 43m 54s 488ms realtime (1 times) (running)
    Top for: 5s 629ms
    Fg Service for: 8h 43m 54s 488ms
    Total running: 8h 44m 0s 117ms
    Total my running: 8h 44m 0s 117ms
    Total cpu time: u=4m 55s 205ms s=7m 26s 840ms
    Total cpu time per freq: 0 0 0 0 139706 2705 121677 4386 55675 92349 10927 7900 5585 29541 174813 7209 112946 4914 302 1049 488 2625 2306 509 1086 2216 841 698 808 720 1647 2327 423 365 58539 13 0 0 0 0 27 5 2 0 0 0 0 0 0 0 2 0 0 0 941
    Total screen-off cpu time per freq: 0 0 0 0 41191 883 607 445 567 434 1981 508 461 550 1619 606 13749 459 59 30 22 86 399 81 67 659 190 92 74 213 531 260 115 59 9738 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
    Proc com.github.shadowsocks:bg:
      CPU: 28s 490ms usr + 16s 340ms krn ; 0ms fg
    Proc libv2ray.so:
      CPU: 1m 10s 850ms usr + 2m 44s 250ms krn ; 0ms fg
    Proc libtun2socks.so:
      CPU: 18s 880ms usr + 2m 5s 200ms krn ; 0ms fg
    Proc libsslocal.so:
      CPU: 2m 59s 590ms usr + 2m 20s 750ms krn ; 0ms fg
    Proc com.github.shadowsocks:
      CPU: 1s 0ms usr + 880ms krn ; 470ms fg
      1 starts

From the log, you can read only 2m59s total CPU runtime for 8h32m foreground usage from libsslocal.so

zonyitoo commented 3 years ago

On RPI series 1, one DNS query took about 15% ~ 30% CPU usage.

It shouldn't cause by encrypt/decrypt operations between sslocal and ssserver, because it worked fine for redir, tunnel and http.

It seems that ACL-list checking is the one to blame!!

dev4u commented 3 years ago

To dump the battery stats, please use this command:

adb shell dumpsys batterystats --charged com.github.shadowsocks

A typical output looks like this

    Foreground activities: 5s 82ms realtime (1 times)
    Foreground services: 8h 43m 54s 488ms realtime (1 times) (running)
    Top for: 5s 629ms
    Fg Service for: 8h 43m 54s 488ms
    Total running: 8h 44m 0s 117ms
    Total my running: 8h 44m 0s 117ms
    Total cpu time: u=4m 55s 205ms s=7m 26s 840ms
    Total cpu time per freq: 0 0 0 0 139706 2705 121677 4386 55675 92349 10927 7900 5585 29541 174813 7209 112946 4914 302 1049 488 2625 2306 509 1086 2216 841 698 808 720 1647 2327 423 365 58539 13 0 0 0 0 27 5 2 0 0 0 0 0 0 0 2 0 0 0 941
    Total screen-off cpu time per freq: 0 0 0 0 41191 883 607 445 567 434 1981 508 461 550 1619 606 13749 459 59 30 22 86 399 81 67 659 190 92 74 213 531 260 115 59 9738 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
    Proc com.github.shadowsocks:bg:
      CPU: 28s 490ms usr + 16s 340ms krn ; 0ms fg
    Proc libv2ray.so:
      CPU: 1m 10s 850ms usr + 2m 44s 250ms krn ; 0ms fg
    Proc libtun2socks.so:
      CPU: 18s 880ms usr + 2m 5s 200ms krn ; 0ms fg
    Proc libsslocal.so:
      CPU: 2m 59s 590ms usr + 2m 20s 750ms krn ; 0ms fg
    Proc com.github.shadowsocks:
      CPU: 1s 0ms usr + 880ms krn ; 470ms fg
      1 starts

From the log, you can read only 2m59s total CPU runtime for 8h32m foreground usage from libsslocal.so

好,我再遇到类似的问题,我就知道怎么反馈了。感谢指导!