opsengine / cpulimit

CPU usage limiter for Linux
Other
1.7k stars 270 forks source link

Why is ALFA 0.08 and MIN_DT 20? #88

Open sam6666666 opened 5 years ago

sam6666666 commented 5 years ago

This is the process I organized. I wonder why ALFA chooses 0.08 and MIN_DT 20? command: cpulimit -i -l=3 While (1) { / / find the process by pid Check to see if the cpulimit process is the same. Do not limit yourself

// limit function Limit_process (pid, limit, include_children); }

Limit_process (pid, limit, include_children) { // all child processes of the pid are added to the hash table with the pid as the key

// read the proc information /proc/stat of the child process pid

/ *

Update_process_group -> cpu_usage for each polling calculation process Tmp_process is the currently reread process information

P is the process information for the last process

Double sample = 1.0 * (tmp_process.cputime-p-> cputime)/dt; Calculate CPU utilization based on two CPU usage times

The first time, p->cpu_usage = sample

After this, p->cpu_usage = (1.0-0.08) p->cpu_usage + 0.08 sample;

CPU usage start limit ->

Double pcpu = 1; // traverses the list of sub-processes and statistics the total CPU utilization of sub-processes (non-statistics less than 0) Pcpu + = p - > cpu_usage;

If the CPU usage of the sub-process is less than 0 pcpu = -1 For the first time: Pcap = 0.05 Workingrate = 0.05 Twork. tv_nsec = 100000 0.05 1000; // CPU usage usage time After: Workinfiring = MIN(workinfiring/pcpu 0.05, 1); Twork.tv_nsec = 100000 1000 workingrate; // statistics the actual time the process has been running Tsleep. tv_nsec = 100000 1000 - twork.tv_nsec; // the time the process should sleep

// traversal sends SIGCONT signal to the process to make it run

// sleep twork time to keep the process running for so long

The gettimeofday (& the startwork, NULL);

Nanosleep (& twork, NULL);

The gettimeofday (& endwork, NULL);

//nanosleep may wake up in the middle and calculate the actual running time

Workingtime = timediff (& endwork, & the startwork);

// too much sleep is bad Long delay = workingtime - twork.tv_nsec/1000;

// traversal process sends SIGSTOP signal

// sleep tsleep time, let the process stop running }

sam6666666 commented 5 years ago

Sorry about the typography。