High Kernel CPU when running multiple python programs

后端 未结 1 748

I developed a python program that does heavy numerical calculations. I run it on a linux machine with 32 Xeon CPUs, 64GB RAM, and Ubuntu 14.04 64-bit. I launch multiple pyth

1条回答
  •  眼角桃花
    2020-12-18 21:43

    If the problem exists in kernel, you should narrow down a problem using a profiler such as OProfile or perf.

    I.e. run perf record -a -g and than read profiling data saved into perf data using perf report. See also: linux perf: how to interpret and find hotspots.


    In your case high CPU usage is caused by competition for /dev/urandom -- it allows only one thread to read from it, but multiple Python processes are doing so.

    Python module random is using it only for initialization. I.e:

    $ strace python -c 'import random;
    while True:
        random.random()'
    open("/dev/urandom", O_RDONLY)     = 4
    read(4, "\16\36\366\36}"..., 2500) = 2500
    close(4)                                   <--- /dev/urandom is closed
    

    You may also explicitly ask for /dev/urandom by using os.urandom or SystemRandom class. So check your code which is dealing with random numbers.

    0 讨论(0)
提交回复
热议问题