Ticket #2782: dynamic_jobqueue-0.21.patch

File dynamic_jobqueue-0.21.patch, 5.5 KB (added by oa@…, 16 years ago)

dynamic jobqueue size patch, updated for 0.21-fixes

  • libs/libmythtv/jobqueue.cpp

     
    167167    int sleepTime;
    168168
    169169    QMap<QString, int> jobStatus;
    170     int maxJobs;
    171170    QString message;
    172171    QMap<int, JobQueueEntry> jobs;
    173172    bool atMax = false;
     
    180179
    181180        startedJobAlready = false;
    182181        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));
    187182
    188183        jobStatus.clear();
    189184
     
    205200                jobsRunning++;
    206201            }
    207202
     203            int totalTime, idleTime;
    208204            message = QString("Currently Running %1 jobs.")
    209205                              .arg(jobsRunning);
    210206            if (!inTimeWindow)
     
    214210                                   "started.");
    215211                VERBOSE(VB_JOBQUEUE, LOC + message);
    216212            }
    217             else if (jobsRunning >= maxJobs)
     213            else if (jobsRunning > 0 && getCPUStats(totalTime, idleTime) &&
     214                    (idleTime * 100 / totalTime) < 25)
    218215            {
    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);
    225221                atMax = true;
    226222            }
    227223            else
     
    232228
    233229
    234230            for (unsigned int x = 0;
    235                  (x < jobs.size()) && (jobsRunning < maxJobs); x++)
     231                 x < jobs.size(); x++)
    236232            {
    237233                id = jobs[x].id;
    238234                chanid = jobs[x].chanid;
     
    418414                }
    419415
    420416                // never start or claim more than one job in a single run
    421                 if (startedJobAlready)
     417                if (startedJobAlready || atMax)
    422418                    continue;
    423419
    424420                if ((inTimeWindow) &&
     
    457453            }
    458454        }
    459455
    460         if (startedJobAlready)
    461             sleep(5);
    462         else
    463             sleep(sleepTime);
     456        sleep(sleepTime);
    464457    }
    465458}
    466459
  • libs/libmyth/util.cpp

     
    955955    return approx_size;
    956956#endif
    957957}
     958
     959bool 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

     
    6767MPUBLIC long long getDiskSpace(const QString&,long long&,long long&);
    6868MPUBLIC bool getUptime(time_t &uptime);
    6969MPUBLIC bool getMemStats(int &totalMB, int &freeMB, int &totalVM, int &freeVM);
     70MPUBLIC bool getCPUStats(int &totalTime, int &idleTime);
    7071
    7172MPUBLIC void myth_eject(void);
    7273
  • programs/mythtv-setup/backendsettings.cpp

     
    465465    return gc;
    466466};
    467467
    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 
    478468static HostSpinBox *JobQueueCheckFrequency()
    479469{
    480470    HostSpinBox *gc = new HostSpinBox("JobQueueCheckFrequency", 5, 300, 5);
     
    727717
    728718    VerticalConfigurationGroup* group5 = new VerticalConfigurationGroup(false);
    729719    group5->setLabel(QObject::tr("Job Queue (Backend-Specific)"));
    730     group5->addChild(JobQueueMaxSimultaneousJobs());
    731720    group5->addChild(JobQueueCheckFrequency());
    732721
    733722    HorizontalConfigurationGroup* group5a =