Ticket #2782: dynamic_jobqueue-0.22.patch
File dynamic_jobqueue-0.22.patch, 5.6 KB (added by , 14 years ago) |
---|
-
libs/libmythtv/jobqueue.cpp
163 163 int sleepTime; 164 164 165 165 QMap<int, int> jobStatus; 166 int maxJobs;167 166 QString message; 168 167 QMap<int, JobQueueEntry> jobs; 169 168 bool atMax = false; … … 177 176 178 177 startedJobAlready = false; 179 178 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));184 179 185 180 jobStatus.clear(); 186 181 … … 211 206 jobsRunning++; 212 207 } 213 208 209 int totalTime, idleTime; 214 210 message = QString("Currently Running %1 jobs.") 215 211 .arg(jobsRunning); 216 212 if (!inTimeWindow) … … 220 216 "started."); 221 217 VERBOSE(VB_JOBQUEUE, LOC + message); 222 218 } 223 else if (jobsRunning >= maxJobs) 219 else if (jobsRunning > 0 && getCPUStats(totalTime, idleTime) && 220 (idleTime * 100 / totalTime) < 25) 224 221 { 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); 231 227 atMax = true; 232 228 } 233 229 else … … 237 233 } 238 234 239 235 240 for ( int x = 0; 241 (x < jobs.size()) && (jobsRunning < maxJobs); x++) 236 for ( int x = 0; x < jobs.size() ; x++) 242 237 { 243 238 jobID = jobs[x].id; 244 239 cmds = jobs[x].cmds; … … 412 407 } 413 408 414 409 // never start or claim more than one job in a single run 415 if (startedJobAlready )410 if (startedJobAlready || atMax) 416 411 continue; 417 412 418 413 if ((inTimeWindow) && … … 447 442 } 448 443 } 449 444 450 if (startedJobAlready) 451 sleep(5); 452 else 453 sleep(sleepTime); 445 sleep(sleepTime); 454 446 } 455 447 } 456 448 -
libs/libmyth/util.h
41 41 MPUBLIC long long getDiskSpace(const QString&,long long&,long long&); 42 42 MPUBLIC bool getUptime(time_t &uptime); 43 43 MPUBLIC bool getMemStats(int &totalMB, int &freeMB, int &totalVM, int &freeVM); 44 MPUBLIC bool getCPUStats(int &totalTime, int &idleTime); 44 45 45 46 MPUBLIC void myth_eject(void); 46 47 -
libs/libmyth/util.cpp
1453 1453 return true; 1454 1454 } 1455 1455 1456 bool 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 1456 1498 /* vim: set expandtab tabstop=4 shiftwidth=4: */ -
programs/mythtv-setup/backendsettings.cpp
526 526 return gc; 527 527 }; 528 528 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 539 529 static HostSpinBox *JobQueueCheckFrequency() 540 530 { 541 531 HostSpinBox *gc = new HostSpinBox("JobQueueCheckFrequency", 5, 300, 5); … … 839 829 840 830 VerticalConfigurationGroup* group5 = new VerticalConfigurationGroup(false); 841 831 group5->setLabel(QObject::tr("Job Queue (Backend-Specific)")); 842 group5->addChild(JobQueueMaxSimultaneousJobs());843 832 group5->addChild(JobQueueCheckFrequency()); 844 833 845 834 HorizontalConfigurationGroup* group5a =