Skip to content

Commit

Permalink
node: fine-tune load-based exit
Browse files Browse the repository at this point in the history
  • Loading branch information
ignoramous committed Jun 30, 2023
1 parent f9d4d71 commit dfdcf6b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/server-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,7 @@ function heartbeat() {
function adjustMaxConns(n) {
const maxc = envutil.maxconns();
const minc = envutil.minconns();
const adjsPerSec = 60 / adjPeriodSec;

// caveats:
// linux-magazine.com/content/download/62593/485442/version/1/file/Load_Average.pdf
Expand All @@ -1086,7 +1087,7 @@ function adjustMaxConns(n) {

let adj = stats.bp[3] || 0;
// increase in load
if (avg5 > 100) {
if (avg5 > 90) {
adj += 3;
} else if (avg1 > 100) {
adj += 2;
Expand All @@ -1105,8 +1106,8 @@ function adjustMaxConns(n) {
} else if (avg1 > 70) {
n = Math.max((n * 0.6) | 0, minc);
} else {
// reset; n reverting back to maxconns
adj = 0;
// reclaim adjs 25% at a time as n approaches maxconns
adj = Math.min(0, adj * 0.75) | 0;
}
} else {
// clamp n based on a preset
Expand All @@ -1117,8 +1118,8 @@ function adjustMaxConns(n) {
}

// adjustMaxConns is called every adjPeriodSec
const breakpoint = 15 * (60 / adjPeriodSec); // 15 mins
const stresspoint = 10 * (60 / adjPeriodSec); // 10 mins
const breakpoint = 15 * adjsPerSec; // 15 mins
const stresspoint = 10 * adjsPerSec; // 10 mins
if (adj > breakpoint) {
log.w("load: stopping; n:", n, "adjs:", adj);
stopAfter(0);
Expand Down

0 comments on commit dfdcf6b

Please sign in to comment.