Skip to content

Commit

Permalink
fallback to best possible process in case all are totally busy
Browse files Browse the repository at this point in the history
  • Loading branch information
CamJN committed Oct 14, 2024
1 parent 8cff85c commit b40c7d2
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions src/agent/Core/ApplicationPool/Group/ProcessListManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,21 @@ Group::findProcessWithStickySessionId(unsigned int id) const {
Process *
Group::findBestProcessPreferringStickySessionId(unsigned int id) const {
Process *bestProcess = nullptr;
Process *fallbackProcess = nullptr;
ProcessList::const_iterator it;
ProcessList::const_iterator end = enabledProcesses.end();
for (it = enabledProcesses.begin(); it != end; it++) {
Process *process = (*it).get();
if (process->getStickySessionId() == id) {
return process;
} else if (process->isTotallyBusy() && bestProcess == nullptr) {
if (fallbackProcess == nullptr ||
process->generation > fallbackProcess->generation ||
(process->generation == fallbackProcess->generation && process->spawnStartTime < fallbackProcess->spawnStartTime) ||
(process->generation == fallbackProcess->generation && process->spawnStartTime == fallbackProcess->spawnStartTime && process->busyness() < fallbackProcess->busyness())
) {
fallbackProcess = process;
}
} else if (!process->isTotallyBusy() && (bestProcess == nullptr ||
process->generation > bestProcess->generation ||
(process->generation == bestProcess->generation && process->spawnStartTime < bestProcess->spawnStartTime) ||
Expand All @@ -80,6 +89,9 @@ Group::findBestProcessPreferringStickySessionId(unsigned int id) const {
bestProcess = process;
}
}
if (bestProcess == nullptr) {
return fallbackProcess;
}
return bestProcess;
}

Expand All @@ -90,19 +102,31 @@ Group::findBestProcess(const ProcessList &processes) const {
}

Process *bestProcess = nullptr;
Process *fallbackProcess = nullptr;
ProcessList::const_iterator it;
ProcessList::const_iterator end = processes.end();
for (it = processes.begin(); it != end; it++) {
Process *process = (*it).get();

if (!process->isTotallyBusy() && (bestProcess == nullptr ||
if (process->isTotallyBusy() && bestProcess == nullptr) {
if (fallbackProcess == nullptr ||
process->generation > fallbackProcess->generation ||
(process->generation == fallbackProcess->generation && process->spawnStartTime < fallbackProcess->spawnStartTime) ||
(process->generation == fallbackProcess->generation && process->spawnStartTime == fallbackProcess->spawnStartTime && process->busyness() < fallbackProcess->busyness())
) {
fallbackProcess = process;
}
} else if (!process->isTotallyBusy() && (bestProcess == nullptr ||
process->generation > bestProcess->generation ||
(process->generation == bestProcess->generation && process->spawnStartTime < bestProcess->spawnStartTime) ||
(process->generation == bestProcess->generation && process->spawnStartTime == bestProcess->spawnStartTime && process->busyness() < bestProcess->busyness())
)) {
bestProcess = process;
}
}
if (bestProcess == nullptr) {
return fallbackProcess;
}
return bestProcess;
}

Expand All @@ -119,6 +143,12 @@ Group::findBestEnabledProcess() const {
unsigned long long bestProcessStartTime = 0;
unsigned int bestProcessGen = 0;
int bestProcessBusyness = 0;

Process* fallbackProcess = nullptr;
unsigned long long fallbackProcessStartTime = 0;
unsigned int fallbackProcessGen = 0;
int fallbackProcessBusyness = 0;

unsigned int size = enabledProcessBusynessLevels.size();
const int *enabledProcessBusynessLevels = &this->enabledProcessBusynessLevels[0];

Expand All @@ -127,7 +157,19 @@ Group::findBestEnabledProcess() const {
unsigned int gen = process->generation;
unsigned long long startTime = process->spawnStartTime;
int busyness = enabledProcessBusynessLevels[i];
if (!process->isTotallyBusy() && (bestProcess == nullptr ||
bool totallyBusy = process->isTotallyBusy();
if (totallyBusy && bestProcess == nullptr) {
if (fallbackProcess == nullptr ||
gen > fallbackProcess->generation ||
(gen == fallbackProcessGen && startTime < fallbackProcessStartTime) ||
(gen == fallbackProcessGen && startTime == fallbackProcessStartTime && busyness < fallbackProcessBusyness)
) {
fallbackProcess = process;
fallbackProcessGen = gen;
fallbackProcessBusyness = busyness;
fallbackProcessStartTime = startTime;
}
} else if (!totallyBusy && (bestProcess == nullptr ||
gen > bestProcess->generation ||
(gen == bestProcessGen && startTime < bestProcessStartTime) ||
(gen == bestProcessGen && startTime == bestProcessStartTime && busyness < bestProcessBusyness)
Expand All @@ -138,6 +180,9 @@ Group::findBestEnabledProcess() const {
bestProcessStartTime = startTime;
}
}
if (bestProcess == nullptr) {
return fallbackProcess;
}
return bestProcess;
}

Expand Down

0 comments on commit b40c7d2

Please sign in to comment.