Update perftool.php
This commit is contained in:
parent
5d5ecbe8a9
commit
cc2773c2d2
|
@ -20,13 +20,13 @@ if(!is_fn("get_cpu_idle")) {
|
|||
}
|
||||
|
||||
if(!is_fn("set_min_cpu_idle")) {
|
||||
function set_min_cpu_idle($idle=0.01) {
|
||||
function set_min_cpu_idle($ratio=0.01) {
|
||||
$wait = 0;
|
||||
|
||||
// default (cpu_sleep_time): 3 seconds
|
||||
$cpu_sleep_time = floatval(get_value_in_array("cpu_sleep_time", $config, 3));
|
||||
if($idle > 0 && $idle < 1) {
|
||||
while(get_cpu_idle() < $idle) {
|
||||
$cpu_sleep_time = floatval(get_value_in_array("cpu_sleep_time", $config, 3));
|
||||
if($ratio > 0 && $ratio < 1) {
|
||||
while(get_cpu_idle() < $ratio) {
|
||||
if($wait == 0) {
|
||||
write_common_log("CPU usage exceeded. wait a few seconds...", "helper/preftool");
|
||||
}
|
||||
|
@ -42,3 +42,15 @@ if(!is_fn("set_min_cpu_idle")) {
|
|||
}
|
||||
}
|
||||
|
||||
if(!is_fn("set_cpu_usage_limit")) {
|
||||
function set_cpu_usage_limit($ratio=0.9) {
|
||||
$config = get_config();
|
||||
$num_cores = get_value_in_array("cpu_num_cores", $config, 1);
|
||||
$pid = get_shared_var("mypid");
|
||||
|
||||
if(!empty($pid) && loadHelper("exectool")) {
|
||||
write_common_log(sprintf("CPU usage limit setted. PID=%s, LIMIT=%s", $pid, ($ratio * $num_cores) * 100), "helper/perftool");
|
||||
exec_command(sprintf("cpulimit --pid %s --limit %s", $pid, ($ratio * $num_cores) * 100));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user