Limiting CPU on some processes on web server
Polytropon
freebsd at edvax.de
Wed Mar 11 14:12:01 UTC 2015
On Wed, 11 Mar 2015 14:04:19 +0000, opendaddy at hushmail.com wrote:
> On 11. mars 2015 at 1:41 PM, "Polytropon" <freebsd at edvax.de> wrote:
> >
> >The main differnce in functionality is that ulimit -t defines
> >the limit as time, whereas cpulimit defines it as percentage
> >of CPU resources used.
> >
> >Another difference is that ulimit comes with FreeBSD's default
> >scripting shell, whereas cpulimit is a Linux program that has
> >to be compiled from source, after porting it, of course. :-)
> >
>
> Sounds really tempting especially considering those other cpulimit
> compile errors.
If you manually add "#include <libgen.h>" to src/cpulimit.c
and remove "#ifdef __APPLE__" ... "#endif" from tests/process_iterator_test.c
around the "#include <libgen.h>" line, you can run "gmake"
(in src/ and /test, or at the top level), and it will successfully
build.
Result:
$ ./cpulimit
Error: You must specify a cpu limit percentage
Usage: cpulimit [OPTIONS...] TARGET
OPTIONS
-l, --limit=N percentage of cpu allowed from 0 to 200 (required)
-v, --verbose show control statistics
-z, --lazy exit if there is no target process, or if it dies
-i, --include-children limit also the children processes
-h, --help display this help and exit
TARGET must be exactly one of these:
-p, --pid=N pid of the process (implies -z)
-e, --exe=FILE name of the executable program file or path name
COMMAND [ARGS] run this command and limit it (implies -z)
You can try that "quick & dirty" modification and check if
the cputime program _works_ for you.
> Is there a CPU time limit equivalent to say 20% or have I totally misunderstood?
I'd say it's hard to calculate or estimate absolute CPU time
from relative resource consumption (load). You will probably
have to test this with the real application you want to limit.
--
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
More information about the freebsd-questions
mailing list