轮询系统负载并仅在有足够的空闲周期时才启动作业的好方法是什么?

时间:2019-06-26 18:51:18

标签: linux perl

我正在使用Perl尝试启动几十个分析工作。我忘记了系统负载将计数可中断的睡眠任务,因此我试图用我的每个分析任务加载一个Perl作业,然后在系统负载过高(> 5)时进入睡眠状态。

一旦我意识到我的睡眠工作得到了适当的服务,但对我的系统平均负载有所贡献,我就尝试使用mpstat释放的空闲百分比。我还不喜欢。

sub VerifyResources {
  my ($MEM,$CPU,$HDF,$HOME,$SLEEP) = @_;
  my $FreeMem=`cat /proc/meminfo |grep MemAvailable|awk '{print \$2}'`;
  $FreeMem=~ s/[\r\n]+//;
  print("Verify Resources performed memory check. ->$FreeMem<-.\n");
  #$CPULoad=`cat /proc/loadavg |awk '{print \$1}'`;
  $CPUIdle=`/usr/bin/mpstat |tail -1|awk '{print \$13}'`;
  $CPUIdle=~ s/[\r\n]+//;
  $CPULoad=(100-$CPUIdle)*8/100; #Multiply idle % by number of cores, divide by 100
  print("Verify Resources performed CPU load check. ==>$CPULoad<==.\n");
  $HDFFree=`df -m /mnt/hdf|tail -1 |awk '{print \$4}'`;
  $HDFFree=~ s/[\r\n]+//;
  print("Verify Resources performed /mnt/hdf space check. [$HDFFree] MB.\n");
  $HOMEFree=`df -m /home/USER |tail -1 |awk '{print \$4}'`;
  $HOMEFree=~ s/[\r\n]+//;
  print("Verify Resources performed /home/tarl space check. [$HOMEFree] MB.\n");
  while($FreeMem < $MEM || $CPULoad > $CPU || $HDFFree < $HDF || $HOMEFree < $HOME) {
    if($FreeMem < $MEM) {
      print("Free memory of -->$FreeMem<-- below $MEM. Sleeping for $SLEEP seconds.\n");
    }
    if($CPULoad > $CPU ) {
      print("CPU Load of $CPULoad is above $CPU. Sleeping for $SLEEP seconds.\n");
    }
    if($HDFFree < $HDF) {
      print("HDF available space of $HDFFree is below $HDF. Sleeping for $SLEEP seconds.\n");
    }
    if($HOMEFree < $HOME) {
      print("/home/USER available space of $HOMEFree is below $HOME. Sleeping for $SLEEP seconds.\n");
    }
    sleep($SLEEP);
    $FreeMem=`cat /proc/meminfo|grep MemAvailable|awk '{print \$2}'`;
    $FreeMem=~ s/[\r\n]+//;
    #$CPULoad=`cat /proc/loadavg |awk '{print \$1}'`;
    #$CPULoad=~ s/[\r\n]+//;
    $CPUIdle=`/usr/bin/mpstat |tail -1|awk '{print \$13}'`;
    $CPUIdle=~ s/[\r\n]+//;
    $CPULoad=(100-$CPUIdle)*8/100; #Multiply idle % by number of cores, divide by 100
    $HDFFree=`df -m /mnt/hdf|tail -1 |awk '{print \$4}'`;
    $HDFFree=~ s/\r\n]+//;
    $HOMEFree=`df -m /home/USER|tail -1 |awk '{print \$4}'`;
    $HOMEFree=~ s/\r\n]+//;
  }
  print("Verify Resources Passed.\n");
}

轮询系统并仅在有足够的备用CPU时才继续进行下一步的好方法是什么?是否有不影响系统负载的等效睡眠?还是一种更好的方式来衡量不计入睡眠的系统负载?

0 个答案:

没有答案