Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track and prioritize routing according to application restart generations #2564

Merged
merged 36 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
20df215
add generation field to process
CamJN Sep 9, 2024
744c2b2
use process generation to inform routing
CamJN Sep 9, 2024
b5dd97a
missed changes
CamJN Sep 9, 2024
df6f2ac
address feedback
CamJN Sep 22, 2024
38187b2
add a test to process test suite
CamJN Sep 22, 2024
a376e8e
add another test
CamJN Sep 23, 2024
824166d
test stub for proper testing of routing algo
CamJN Sep 23, 2024
60d254b
impl new algo
CamJN Sep 27, 2024
6b739f3
update changelog
CamJN Sep 30, 2024
fd21774
Fix indentation
FooBarWidget Oct 3, 2024
c0d99a6
Remove the new test in ProcessTest.cpp because it's pointless
FooBarWidget Oct 3, 2024
f8481e1
Fix typo, set test name
FooBarWidget Oct 3, 2024
6ab1b52
Use spawnStartTime instead of spawnerCreationTime
FooBarWidget Oct 3, 2024
fc86370
Merge branch 'stable-6.0' into feature/app_generations
FooBarWidget Oct 4, 2024
ee8e35c
Merge branch 'stable-6.0' into feature/app_generations
FooBarWidget Oct 12, 2024
cec7638
remove unused headers
CamJN Oct 14, 2024
a45c981
change test condition per hongli’s request
CamJN Oct 14, 2024
8cff85c
don’t select a totally busy process
CamJN Oct 14, 2024
b40c7d2
fallback to best possible process in case all are totally busy
CamJN Oct 14, 2024
506dccd
Merge remote-tracking branch 'origin/stable-6.0' into feature/app_gen…
CamJN Oct 16, 2024
04fb08b
Merge remote-tracking branch 'origin/stable-6.0' into feature/app_gen…
CamJN Oct 17, 2024
dec5f73
fix pool test for process generation incrementing
CamJN Oct 17, 2024
6de82a7
try to make test 8 match new expectations of process selection
CamJN Oct 18, 2024
3b0605a
test doesn’t process requests on totallybusy processes obviously
CamJN Oct 21, 2024
815e8e3
Merge remote-tracking branch 'origin/stable-6.0' into feature/app_gen…
CamJN Oct 21, 2024
c76fb2d
Tests: fix detecting Python on systems with only "python3" command
FooBarWidget Oct 27, 2024
7bceab1
Fix indenting and coding style
FooBarWidget Oct 29, 2024
50bfe8d
Merge branch 'stable-6.0' into feature/app_generations
FooBarWidget Oct 29, 2024
03da686
Fix indenting
FooBarWidget Oct 29, 2024
c2b48f8
Fix up test 8, improve code docs
FooBarWidget Oct 27, 2024
d613e48
Improve tests
FooBarWidget Nov 1, 2024
8a5ebc3
address comments about only finding routeable processes
CamJN Nov 11, 2024
170c628
fixes
FooBarWidget Nov 10, 2024
aee6fbf
Merge branch 'stable-6.0' into feature/app_generations
FooBarWidget Nov 13, 2024
f06c4f7
fixup changelog
CamJN Nov 18, 2024
7a59e7b
Update changelog
FooBarWidget Nov 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/agent/Core/ApplicationPool/Group/InternalUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ Group::createNullProcessObject() {
LockGuard l(context->memoryManagementSyncher);
Process *process = context->processObjectPool.malloc();
Guard guard(context, process);
process = new (process) Process(&info, args);
process = new (process) Process(&info, info.group->restartsInitiated, args);
process->shutdownNotRequired();
guard.clear();
return ProcessPtr(process, false);
Expand Down Expand Up @@ -215,7 +215,7 @@ Group::createProcessObject(const SpawningKit::Spawner &spawner,
LockGuard l(context->memoryManagementSyncher);
Process *process = context->processObjectPool.malloc();
Guard guard(context, process);
process = new (process) Process(&info, spawnResult, args);
process = new (process) Process(&info, info.group->restartsInitiated, spawnResult, args);
guard.clear();
return ProcessPtr(process, false);
}
Expand Down
27 changes: 22 additions & 5 deletions src/agent/Core/ApplicationPool/Group/ProcessListManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,20 @@ Process *
Group::findProcessWithStickySessionIdOrLowestBusyness(unsigned int id) const {
int leastBusyProcessIndex = -1;
int lowestBusyness = 0;
unsigned int i, size = enabledProcessBusynessLevels.size();
unsigned int i, size = enabledProcessBusynessLevels.size(), highest_gen = 0;
const int *enabledProcessBusynessLevels = &this->enabledProcessBusynessLevels[0];

for (i = 0; i < size; i++) {
Process *process = enabledProcesses[i].get();
highest_gen = max(highest_gen, process->generation);
FooBarWidget marked this conversation as resolved.
Show resolved Hide resolved
FooBarWidget marked this conversation as resolved.
Show resolved Hide resolved
if (process->getStickySessionId() == id) {
return process;
} else if (leastBusyProcessIndex == -1 || enabledProcessBusynessLevels[i] < lowestBusyness) {
} else if (leastBusyProcessIndex == -1 ||
FooBarWidget marked this conversation as resolved.
Show resolved Hide resolved
enabledProcessBusynessLevels[i] < lowestBusyness ||
(enabledProcessBusynessLevels[i] == lowestBusyness && process->generation > highest_gen)) {
FooBarWidget marked this conversation as resolved.
Show resolved Hide resolved
if (process->generation > highest_gen) {
highest_gen = process->generation;
}
leastBusyProcessIndex = i;
lowestBusyness = enabledProcessBusynessLevels[i];
}
Expand All @@ -88,13 +94,19 @@ Group::findProcessWithLowestBusyness(const ProcessList &processes) const {
}

int lowestBusyness = -1;
unsigned int highest_gen = 0;
FooBarWidget marked this conversation as resolved.
Show resolved Hide resolved
Process *leastBusyProcess = NULL;
ProcessList::const_iterator it;
ProcessList::const_iterator end = processes.end();
for (it = processes.begin(); it != end; it++) {
Process *process = (*it).get();
int busyness = process->busyness();
if (lowestBusyness == -1 || lowestBusyness > busyness) {
if (lowestBusyness == -1 ||
lowestBusyness > busyness ||
(busyness == lowestBusyness && process->generation > highest_gen)) {
FooBarWidget marked this conversation as resolved.
Show resolved Hide resolved
if (process->generation > highest_gen) {
highest_gen = process->generation;
FooBarWidget marked this conversation as resolved.
Show resolved Hide resolved
}
lowestBusyness = busyness;
leastBusyProcess = process;
}
Expand All @@ -113,11 +125,16 @@ Group::findEnabledProcessWithLowestBusyness() const {

int leastBusyProcessIndex = -1;
int lowestBusyness = 0;
unsigned int i, size = enabledProcessBusynessLevels.size();
unsigned int i, size = enabledProcessBusynessLevels.size(), highest_gen = 0;
const int *enabledProcessBusynessLevels = &this->enabledProcessBusynessLevels[0];

for (i = 0; i < size; i++) {
if (leastBusyProcessIndex == -1 || enabledProcessBusynessLevels[i] < lowestBusyness) {
if (leastBusyProcessIndex == -1 ||
enabledProcessBusynessLevels[i] < lowestBusyness ||
(enabledProcessBusynessLevels[i] == lowestBusyness && enabledProcesses[i]->generation > highest_gen)) {
FooBarWidget marked this conversation as resolved.
Show resolved Hide resolved
if (enabledProcesses[i]->generation > highest_gen) {
highest_gen = enabledProcesses[i]->generation;
FooBarWidget marked this conversation as resolved.
Show resolved Hide resolved
}
leastBusyProcessIndex = i;
lowestBusyness = enabledProcessBusynessLevels[i];
}
Expand Down
11 changes: 8 additions & 3 deletions src/agent/Core/ApplicationPool/Process.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,10 @@ class Process {

/** Last time when a session was opened for this Process. */
unsigned long long lastUsed;
/** Which gereration of app processes this one belongs to,
FooBarWidget marked this conversation as resolved.
Show resolved Hide resolved
inherited from the app group, incremented when a restart
is initiated*/
const unsigned int generation;
/** Number of sessions currently open.
* @invariant session >= 0
*/
Expand Down Expand Up @@ -446,8 +450,7 @@ class Process {
/** Collected by Pool::collectAnalytics(). */
ProcessMetrics metrics;


Process(const BasicGroupInfo *groupInfo, const Json::Value &args)
Process(const BasicGroupInfo *groupInfo, const unsigned int gen, const Json::Value &args)
: info(this, groupInfo, args),
socketsAcceptingHttpRequestsCount(0),
spawnerCreationTime(getJsonUint64Field(args, "spawner_creation_time")),
Expand All @@ -458,6 +461,7 @@ class Process {
refcount(1),
index(-1),
lastUsed(spawnEndTime),
generation(gen),
sessions(0),
processed(0),
lifeStatus(ALIVE),
Expand All @@ -471,7 +475,7 @@ class Process {
indexSocketsAcceptingHttpRequests();
}

Process(const BasicGroupInfo *groupInfo, const SpawningKit::Result &skResult,
Process(const BasicGroupInfo *groupInfo, const unsigned int gen, const SpawningKit::Result &skResult,
const Json::Value &args)
: info(this, groupInfo, skResult),
socketsAcceptingHttpRequestsCount(0),
Expand All @@ -483,6 +487,7 @@ class Process {
refcount(1),
index(-1),
lastUsed(spawnEndTime),
generation(gen),
sessions(0),
processed(0),
lifeStatus(ALIVE),
Expand Down
6 changes: 4 additions & 2 deletions test/cxx/Core/ApplicationPool/ProcessTest.cpp
FooBarWidget marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,10 @@ namespace tut {

args["spawner_creation_time"] = 0;

ProcessPtr process(context.processObjectPool.construct(
&groupInfo, result, args), false);
Process *p = context.processObjectPool.malloc();
FooBarWidget marked this conversation as resolved.
Show resolved Hide resolved
p = new (p) Process(&groupInfo, 0, result, args);
ProcessPtr process(p, false);

process->shutdownNotRequired();
return process;
}
Expand Down
Loading