-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
两台VPS,客户端连接CPU占用100%,即便未使用的情况下。 #584
Labels
bug
Something isn't working
Comments
我systemctl stop npc先停了客户端 ,到服务端,关闭了加密和压缩,回来继续systemctl start npc开启客户端,目前暂时正常CPU在:4%~40%之间浮动,但是这台配置的CPU也是E3级别的CPU,按道理这么点加密和压缩量,不会导致CPU:100%的。 |
估计是压缩,可以先单独开加密跑跑,另外可以开启下pprof问题出现的时候跟踪下goroutine的状态,哪里在用CPU |
单核100% 我这边也是这个问题 即便是什么都没有使用 |
在 crontab 里面加一个定时任务,检测 npc 的 CPU 使用率,超过 90% 就重启。 $ sudo crontab -e 在最后加一行,每 5 分钟检测一下: */5 * * * * /path/to/npcRestarter.sh npc CPU 使用率检测脚本: #!/bin/bash
cpuUsage=`ps -C npc --no-headers -o %cpu`
echo $cpuUsage
if [ `echo "$cpuUsage > 90" | bc` -eq 1 ]; then
sudo npc restart
fi |
kiririx
pushed a commit
to kiririx/nps
that referenced
this issue
Jul 26, 2022
写了个 python 的版本,稍微精细一些。 #!/usr/bin/env python3
import time
import subprocess
threshold = 25
sampling_interval = 3
sampling_per_second = 10
print(f"[+] checking npc cpu usage...")
process = subprocess.Popen(['ps', '-C', 'npc', '--no-headers', '-o', '%cpu,pid'], stdout=subprocess.PIPE)
output, _ = process.communicate()
for line in output.decode().strip().split('\n'):
cpuUsage, pid = line.strip().split()
print(f"[+] npc with pid {pid} has cpu usage {cpuUsage}%")
print(f"[+] begin sampling npc with pid {pid} for {sampling_interval} seconds...")
sum_usage = 0
total_sample = sampling_interval * sampling_per_second
for _ in range(total_sample):
process = subprocess.Popen(['ps', '-p', pid, '--no-headers', '-o', '%cpu'], stdout=subprocess.PIPE)
output, _ = process.communicate()
sum_usage += float(output.decode().strip())
time.sleep(1 / sampling_per_second)
print(f"[+] npc with pid {pid} has average cpu usage {int(sum_usage / total_sample)}%")
if sum_usage / total_sample > threshold:
print(f"[+] killing npc with pid {pid}...")
subprocess.Popen(['kill', pid])
print("[+] done") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
美国VPS上跑的一个客户端:0.26.8 ,单纯的TCP连接中国大陆VPS服务端:0.26.8,服务是正常的,但是我即便没有使用它,它的CPU还是100%
客户端出现CPU:100%
https://i.niupic.com/images/2020/07/01/8lLu.jpg
The text was updated successfully, but these errors were encountered: