abhinavsingh / proxy.py

💫 Ngrok FRP Alternative • ⚡ Fast • 🪶 Lightweight • 0️⃣ Dependency • 🔌 Pluggable • 😈 TLS interception • 🔒 DNS-over-HTTPS • 🔥 Poor Man's VPN • ⏪ Reverse & ⏩ Forward • 👮🏿 "Proxy Server" framework • 🌐 "Web Server" framework • ➵ ➶ ➷ ➠ "PubSub" framework • 👷 "Work" acceptor & executor framework
https://abhinavsingh.com/proxy-py-a-lightweight-single-file-http-proxy-server-in-python/
BSD 3-Clause "New" or "Revised" License
2.92k stars 569 forks source link

High CPU usage in idle state on Intel Mac when using Python3.8 #1298

Open yanxurui opened 1 year ago

yanxurui commented 1 year ago

Check FAQs Checked.

Describe the bug I started the proxy from command line in my mac and noticed the CPU usage of the acceptor is very high even though there is zero load. Seems there is a while loop running inside the process?

To Reproduce Steps to reproduce the behavior:

  1. clone the repo
  2. install depedencies
  3. checkout to v2.4.3
  4. python -m proxy --num-acceptors 1 --hostname 0.0.0.0 --log-level d
develop ✔ $ python -m proxy --num-acceptors 1 --hostname 0.0.0.0 --log-level d
2022-11-27 14:17:20,414 - pid:28662 [D] utils.set_open_file_limit:320 - Open file soft limit set to 1024
2022-11-27 14:17:20,415 - pid:28662 [I] plugins.load:85 - Loaded plugin proxy.http.proxy.HttpProxyPlugin
2022-11-27 14:17:20,416 - pid:28662 [I] tcp.listen:80 - Listening on 0.0.0.0:8899
2022-11-27 14:17:20,421 - pid:28662 [D] pool._start:148 - Started acceptor#0 process 28680
2022-11-27 14:17:20,423 - pid:28662 [I] pool.setup:105 - Started 1 acceptors in threadless (local) mode
2022-11-27 14:17:20,673 - pid:28680 [D] selector_events.__init__:59 - Using selector: KqueueSelector
2022-11-27 14:17:20,674 - pid:28680 [D] threadless.run:412 - Working on 0 works

Expected behavior I expect the CPU usage of the proxy process to be very low when there is no load at all. However, the process is utilizing the entire core.

Version information

Screenshots If applicable, add screenshots to help explain your problem.

Screen Shot 2022-11-27 at 14 18 30
abhinavsingh commented 1 year ago

Thanks for reporting. This is unusual. I'll look into it today.

yanxurui commented 1 year ago

Thanks for the quick response. Without specifying num-acceptors, 4 acceptors will be launched and each of them are comsuming 70%~100% of a core, making the fan of my Mac work crasily. This can also be reproduced in the develop branch.

abhinavsingh commented 1 year ago

So I am using develop branch and used flags as you passed. I made a few requests through proxy.py and now I am using it for my entire MacOS system.

Below is a screenshot and video from the same duration

Screenshot 2022-11-27 at 5 21 17 PM

https://user-images.githubusercontent.com/126065/204133859-e5f6a131-f0e3-4f0f-b891-40addd6bb708.mov

I see with contact traffic through proxy.py, its consumption doesn't go over 5-7% which is expected.

I'll further try to also reproduce the scenario. If not, will ask you for more debugging information.

Stay with me :)

yanxurui commented 1 year ago

Thanks. I am using an old mac

Screen Shot 2022-11-27 at 20 10 11

It looks good when I use Python 3.10.2

abhinavsingh commented 1 year ago

@yanxurui Awesome, thanks for confirming the same. I do have an older model in office :). I'll give a try on it tomorrow and share my findings.