Ticket #2782: dynamic_jobqueue-0.21.patch
File dynamic_jobqueue-0.21.patch, 5.5 KB (added by , 15 years ago) |
---|
-
libs/libmythtv/jobqueue.cpp
167 167 int sleepTime; 168 168 169 169 QMap<QString, int> jobStatus; 170 int maxJobs;171 170 QString message; 172 171 QMap<int, JobQueueEntry> jobs; 173 172 bool atMax = false; … … 180 179 181 180 startedJobAlready = false; 182 181 sleepTime = gContext->GetNumSetting("JobQueueCheckFrequency", 30); 183 maxJobs = gContext->GetNumSetting("JobQueueMaxSimultaneousJobs", 3);184 VERBOSE(VB_JOBQUEUE, LOC +185 QString("Currently set to run up to %1 job(s) max.")186 .arg(maxJobs));187 182 188 183 jobStatus.clear(); 189 184 … … 205 200 jobsRunning++; 206 201 } 207 202 203 int totalTime, idleTime; 208 204 message = QString("Currently Running %1 jobs.") 209 205 .arg(jobsRunning); 210 206 if (!inTimeWindow) … … 214 210 "started."); 215 211 VERBOSE(VB_JOBQUEUE, LOC + message); 216 212 } 217 else if (jobsRunning >= maxJobs) 213 else if (jobsRunning > 0 && getCPUStats(totalTime, idleTime) && 214 (idleTime * 100 / totalTime) < 25) 218 215 { 219 message += " (At Maximum, no new jobs can be started until " 220 "a running job completes)"; 221 222 if (!atMax) 223 VERBOSE(VB_JOBQUEUE, LOC + message); 224 216 // don't permit more than one job if there's no free CPU 217 message += QString(" CPU near full capacity (%1% idle), " 218 "will not start more jobs") 219 .arg(idleTime * 100 / totalTime); 220 VERBOSE(VB_JOBQUEUE, LOC + message); 225 221 atMax = true; 226 222 } 227 223 else … … 232 228 233 229 234 230 for (unsigned int x = 0; 235 (x < jobs.size()) && (jobsRunning < maxJobs); x++)231 x < jobs.size(); x++) 236 232 { 237 233 id = jobs[x].id; 238 234 chanid = jobs[x].chanid; … … 418 414 } 419 415 420 416 // never start or claim more than one job in a single run 421 if (startedJobAlready )417 if (startedJobAlready || atMax) 422 418 continue; 423 419 424 420 if ((inTimeWindow) && … … 457 453 } 458 454 } 459 455 460 if (startedJobAlready) 461 sleep(5); 462 else 463 sleep(sleepTime); 456 sleep(sleepTime); 464 457 } 465 458 } 466 459 -
libs/libmyth/util.cpp
955 955 return approx_size; 956 956 #endif 957 957 } 958 959 bool getCPUStats(int &totalTime, int &idleTime) 960 { 961 #ifdef __linux__ 962 bool found = false; 963 char line[256]; 964 FILE *stat = fopen("/proc/stat", "r"); 965 if (stat) 966 { 967 while ( (found = fgets(line, sizeof line, stat)) && strncmp(line, "cpu ", 4) ) 968 ; 969 970 fclose(stat); 971 } 972 973 if (found) 974 { 975 char what[32]; 976 unsigned long user_time, nice_time, system_time, idle_time, wait_time = 0; 977 sscanf(line, "%s %lu %lu %lu %lu %lu", what, &user_time, &nice_time, 978 &system_time, &idle_time, &wait_time); 979 980 unsigned long total_time = user_time + nice_time + system_time + idle_time + wait_time ; 981 static unsigned long last_total_time = 0, last_idle_time = 0; 982 totalTime = total_time - last_total_time; 983 last_total_time = total_time; 984 idleTime = idle_time - last_idle_time; 985 last_idle_time = idle_time; 986 return true; 987 } 988 else 989 { 990 VERBOSE(VB_IMPORTANT, "cpuCPUAvail(): can't read /proc/stat"); 991 return false; 992 } 993 #else 994 VERBOSE(VB_IMPORTANT, "getCPUAvail(): Unknown platform. " 995 "How do I get CPU stats?"); 996 return false; 997 #endif 998 } -
libs/libmyth/util.h
67 67 MPUBLIC long long getDiskSpace(const QString&,long long&,long long&); 68 68 MPUBLIC bool getUptime(time_t &uptime); 69 69 MPUBLIC bool getMemStats(int &totalMB, int &freeMB, int &totalVM, int &freeVM); 70 MPUBLIC bool getCPUStats(int &totalTime, int &idleTime); 70 71 71 72 MPUBLIC void myth_eject(void); 72 73 -
programs/mythtv-setup/backendsettings.cpp
465 465 return gc; 466 466 }; 467 467 468 static HostSpinBox *JobQueueMaxSimultaneousJobs()469 {470 HostSpinBox *gc = new HostSpinBox("JobQueueMaxSimultaneousJobs", 1, 10, 1);471 gc->setLabel(QObject::tr("Maximum simultaneous jobs on this backend"));472 gc->setHelpText(QObject::tr("The Job Queue will be limited to running "473 "this many simultaneous jobs on this backend."));474 gc->setValue(1);475 return gc;476 };477 478 468 static HostSpinBox *JobQueueCheckFrequency() 479 469 { 480 470 HostSpinBox *gc = new HostSpinBox("JobQueueCheckFrequency", 5, 300, 5); … … 727 717 728 718 VerticalConfigurationGroup* group5 = new VerticalConfigurationGroup(false); 729 719 group5->setLabel(QObject::tr("Job Queue (Backend-Specific)")); 730 group5->addChild(JobQueueMaxSimultaneousJobs());731 720 group5->addChild(JobQueueCheckFrequency()); 732 721 733 722 HorizontalConfigurationGroup* group5a =