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

CPU usage is pretty high than previous v5.0.6 #2625

Closed
xygwfxu opened this issue Dec 12, 2020 · 52 comments
Closed

CPU usage is pretty high than previous v5.0.6 #2625

xygwfxu opened this issue Dec 12, 2020 · 52 comments

Comments

@xygwfxu
Copy link

xygwfxu commented Dec 12, 2020

when compared with previous 5.0.6, my xiaomi10 shows cpu is very high, almost 100% with full 8 core running.

when downgrade the v5.0.6, cpu becomes normal.

They are using same profile.

@madeye
Copy link
Contributor

madeye commented Dec 12, 2020

When you claim anything about CPU usage, make sure you post the battery usage info here.

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

@xygwfxu
Copy link
Author

xygwfxu commented Dec 12, 2020

from setting, it shows 28% battery used in minutes. and it's 0.7% while for 5.0.6。

before I filed this issue, I tried several time to make sure that issue is from this app. I am an Android app test QA(just to tell that I have some background of test Android.)

@madeye
Copy link
Contributor

madeye commented Dec 12, 2020

Make sure provide the batterystats info, you can dump the stats with this command:

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

@notsure2
Copy link

notsure2 commented Dec 15, 2020

I'm seeing this myself, this is idle phone sleeping:

image
Battery Stats here

@madeye

Realme 7 Pro Latest firmware Android 10

I will test with 5.1.4 and 5.0.6

@notsure2
Copy link

@madeye with 5.0.6 issue completely not present.
Without change any setting or profile upgrade to 5.1.4 issue appears, 5.1.6 same issues.

The issue is like this: When any app makes any network activity that needs to be proxied, libsslocal consumes very high CPU during the activity and even after the network traffic stops it keeps consuming high CPU.

Over time, one or two or three apps do network activity, result: libsslocal 100% CPU all cores for long time.

@notsure2
Copy link

If it helps, in my profile I have Redirect IPv6 enabled, I have Bypass Local Route, and I use 8.8.8.8 custom DNS. Also I have Apps VPN mode bypass, and I have a list of apps excluded from Shadowsocks.

@madeye
Copy link
Contributor

madeye commented Dec 15, 2020

It looks you enabled UDP fallback.

Can you disable UDP fallback and try again?

@notsure2

@notsure2
Copy link

@madeye The issue seems to be solved by disabling UDP fallback, however this is an important feature, I hope it can be fixed soon :-) Any explanation of the problem ? I am curious, was it packet looping or something like that ?

@madeye
Copy link
Contributor

madeye commented Dec 15, 2020

It could be a bug in previous versions of shadowsocks-rust.

I'll provide you a new APK to try out.

@notsure2

@notsure2
Copy link

@madeye I reported how timeout is completely broken in ss-rust, maybe it is wise to switch to ss-libev temporarily until ss-rust stabilizes. It's very obvious and clear that ss-rust is still in "development" phase unlike ss-libev which already passed the stabilization phase...

@madeye
Copy link
Contributor

madeye commented Dec 15, 2020

@madeye
Copy link
Contributor

madeye commented Dec 15, 2020

We need to move on... 😊

With shadowsocks-rust, we can have better performance, DNS based ACL support, and many other important features for the future development.

You can still use 5.0.6 as a stable version.

So, just be patient...

@notsure2
Copy link

notsure2 commented Dec 15, 2020

Hello,
Unfortunately, the test build improves the situation only slightly, it spikes only 1 core to 100% but it still acts the same. The bug is still there in shadowsocks-rust ...

The problem with using the old as stable is that the Play Store will auto update it against my will and I don't want to turn off auto updates on the whole phone. Is it possible perhaps to make a second "Legacy" build or "bug fix only" build with the 5.0.6 code base, or make an apk not connected to the play store so that it doesn't auto update ? At least for some months maybe until shadowsocks-rust is in a better shape. Maybe even release 2nd shadowsocks app in the store "legacy" version.

I expect still many more bugs in the near future because I can see the team is doing heavy refactoring and rebuilding which always introduces issues especially when there is no full exhaustive regression test suite.

Note: The UI in the test build is messed up a bit, the bottom part of the UI is rendered behind the navigation button bar like it's a full screen app...

@madeye
Copy link
Contributor

madeye commented Dec 16, 2020

@Mygod Can you reproduce this locally? I cannot reproduce it on any of my devices locally.

@notsure2 Please try these two APKs:

  1. https://www.dropbox.com/s/c90g3ab0foorv16/shadowsocks-rust-1.8.23.apk
  2. https://www.dropbox.com/s/sw2lbmj6ftl1o0a/shadowsocks-rust-1.9.0.apk

@Mygod
Copy link
Contributor

Mygod commented Dec 16, 2020

ablobsleep

@notsure2
Copy link

notsure2 commented Dec 16, 2020

Hello @Mygod @madeye
I have investigated more deeply. I discovered that the UDP relay on my server is not working. When I fixed it, the high CPU usage issue disappeared, even the latest official 5.1.6 version.

shadowsocks-rust-1.9.0: UDP doesn't work at all, no UDP packets sent at all even with working server.
shadowsocks-rust-1.8.23: UDP relay works with different server without high CPU usage. But high CPU issue with the non-working server.

So there is a bug, but the bug is less severe, the high CPU usage occurs when the UDP relay connection is not working. So that's how to reproduce it.

Make a UDP relay on non-working server and then the broken behavior will happen.

ss-libev was simply not working, but it was correctly not working without making high CPU usage.

@madeye
Copy link
Contributor

madeye commented Dec 16, 2020

Make a UDP relay on non-working server and then the broken behavior will happen.

I cannot reproduce this locally. The only reason I can think of is that your system keep sending UDP packets to remote if there's no response.

IMO, it's a third-party bug of Xiaomi devices due to some backdoor service? Maybe switching to a pixel phone?

Also, please try this APK: https://www.dropbox.com/s/sw2lbmj6ftl1o0a/shadowsocks-rust-1.9.0-new.apk

@madeye
Copy link
Contributor

madeye commented Dec 16, 2020

@zonyitoo Do we have a limit for number of open socket of UDP relay in shadowsocks-rust?

It's possible we are out of sockets and get stuck if the system keep sending UDP packet from different local ports.

@notsure2
Copy link

@madeye i am happy to report with the 1.9.0-new, udp relay is working, and when I intentionally set it to a server with non-working UDP relay, it is not producing the high CPU usage anymore.

Thank you for fast fix :-) Hope to see new version soon.

@zonyitoo
Copy link

zonyitoo commented Dec 16, 2020

@zonyitoo Do we have a limit for number of open socket of UDP relay in shadowsocks-rust?

It's possible we are out of sockets and get stuck if the system keep sending UDP packet from different local ports.

Yes, set udp_max_associations to the limit you want.

In v1.9.0, this configuration will have a defult value 256. (not merged yet).

@madeye
Copy link
Contributor

madeye commented Dec 16, 2020

Cool! I guess it's because @zonyitoo limit the number to 256 now in v1.9.0.

Let me fix this in master branch as well.

@zonyitoo
Copy link

I haven't solve that in the master branch yet. https://github.com/shadowsocks/shadowsocks-rust/blob/a7c9f75d0767f5d8b8f2d23c6a8f70278429819f/shadowsocks/src/relay/udprelay/association.rs#L686-L690

So if your problem is solved, please make sure that you are compiling with the feature-separate-crates branch.

@madeye
Copy link
Contributor

madeye commented Dec 16, 2020

Sure, I will try that branch instead.

@madeye
Copy link
Contributor

madeye commented Dec 16, 2020

For now, we set udp_max_associations to 256 with shadowsocks-rust 1.8.23.

We will have a release soon for all the critical issues found recently.

@xygwfxu
Copy link
Author

xygwfxu commented Dec 17, 2020

I just tested v5.1.7 on xiaomi 10 (android 11). Now with monitoring cpu usage, only one 2.84G core is 100% running, other 7 cores are in idle status. Not sure how I can help on this for more.

My profile don't have "UDP relay" option, my profile is simple, just host, port, encryption, china-bypass, 4 options.

Since we cannot stop xiaomi sending stupid UDP packets(if you were rigth), is that impossible to fix at all?

@madeye
Copy link
Contributor

madeye commented Dec 17, 2020

@xygwfxu
Copy link
Author

xygwfxu commented Dec 17, 2020

@madeye does v5.1.7 not contain fix from shadowsocks-rust-1.9.0-new.apk?
Let me try this one and update you soon.

@xygwfxu
Copy link
Author

xygwfxu commented Dec 17, 2020

@madeye wow, what magic you made, that's too awesome!!!
I cannot reproduce cpu high usage on the apk you sent(1.9.0) .

Appreciated your great helps again.

@madeye
Copy link
Contributor

madeye commented Dec 17, 2020

@zonyitoo Anything changed in UDP relay in 1.9.0, except udp_max_associations?

@madeye madeye reopened this Dec 17, 2020
@zonyitoo
Copy link

Everything changes in v1.9.0. :P .. which is completely refactored.

@zonyitoo
Copy link

Now with monitoring cpu usage, only one 2.84G core is 100% running, other 7 cores are in idle status.

So there must be a infinite loop, did you see anything related via logging output?

@madeye
Copy link
Contributor

madeye commented Dec 17, 2020

The 1.9.0 apk I provided is still using the master branch.

So I think there is some key change to UDP association on master branch recently, which fixed the issue here.

@xygwfxu
Copy link
Author

xygwfxu commented Dec 17, 2020

@zonyitoo The log is adb logcat right?

@zonyitoo
Copy link

I have no idea. Where did sslocal's output log store? @madeye

@xygwfxu
Copy link
Author

xygwfxu commented Dec 18, 2020

No luck on logcat, no logfile for libsslocal.so according to /proc/pid/fd (there are about 40 socket opened).
19582 u0_a237 20 0 66M 42M 3.2M R 90.9 1.1 5:21.68 libsslocal.so libsslocal.so

@xygwfxu
Copy link
Author

xygwfxu commented Dec 18, 2020

I use strace to attach this proc, and see same line below but copy to few thousands in second:

[7fd4cf9c80] 21013: recvfrom (33 socket:[7135356],(0x7eaef7b880),65536,0x0,0x0) = -11 (Try again)
[7fd4cf9c80] 21013: recvfrom (24 socket:[7131949],(0x7eae60db80),65536,0x0,0x0) = -11 (Try again)

@zonyitoo
Copy link

[7fd2276720] 19582: recvfrom (25 socket:[7091543],(0x787c3e9140),65536,0x0,0x0) = -11 (Try again)

Could you verify that those thousands of recvfrom is for the same fd?

@xygwfxu
Copy link
Author

xygwfxu commented Dec 18, 2020

Just tried again, two sockets in looply.

@zonyitoo
Copy link

What is that -11 (Try again) means? EAGAIN?

@xygwfxu
Copy link
Author

xygwfxu commented Dec 18, 2020

should be: #define EAGAIN 11 /* Try again */

@zonyitoo
Copy link

I think that must be a bug in tokio. The recvfrom call should only be used for UDP sockets in this project. If sockets returned EAGAIN, tokio should register readiness event and yield the current coroutine.

@madeye
Copy link
Contributor

madeye commented Dec 18, 2020

It's quite weird that recvfrom for UDP socket would get EAGAIN.

@zonyitoo
Copy link

@xygwfxu Have you seen any ERROR outputs in stderr/stdout?

@xygwfxu
Copy link
Author

xygwfxu commented Dec 18, 2020

@zonyitoo It's an android phone, I not sure how to get stderr/stdout from sslocal anyway.

@zonyitoo
Copy link

Have you redirect sslocal's output to files? @madeye

@madeye
Copy link
Contributor

madeye commented Dec 18, 2020

To get the log from sslocal, just type adb logcat -s libsslocal.

@xygwfxu
Copy link
Author

xygwfxu commented Dec 22, 2020

Look like I see some error:
12-18 10:51:43.825 17193 17647 E libsslocal: 2020-12-18T10:51:43.824524481+08:00 ERROR TCP socks5 client exited with error: CONNECT 15.xx.xx.82:33445 failed with error "Connection timed out (os error 110)"
12-18 10:51:45.489 17193 17647 E libsslocal: 2020-12-18T10:51:45.489345053+08:00 ERROR TCP socks5 client exited with error: early eof
12-18 10:51:45.491 17193 17647 E libsslocal: 2020-12-18T10:51:45.490943282+08:00 ERROR TCP socks5 client exited with error: early eof
12-18 10:52:53.573 17193 17647 E libsslocal: 2020-12-18T10:52:53.560304090+08:00 ERROR UDP association recv 127.0.0.1:42768 <- .., error: Connection refused (os error 111)

@zonyitoo
Copy link

zonyitoo commented Dec 22, 2020

12-18 10:52:53.573 17193 17647 E libsslocal: 2020-12-18T10:52:53.560304090+08:00 ERROR UDP association recv 127.0.0.1:42768 <- .., error: Connection refused (os error 111)

That's strange. It seems that the endpoint returns an ICMP failure.

@xygwfxu
Copy link
Author

xygwfxu commented Dec 29, 2020

Verified at v5.1.8, cpu high usage is not able to reproduce.

@xygwfxu xygwfxu closed this as completed Dec 29, 2020
Mygod added a commit that referenced this issue Apr 16, 2021
JackyAnn added a commit to JackyAnn/shadowsocks-android that referenced this issue Sep 22, 2022
* Allow user to keep data when uninstalling (shadowsocks#2506)

* Update README.md

* Update dependencies

* Add cargo clean task

* Enable LTO

* Speed up rebuild

* Update issue templates with labels

* Update dependencies

* Fix output name second attempt

* Update NDK

* Ensure cargoBuild is ran before mergeJniLibFolders

* Bump version

* Refine release build process

* Refine gradle files

* Add RUST_BACKTRACE

* Use rethrowAsSocketException

* Suppress write errors to protect_path

* Update shadowsocks-rust

* Bump version

* Improve accessibility

* Rename cipher plain to none

* Revert "Add RUST_BACKTRACE"

This reverts commit fdff88e.

ndk-stack should be used instead.

* Use cp.cloudflare.com for connectivity test

Credits: https://www.v2ex.com/t/656983#r_8748918

* Update dependencies

* Remote DNS setting is enabled unconditionally

* Show more information on conflicting plugins

Because one of you feckers just cannot learn to be decent.

* Add support for PTR queries

* Prevent querying PTR on custom Network

* Suppress network unspecified exceptions

* Handle IOException while reading

* Refine handling duplicate plugins

* Use any address as default DNS

* Suppress EACCES for ProtectWorker

* Clean up unused code

* Do not suppress IOException

* Disable UDP relay if plugin is enabled and no fallback

* Remove unnecessary isExperimental

* Update dependencies

* Fix unchecked cast

* Do not use WorkManager in device storage

* Remove unnecessary directBootAware overloading

* Suppress BadConfigurationProvider

* Disable RemoveWorkManagerInitializer lint for apps

* Update to Android 11 beta 1

* Request QUERY_ALL_PACKAGES for mobile

* Refine code style

* Fix ambiguous coroutineContext

* Downgrade coroutines

* Update dependencies

* Deprecate using Handler

* Fix shadowsocks#2546

* Only match exported plugins

* Update dependencies

* Update dependencies

* Migrate to ML kit for scanning QR code

Fixes shadowsocks#2548.

* Make scanner immersive

* Lock orientation to prevent camera recreation

* Fix missing Serializable declaration

* Add missing serialVersionUID

* Update dependencies

* Partially migrate to ActivityResultContracts

AlertDialogFragment will be migrated after the API goes stable.

* Add ActionBar to oss activity

* Add ActionBar to details activity

* Refine Scanner

* Bump version

* Update dependencies

* Suppress cancellation exceptions

* Skip processing if EOS is reached

* Refine PTR compat

* Fix shadowsocks#2557

* Fix shadowsocks#2562

* Update Android gradle

* Set VPN flag properly

Refine shadowsocks#2562.

* Drop support for Android Lollipop

* Update dependencies

* Remove UDP upstream DNS support. Fix shadowsocks#2564 shadowsocks#2518

* Update shadowsocks-rust

* Update dependencies

* Decouple main dependencies from plugin lib

* Simplify code

* Add missing type

* Update dependencies

* Deprecate old backup mechanism for Android 5-

* Update leanback theme to appcompat

* Use singleTask launchMode

* Fix build

* Bump version

* Update dependencies

* Update dependencies

* Bump plugin lib version to 2.0.0

* Add isV2 to PluginManager.InitResult

* Pass a value with the VPN option, if plugin version < 2.0

* Switch to __android_vpn

* Remove unnecessary parentheses

* Update shadowsocks-rust

* Bump version

* Clean up and bump version

* Revert camera-view back to alpha17

* Bump version

* Update dependencies

* Migrate away from deprecated APIs with core 1.3.0-alpha05

* Clean up code

* Refine code style

* Remove old ciphers. Fix shadowsocks#2621

* Enable single-threaded

* Update shadowsocks-rust to 1.8.23

* Use Parcelize for TrafficStats

* Fix platform insets on API 29-

* Fix shadowsocks#2623

* Update barcode-scanning

* Fix shadowsocks#2571

* Refine error message

* Refine shadowsocks#2571

* Limit open sockets to 256 in UDP association. Fix shadowsocks#2625

* Bump version

* Fix little problem of profile switching

* Update shadowsocks-rust to 1.9.0 (shadowsocks#2622)

* Fix shadowsocks#2638

* Bump version

* Switch to local UDP DNS resolver (shadowsocks#2635)

* Switch to the local UDP DNS resolver

* Update shadowsocks-rust

* Revert the rustup commands

* Fix shadowsocks#2642

* Fix the ByteBuffer allocation

* Update shadowsocks-rust

* Revert to local UDS resolver

Fix shadowsocks#2650

* Check deprecated ciphers (shadowsocks#2651)

* Bump version

* Fix shadowsocks#2301

* Bump version

* Remove the non-ietf chacha20 and salsa20 ciphers

* Fix shadowsocks#2665

* Update dependencies

* Fix deprecation of kotlin extensions

* Remove unused gcm work library for API 23+

* Use work-multiprocess

* Refine code style

* Update dependencies (shadowsocks#2672)

* Update dependencies

* Refine code style

* Bump gradle to 6.8.2

* Drop packet if out of buffer

* Refine error message

* Enlarge the buffer size of a UDP connection

* Bump version

* Ignore all exceptions whilst updating subscriptions

* Refine the JSON config file for ss-rust 1.10

* Refine the code style

* Update shadowsocks-rust to v1.10.3

* Fix shadowsocks#2679

* Update dependencies

Fixes shadowsocks#2699.

* Fix deprecation of adapterPosition

* Bump plugin to 2.0.1

* Migrate AlertDialogFragment to fragment result API

* Remove useless dependency update

* Migrate the rest to fragment result API

* Remove unused field

* Prevent crashing on shitty ROMs

* Add search tool for profiles (shadowsocks#2682)

* Suppress logging unsupported query type errors

* Ignore if connection was prematurely closed

* Use default udp_timeout=300 instead

Refine shadowsocks#2625.

* Mark underlyingNetwork as volatile

Attempts at addressing shadowsocks#2667.

* Fixed required targetFragments for preference

* Downgrade gradle plugin

* Update shadowsocks-rust and add back some ciphers

Fix shadowsocks#2705 and shadowsocks#2663.

* Update dependencies

* Check plugin properly

Fix shadowsocks#2667.

* Check crypto before init

* Make code style more Kotlin

* Update core and remove workaround

* Refine search to respect locale

* Double fixes touch target

* Resolve server name dynamically always (shadowsocks#2731)

Fixes shadowsocks#2722.

* Bump version

* Downgrade fragment to 1.3.2

Fixes shadowsocks#2733.

* Make plugin library depend on minimum version instead

* Enable Parallel GC

* Set useLegacyPackaging

* Update the maven publish plugin (shadowsocks#2734)

1. Remove the unnecessary custom URL
2. Replace jcenter with mavenCentral

* Handle illegal profiles properly

* Fix windows build failed shadowsocks#2666 shadowsocks#2711

* Allowed build under msys2 or cygwin

* Update dependencies

* Bring back semitransparent TV app via build variants (shadowsocks#2741)

This creates two variants for tv, freedom containing the original design, and google containing one matching Google's nonsense guideline. The former should be published on GitHub and elsewhere.

Revert "Revert "Revert "Revert "Revert "Make app fullscreen to match guidelines"""""

This reverts commit 0c67ac6.

* Fix typo

* Show full proxied apps mode to compensate for missing title

* Use MaterialAlertDialogBuilder

* Add progress indicator to ServiceButton

* Remove elevation from progress

* Only show progress for connecting

* Only show progress when connecting is taking too long

* Bump version

* Update dependencies

* Update sdk to S

* Use registerBestMatchingNetworkCallback

* Use OsConstants.ENONET

* Deal with new requirements

* Use main thread for default network callback on API 26+

* Remove unused code

* Fix duplicate authentication

* Update dependencies

* Bump version

* More stupid Android 6 bugs

* Update dependencies

* Downgrade leanback-preference

* Update to API 31

* Remove STORAGE permission on Android 10+

* Update dnsjava

* Ensure that redirects are always followed

Fixes shadowsocks#2786, shadowsocks#2791.

* Update dependencies

* Update to AGP 7.0.2

* Fix lint

* Update dependencies

* Fix shadowsocks#2803

* Remove extra file

* v5.2.6

* Revert "Show full proxied apps mode to compensate for missing title"

This reverts commit d21cf7b.

Fixes shadowsocks#2806.

* Add linkedin.com to gfwlist

* Fix Codacy badge

* Update dependencies

* Update .gitignore

ignore DS_Store

* Just to satisfy the obsessive-compulsive disorder :-)

* Update shadowsocks-rust

Update rust  dependency

* add new ciphers feature, and reorder cipher name

* Modify acl rules

* Update config.yml

try to fix up the rust build error

* enable armv8, neon feathures for hardware acceleration.

* Fix the missing springAnimator

* Update shadowsocks-rust to v1.15.0-alpha.5

* Bump version

* Update translations

Fixes shadowsocks#2867.

* Add German and Ukrainian translations

* Misc fixes

* Fix order

* Use system resolver

* Update dependencies

* Declare POST_NOTIFICATIONS

* Protect sensitive profile information when copied

* Add support for monochrome icons (not recommended)

* Declare supported languages

* Require authentication for closing service

* Support skipping animation in StatsBar

* Downgrade AGP

* Misc fixes

* Turn on fun switch

* Remove useless code

* Bump version

* Fix the compile error shadowsocks#2930 (shadowsocks#2935)

Make checking python version code compatible with windows and *nix

Redefine the python version detection code

Co-authored-by: Mygod <[email protected]>
Co-authored-by: Mygod <[email protected]>
Co-authored-by: Max Lv <[email protected]>
Co-authored-by: cyber386 <[email protected]>
Co-authored-by: Goooler <[email protected]>
Co-authored-by: SquallATF <[email protected]>
Co-authored-by: dev4u <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants