MetaCubeX / mihomo

A simple Python Pydantic model for Honkai: Star Rail parsed data from the Mihomo API.
https://wiki.metacubex.one
MIT License
15.71k stars 2.57k forks source link

[Bug] high CPU usage when using grpc with trojan/vmess/vless #533

Open remedynotavailable opened 1 year ago

remedynotavailable commented 1 year ago

Verify steps

Clash version

1.14.3 to alpha

What OS are you seeing the problem on?

Linux

Clash config

proxies:
  - name: US+VMESS-gRPC (2023-05-04)
    server: us4.socifiles.com
    port: 443
    type: vmess
    uuid: cee1c580-e4d9-11ed-baaa-1239d0255272
    alterId: 0
    cipher: auto
    tls: true
    skip-cert-verify: true
    servername: us4.socifiles.com
    network: grpc
    grpc-opts:
      grpc-service-name: vmgrpc
    udp: true

Clash log

2023/04/29 19:01:20 protocol error: received DATA after END_STREAM
2023/04/29 19:01:19 protocol error: received DATA after END_STREAM
2023/04/29 19:01:17 protocol error: received DATA after END_STREAM
2023/04/29 19:01:17 protocol error: received DATA after END_STREAM
2023/04/29 19:00:13 protocol error: received DATA after END_STREAM
2023/04/29 19:00:03 protocol error: received DATA after END_STREAM
2023/04/29 18:59:48 protocol error: received DATA after END_STREAM
2023/04/29 18:59:45 protocol error: received DATA after END_STREAM
2023/04/29 18:03:45 protocol error: received DATA after END_STREAM
2023/04/29 18:03:45 protocol error: received DATA after END_STREAM
2023/04/29 18:02:50 protocol error: received DATA after END_STREAM
2023/04/29 18:00:14 protocol error: received DATA after END_STREAM
2023/04/29 17:49:42 protocol error: received DATA after END_STREAM
2023/04/29 17:48:11 protocol error: received DATA after END_STREAM
2023/04/29 17:42:13 protocol error: received DATA after END_STREAM
2023/04/29 17:42:10 protocol error: received DATA after END_STREAM
2023/04/29 17:34:42 protocol error: received DATA after END_STREAM
2023/04/29 17:30:44 protocol error: received DATA after END_STREAM
2023/04/29 17:30:42 protocol error: received DATA after END_STREAM
2023/04/29 17:30:11 protocol error: received DATA after END_STREAM
2023/04/29 17:27:18 protocol error: received DATA after END_STREAM
2023/04/29 17:27:16 protocol error: received DATA after END_STREAM
2023/04/29 17:27:14 protocol error: received DATA after END_STREAM
2023/04/29 17:27:14 protocol error: received DATA after END_STREAM
2023/04/29 17:26:04 protocol error: received DATA after END_STREAM
2023/04/29 17:25:13 protocol error: received DATA after END_STREAM
2023/04/29 17:15:08 protocol error: received DATA after END_STREAM
2023/04/29 17:13:05 protocol error: received DATA after END_STREAM
2023/04/29 17:09:36 protocol error: received DATA after END_STREAM
2023/04/29 17:05:11 protocol error: received DATA after END_STREAM
2023/04/29 17:05:11 protocol error: received DATA after END_STREAM
2023/04/29 17:05:10 protocol error: received DATA after END_STREAM
2023/04/29 17:03:39 protocol error: received DATA after END_STREAM
2023/04/29 17:00:09 protocol error: received DATA after END_STREAM
2023/04/29 16:58:38 protocol error: received DATA after END_STREAM
2023/04/29 16:32:48 protocol error: received DATA after END_STREAM
2023/04/29 16:31:44 protocol error: received DATA after END_STREAM
2023/04/29 16:28:05 protocol error: received DATA after END_STREAM
2023/04/29 16:24:39 protocol error: received DATA after END_STREAM
2023/04/29 16:22:08 protocol error: received DATA after END_STREAM
2023/04/29 16:10:12 protocol error: received DATA after END_STREAM
2023/04/29 16:02:46 protocol error: received DATA after END_STREAM
2023/04/29 15:46:39 protocol error: received DATA after END_STREAM
2023/04/29 15:45:04 protocol error: received DATA after END_STREAM
2023/04/29 15:44:24 protocol error: received DATA after END_STREAM
2023/04/29 15:43:30 protocol error: received DATA after END_STREAM
2023/04/29 15:43:17 protocol error: received DATA after END_STREAM

Description

When using grpc for any trojan/vmess/vless the CPU usage went berserk. It may not immediately pickep up but after a few minutes used for browsing the CPU stuck at 100%. I confirmed it with other proxies the problem is with grpc. Just tried with any free grpc trojan/vmess/vless found on Google. Even after changing the proxy to non grpc it wouldn't goes down. Checked the yacd dashboard there's no ongoing heavy load. It's on idle, dl and ul just around 5kbps. Only after restarting the clash process and removing the grpc proxies it would back to normal. Tried the stable version from last 2022 to alpha it still the same. Also tried boxformagisk(with clash core) for Android the issue persists.

Thanks.

Picrel _20230427_170859

remedynotavailable commented 1 year ago

Apparently it's an old issue that was ignored. https://github.com/Dreamacro/clash/issues/1979#issue-1143190088 It's affecting all h2 protocol. Maybe kindly add the option initial_windows_size

Skyxim commented 1 year ago

@remedynotavailable setting log level is debug, and the continuous usage of CPU is too high. Visit http://${contrller-api}/debug/pprof/profile, wait and upload the downloaded file

remedynotavailable commented 1 year ago

@remedynotavailable setting log level is debug, and the continuous usage of CPU is too high. Visit http://${contrller-api}/debug/pprof/profile, wait and upload the downloaded file

~ $ curl "http://192.168.1.1:9090/version"
{"meta":true,"version":"v1.14.4"}
~ $ curl "http://192.168.1.1:9090/debug/pprof/profile"
404 page not found
~ $

Do I need to compile it with debug tags or something?

Skyxim commented 1 year ago

@remedynotavailable Need to launch with log-level: debug

remedynotavailable commented 1 year ago

Running it with debug for more 3 hours already without cpu spike. Only higher ram and CPU than average. I will wait more.

remedynotavailable commented 1 year ago

Only 1 core 100% used at the moment. I will post again when all cores maxed out. profile (2).log

IMG_20230430_124556

remedynotavailable commented 1 year ago

profile.txt

_20230430_131446

remedynotavailable commented 1 year ago

331 was correct it's only happened when used as upstream DNS by clash. I tried using adguardhome with clash+trojan grpc as upstream. there seems no problem so far though the log still print protocol error: received DATA after END_STREAM. but cpu is normal.

the problem only occured with internal clash dns resolver in combination with grpc.

lux5am commented 7 months ago

@Skyxim can you please consider to add full grpc like sing-box. It can be included with compile time flag. I tried with sing-box it's basically the same result. High CPU and RAM after a while. compiled sing-box with with_grpc tag, the result is very stable. Tho, the performance slightly degraded. Idk maybe just placebo. Tried with speedtest just a bit lower. I tried to do it myself but stuck here and there. I'm new in golang. Thanks.