Adding Priority Scheduling feature to the subprocess

Nick Craig-Wood nick at craig-wood.com
Fri Feb 22 04:30:02 EST 2008


TimeHorse <TimeHorse at gmail.com> wrote:
>  Anyway, on the one hand AmigaOS support where -128 -> p = 0.0 and +127
>  -> p = 1.0 would be a good example of why simply using a 41 point UNIX
>  scale is defecient in representing all possible priorities, but apart
>  from the support AmigaOS argument, you bring up another issue which
>  may be dangerous: are priorities linear in nature?

Interestingly enough this was changed in recent linux kernels.
Process levels in linus kernels are logarithmic now, whereas before
they weren't (but I wouldn't like to say exactly what!).

If I run two CPU intensive jobs to busy out both my CPUs, then using
kernel 2.6.22, run

$ python -c 'from time import time
t = time()
for i in xrange(10000000):
    pass
print time()-t'
1.36508607864

$ nice -n 10 python -c 'from time import time
t = time()
for i in xrange(10000000):
    pass
print time()-t'
4.27783703804

$ nice -n 20 python -c 'from time import time
t = time()
for i in xrange(10000000):
    pass
print time()-t'
36.9293899536

You can see that the levels are not linear! A nice 10 job gets 32% of
the CPU of a nice 0 job, but a nice 20 job gets only 4%.

I think you are on to a loser here trying to normalise it across
OSes unfortunately :-(

-- 
Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick



More information about the Python-list mailing list