当前位置:网站首页>Reasonably set the number of threads 【 rpm 】

Reasonably set the number of threads 【 rpm 】

2022-06-21 14:32:00 Internet Walker

1. The speed-up relationship between multithreaded programs and single threaded programs

 Amdahl's The laws of

   Set the number of processors to N, The program must be serial ( That is, it cannot be parallelized ) The proportion of partial time-consuming to the total time-consuming of the program is p, Then change such a program into a multithreaded program , The theoretical maximum acceleration we can get Smax by

  Smax = 1 / (p + (1 - p) / N);

   set up T(1) The total time taken to run a single threaded version of the program ,T(N) The total time taken to run the multithreaded version of the program , So the speedup obtained by changing the program to a multithreaded program Smax by

  Smax = T(1) / T(N)

  N->∞ Smax = 1 / p

2. The principle of setting the number of threads

   set up Ncpu Indicates the number of processors in a system , Ncpu The specific value of can be as follows Java Code acquisition :

  int nCPU = Runtime.getRuntime().avaliableProcessors();

2.1 about CPU Intensive thread , You can set the number of threads to Ncpu + 1;

2.2 about I/O Intensive thread , Priority is given to setting the number of threads to 1, Only when one thread is not enough, count the threads to 2 * Ncpu near

2.3 Settings for software with processor utilization thresholds

  Nthreads = Ncpu * Ucpu * (1 + WT / ST)

 Nthreads A reasonable size for the number of threads , Ncpu by CPU number , Ucpu Target CPU The usage rate of (0 < Ucpu <= 1), WT(Wait Time) Waiting for program ( Wait for I/O Operating results ) Length of time on , ST(Service Time) The length of time that the program actually uses the processor to perform calculations . In practice , We can use jvisualvm Calculated from the monitoring data provided WT/ST Value .

原网站

版权声明
本文为[Internet Walker]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202221423319254.html