Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
FooBarWidget committed Nov 10, 2024
1 parent 8a5ebc3 commit 170c628
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
36 changes: 23 additions & 13 deletions src/agent/Core/ApplicationPool/Group/ProcessListManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,30 @@ Group::findProcessWithStickySessionId(unsigned int id) const {
*
* - If the process with the given sticky session ID exists, then always
* returns that process. Meaning that this process could be `!canBeRoutedTo()`.
* - If there is no process that be routed to, then returns nullptr.
* - If there is no process that can be routed to, then returns nullptr.
*/
Process *
Group::findBestProcessPreferringStickySessionId(unsigned int id) const {
Process *bestProcess = 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 ||
process->generation > bestProcess->generation ||
(process->generation == bestProcess->generation && process->spawnStartTime < bestProcess->spawnStartTime) ||
(process->generation == bestProcess->generation && process->spawnStartTime == bestProcess->spawnStartTime && process->busyness() < bestProcess->busyness())
)) {
} 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;
}
}

return bestProcess;
}

Expand All @@ -97,7 +102,7 @@ Group::findBestProcessPreferringStickySessionId(unsigned int id) const {
* At the moment, "best" is defined as the process with the highest generation,
* lowest start time, and lowest busyness, in that order of priority.
*
* If there is no process that be routed to, then returns nullptr.
* If there is no process that can be routed to, then returns nullptr.
*
* @post result != nullptr || result.canBeRoutedTo()
*/
Expand All @@ -110,17 +115,22 @@ Group::findBestProcess(const ProcessList &processes) const {
Process *bestProcess = nullptr;
ProcessList::const_iterator it;
ProcessList::const_iterator end = processes.end();

for (it = processes.begin(); it != end; it++) {
Process *process = (*it).get();
Process *process = it->get();

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())
)) {
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;
}
}

return bestProcess;
}

Expand Down
3 changes: 1 addition & 2 deletions src/agent/Core/ApplicationPool/Group/SessionManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,7 @@ Group::get(const Options &newOptions, const GetCallback &callback,

if (disablingCount > 0 && !restarting()) {
Process *process = findBestProcess(disablingProcesses);
assert(process != NULL);
if (!process->isTotallyBusy()) {
if (process != nullptr && !process->isTotallyBusy()) {
return newSession(process, newOptions.currentTime);
}
}
Expand Down

0 comments on commit 170c628

Please sign in to comment.