Ticket #2782: dynamic_jobqueue-0.22.patch

File dynamic_jobqueue-0.22.patch, 5.6 KB (added by oa@…, 14 years ago)

the original patch updated for 0.22

  • libs/libmythtv/jobqueue.cpp

     
    163163    int sleepTime;
    164164
    165165    QMap<int, int> jobStatus;
    166     int maxJobs;
    167166    QString message;
    168167    QMap<int, JobQueueEntry> jobs;
    169168    bool atMax = false;
     
    177176
    178177        startedJobAlready = false;
    179178        sleepTime = gContext->GetNumSetting("JobQueueCheckFrequency", 30);
    180         maxJobs = gContext->GetNumSetting("JobQueueMaxSimultaneousJobs", 3);
    181         VERBOSE(VB_JOBQUEUE, LOC +
    182                 QString("Currently set to run up to %1 job(s) max.")
    183                         .arg(maxJobs));
    184179
    185180        jobStatus.clear();
    186181
     
    211206                jobsRunning++;
    212207            }
    213208
     209            int totalTime, idleTime;
    214210            message = QString("Currently Running %1 jobs.")
    215211                              .arg(jobsRunning);
    216212            if (!inTimeWindow)
     
    220216                                   "started.");
    221217                VERBOSE(VB_JOBQUEUE, LOC + message);
    222218            }
    223             else if (jobsRunning >= maxJobs)
     219            else if (jobsRunning > 0 && getCPUStats(totalTime, idleTime) &&
     220                    (idleTime * 100 / totalTime) < 25)
    224221            {
    225                 message += " (At Maximum, no new jobs can be started until "
    226                            "a running job completes)";
    227 
    228                 if (!atMax)
    229                     VERBOSE(VB_JOBQUEUE, LOC + message);
    230 
     222                // don't permit more than one job if there's no free CPU
     223                message += QString(" CPU near full capacity (%1% idle), "
     224                                   "will not start more jobs")
     225                                   .arg(idleTime * 100 / totalTime);
     226                VERBOSE(VB_JOBQUEUE, LOC + message);
    231227                atMax = true;
    232228            }
    233229            else
     
    237233            }
    238234
    239235
    240             for ( int x = 0;
    241                  (x < jobs.size()) && (jobsRunning < maxJobs); x++)
     236            for ( int x = 0; x < jobs.size() ; x++)
    242237            {
    243238                jobID = jobs[x].id;
    244239                cmds = jobs[x].cmds;
     
    412407                }
    413408
    414409                // never start or claim more than one job in a single run
    415                 if (startedJobAlready)
     410                if (startedJobAlready || atMax)
    416411                    continue;
    417412
    418413                if ((inTimeWindow) &&
     
    447442            }
    448443        }
    449444
    450         if (startedJobAlready)
    451             sleep(5);
    452         else
    453             sleep(sleepTime);
     445        sleep(sleepTime);
    454446    }
    455447}
    456448
  • libs/libmyth/util.h

     
    4141MPUBLIC long long getDiskSpace(const QString&,long long&,long long&);
    4242MPUBLIC bool getUptime(time_t &uptime);
    4343MPUBLIC bool getMemStats(int &totalMB, int &freeMB, int &totalVM, int &freeVM);
     44MPUBLIC bool getCPUStats(int &totalTime, int &idleTime);
    4445
    4546MPUBLIC void myth_eject(void);
    4647
  • libs/libmyth/util.cpp

     
    14531453    return true;
    14541454}
    14551455
     1456bool getCPUStats(int &totalTime, int &idleTime)
     1457{
     1458#ifdef __linux__
     1459  bool found = false;
     1460    char line[256];
     1461  FILE *stat = fopen("/proc/stat", "r");
     1462  if (stat)
     1463  {
     1464      while ( (found = fgets(line, sizeof line, stat)) && strncmp(line, "cpu ", 4) )
     1465          ;
     1466
     1467      fclose(stat);
     1468  }
     1469 
     1470    if (found)
     1471  {
     1472      char what[32];
     1473      unsigned long user_time, nice_time, system_time, idle_time, wait_time = 0;
     1474      sscanf(line, "%s %lu %lu %lu %lu %lu", what, &user_time, &nice_time,
     1475          &system_time, &idle_time, &wait_time);
     1476
     1477      unsigned long total_time = user_time + nice_time + system_time + idle_time + wait_time ;
     1478      static unsigned long last_total_time = 0, last_idle_time = 0;
     1479      totalTime = total_time - last_total_time;
     1480      last_total_time = total_time;
     1481      idleTime = idle_time - last_idle_time;
     1482      last_idle_time = idle_time;
     1483      return true;   
     1484  }
     1485  else
     1486  {
     1487      VERBOSE(VB_IMPORTANT, "cpuCPUAvail(): can't read /proc/stat");
     1488      return false;
     1489  }
     1490#else
     1491  VERBOSE(VB_IMPORTANT, "getCPUAvail(): Unknown platform. "
     1492          "How do I get CPU stats?");
     1493  return false;
     1494#endif
     1495}
     1496
     1497
    14561498/* vim: set expandtab tabstop=4 shiftwidth=4: */
  • programs/mythtv-setup/backendsettings.cpp

     
    526526    return gc;
    527527};
    528528
    529 static HostSpinBox *JobQueueMaxSimultaneousJobs()
    530 {
    531     HostSpinBox *gc = new HostSpinBox("JobQueueMaxSimultaneousJobs", 1, 10, 1);
    532     gc->setLabel(QObject::tr("Maximum simultaneous jobs on this backend"));
    533     gc->setHelpText(QObject::tr("The Job Queue will be limited to running "
    534                     "this many simultaneous jobs on this backend."));
    535     gc->setValue(1);
    536     return gc;
    537 };
    538 
    539529static HostSpinBox *JobQueueCheckFrequency()
    540530{
    541531    HostSpinBox *gc = new HostSpinBox("JobQueueCheckFrequency", 5, 300, 5);
     
    839829   
    840830    VerticalConfigurationGroup* group5 = new VerticalConfigurationGroup(false);
    841831    group5->setLabel(QObject::tr("Job Queue (Backend-Specific)"));
    842     group5->addChild(JobQueueMaxSimultaneousJobs());
    843832    group5->addChild(JobQueueCheckFrequency());
    844833
    845834    HorizontalConfigurationGroup* group5a =