automatic rate limiting of runners: mark ill performing runners as slow, but let speed runners marked as slow back into the main thread pool.
svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=772741
This commit is contained in:
parent
9906e6746d
commit
4ebb5fcaeb
@ -43,13 +43,16 @@ class AbstractRunner::Private
|
|||||||
RunnerScript* script;
|
RunnerScript* script;
|
||||||
KPluginInfo runnerDescription;
|
KPluginInfo runnerDescription;
|
||||||
AbstractRunner* runner;
|
AbstractRunner* runner;
|
||||||
|
QTime runtime;
|
||||||
|
int fastRuns;
|
||||||
|
|
||||||
Private(AbstractRunner* r, KService::Ptr service)
|
Private(AbstractRunner* r, KService::Ptr service)
|
||||||
: priority(NormalPriority),
|
: priority(NormalPriority),
|
||||||
speed(NormalSpeed),
|
speed(NormalSpeed),
|
||||||
script(0),
|
script(0),
|
||||||
runnerDescription(service),
|
runnerDescription(service),
|
||||||
runner(r)
|
runner(r),
|
||||||
|
fastRuns(0)
|
||||||
{
|
{
|
||||||
if (runnerDescription.isValid()) {
|
if (runnerDescription.isValid()) {
|
||||||
QString language = runnerDescription.property("X-Plasma-Language").toString();
|
QString language = runnerDescription.property("X-Plasma-Language").toString();
|
||||||
@ -101,13 +104,29 @@ KConfigGroup AbstractRunner::config() const
|
|||||||
|
|
||||||
void AbstractRunner::performMatch( Plasma::SearchContext &globalContext )
|
void AbstractRunner::performMatch( Plasma::SearchContext &globalContext )
|
||||||
{
|
{
|
||||||
|
static const int reasonableRunTime = 1500;
|
||||||
|
static const int fastEnoughTime = 250;
|
||||||
|
|
||||||
|
d->runtime.restart();
|
||||||
Plasma::SearchContext localContext( 0, globalContext );
|
Plasma::SearchContext localContext( 0, globalContext );
|
||||||
//Keep track of global context list sizes so we know which pointers are our responsibility to delete
|
//Keep track of global context list sizes so we know which pointers are our responsibility to delete
|
||||||
int exactEnd = localContext.exactMatches().count();
|
const int exactEnd = localContext.exactMatches().count();
|
||||||
int possibleEnd = localContext.possibleMatches().count();
|
const int possibleEnd = localContext.possibleMatches().count();
|
||||||
int infoEnd = localContext.informationalMatches().count();
|
const int infoEnd = localContext.informationalMatches().count();
|
||||||
|
|
||||||
match( &localContext );
|
match(&localContext);
|
||||||
|
|
||||||
|
// automatically rate limit runners that become slooow
|
||||||
|
const int runtime = d->runtime.elapsed();
|
||||||
|
bool slowed = speed() == SlowSpeed;
|
||||||
|
|
||||||
|
if (!slowed && runtime > reasonableRunTime) {
|
||||||
|
// we punish runners that return too slowly, even if they don't bring
|
||||||
|
// back matches
|
||||||
|
kDebug() << runnerName() << "runner is too slow, putting it on the back burner.";
|
||||||
|
d->fastRuns = 0;
|
||||||
|
setSpeed(SlowSpeed);
|
||||||
|
}
|
||||||
|
|
||||||
QList<SearchMatch *> exact = localContext.exactMatches().mid(exactEnd);
|
QList<SearchMatch *> exact = localContext.exactMatches().mid(exactEnd);
|
||||||
QList<SearchMatch *> possible = localContext.possibleMatches().mid(possibleEnd);
|
QList<SearchMatch *> possible = localContext.possibleMatches().mid(possibleEnd);
|
||||||
@ -118,6 +137,15 @@ void AbstractRunner::performMatch( Plasma::SearchContext &globalContext )
|
|||||||
qDeleteAll(exact);
|
qDeleteAll(exact);
|
||||||
qDeleteAll(possible);
|
qDeleteAll(possible);
|
||||||
qDeleteAll(info);
|
qDeleteAll(info);
|
||||||
|
} else if (slowed && runtime < fastEnoughTime) {
|
||||||
|
++d->fastRuns;
|
||||||
|
|
||||||
|
if (d->fastRuns > 2) {
|
||||||
|
// we reward slowed runners who bring back matches fast enough
|
||||||
|
// 3 times in a row
|
||||||
|
kDebug() << runnerName() << "runner is faster than we thought, kicking it up a notch";
|
||||||
|
setSpeed(NormalSpeed);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user