Limita o uso de CPU de um processo - métodos?

7

Gostaria de limitar o uso da CPU de um processo para, digamos, 10%.

Uma maneira de fazer isso é executar o processo por 6 segundos contínuos a cada minuto e pausar o restante do tempo.

Não pretendo alterar a prioridade do processo com legalidade.

    
por user143118 29.06.2012 / 13:23

2 respostas

6

cpulimit (mais recente link do github aqui ) parece ser a ferramenta para o trabalho - permite controlar o uso do processador de um processo pelo PID, nome do processo ou localização absoluta, e definir o uso do processador em termos de porcentagem do total.

A partir dos documentos na página da fonte de origem -

Exemplos de uso

Limite o processo 'bigloop' pelo nome do executável para 40% da CPU:

cpulimit --exe bigloop --limit 40
cpulimit --exe /usr/local/bin/bigloop --limit 40 

Limite um processo por PID para 55% da CPU:

cpulimit --pid 2960 --limit 55 

Inicie um processo por linha de comando e limite-o para 40% (somente na versão de desenvolvimento!):

cpulimit --limit 40 /etc/rc.d/rc.boinc start 

O Cyberciti.biz tem um howto que também indica que você talvez possa usar

-p : Process PID.
-e : Process name.
-l : percentage of CPU allowed from 0 to 100.
-P: absolute path name of the executable program file.

Em vez de --exe e assim por diante.

E para os multiprocessadores, você deve definir a porcentagem com base no número de núcleos de 100 * - portanto, um sistema dual pode permitir porcentagens de até 150 e um núcleo quádruplo pode permitir até 200

    
por 29.06.2012 / 15:08
3

Como você não especificou o seu sistema operacional, vou colocar aqui uma opção para o Windows e outra para o Linux:

Para Linux:

Use o Stress :

stress is a deliberately simple workload generator for POSIX systems. It imposes a configurable amount of CPU, memory, I/O, and disk stress on the system. It is written in C, and is free software licensed under the GPLv2.

Here is an example invocation: a load average of four is imposed on the system by specifying two CPU-bound processes, one I/O-bound process, and one memory allocator process.

   $ stress --cpu 2 --io 1 --vm 1 --vm-bytes 128M --timeout 10s --verbose
   stress: info: [9372] dispatching hogs: 2 cpu, 1 io, 1 vm, 0 hdd
   stress: dbug: [9372] (243) using backoff sleep of 12000us
   stress: dbug: [9372] (262) setting timeout to 10s
   stress: dbug: [9372] (285) --> hogcpu worker 9373 forked
   stress: dbug: [9372] (305) --> hogio worker 9374 forked
   stress: dbug: [9372] (325) --> hogvm worker 9375 forked
   stress: dbug: [9372] (243) using backoff sleep of 3000us
   stress: dbug: [9372] (262) setting timeout to 10s
   stress: dbug: [9372] (285) --> hogcpu worker 9376 forked
   stress: dbug: [9375] (466) hogvm worker malloced 134217728 bytes
   stress: dbug: [9372] (382) <-- worker 9374 signalled normally
   stress: dbug: [9372] (382) <-- worker 9373 signalled normally
   stress: dbug: [9372] (382) <-- worker 9375 signalled normally
   stress: dbug: [9372] (382) <-- worker 9376 signalled normally
   stress: info: [9372] successful run completed in 10s

No Windows:

Use BES - Codificador de Batalha Shirase 1.4.5 / 1.5.2 :

Free software that controls per-process CPU usage. “Active” software CPU cooler. BES is a small tool that throttles the CPU usage for the process you “target”: for instance, you can limit the CPU usage of a process which would use CPU 100%, down to 50% (or any percentage you’d like). With this, you can use other programs comfortably while doing something CPU-intensive in the background.

By limiting the CPU load, you can also cool down your CPU immediately when it happens to get too hot. It’s an “active” software CPU cooler. Conventional soft-coolers save CPU energy by making CPU sleep when it is idle. They passively wait until CPU gets idle. BES is more aggressive: it cools CPU by making the “heating” process slow down, i.e. periodically forcing CPU to be idle for a short time. (But you should install a better hardware cooler if you often need to use BES for this purpose. Actually, the first thing you should try is to remove dust around your heat sink (See below). Active soft-cooling might be an interesting hack, but it's just a workaround after all. On the other hand, if your application uses CPU 100% meaninglessly, let BES do the job!)

Vocêtambémpodeautomatizá-lousandoalinhadecomandodoWindows:

ThefollowingcommandlinetellsBEStowatchtarget.exe,and—whentarget.exestartsrunning—throttleitsCPUusagesothattarget.exewillbeonlyallowedtouseCPU(100−percentage)%atmost:

"C:\path\to\bes.exe" "D:\path to\target.exe" [percentage] [--minimize]

Optionally, you can use an integer between 1 and 99 as percentage. If percentage is omitted or invalid, the last known valid percentage for target.exe is automatically used (if this is the first time to target target.exe, the default reduction 33% will be applied, unless percentage is specified). Note that, when started from command line, BES will Watch/Limit the target, not just Limit it.

    
por 29.06.2012 / 13:48

Tags