Skip to content

Commit 626ad24

Browse files
committed
Fix HIGH_WATER_MARK to match actual per-worker capacity
Each eventlet worker can handle 8 concurrent connections, not 32. The previous HIGH_WATER_MARK of 26 would never trigger since workers max out at 8 concurrent requests. Changes: - Update HIGH_WATER_MARK default from 26 to 6 (75% of 8 connections) - Fix fallback value in is_worker_overloaded() from 26 to 6 - Update test mocks to use realistic values (3-8 instead of 10-30)
1 parent 63b7ae3 commit 626ad24

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

app/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ class Config:
164164

165165
# Load Shedding Configuration
166166
LOAD_SHEDDING_ENABLED = os.getenv("LOAD_SHEDDING_ENABLED", "false").lower() == "true"
167-
# High water mark: 80% of capacity (26 out of 32 concurrent requests per worker)
168-
HIGH_WATER_MARK = int(os.getenv("HIGH_WATER_MARK", "26"))
167+
# High water mark: 75% of capacity (6 out of 8 concurrent requests per worker)
168+
HIGH_WATER_MARK = int(os.getenv("HIGH_WATER_MARK", "6"))
169169
# Throttle services contributing this % or more of total request volume
170170
THROTTLE_CONTRIBUTION_PCT = int(os.getenv("THROTTLE_CONTRIBUTION_PCT", "20"))
171171
# Only apply contribution-based throttling when enough services are active

app/load_shedding.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def is_worker_overloaded() -> bool:
185185

186186
try:
187187
current_load = concurrent_request_counter.get()
188-
high_water_mark = current_app.config.get("HIGH_WATER_MARK", 26)
188+
high_water_mark = current_app.config.get("HIGH_WATER_MARK", 6)
189189

190190
is_overloaded = current_load > high_water_mark
191191

tests/app/test_load_shedding.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test_returns_false_when_worker_not_overloaded(self, notify_api: "Flask", moc
3131

3232
def test_returns_false_when_below_high_water_mark(self, notify_api: "Flask", mocker: MockerFixture) -> None:
3333
mock_counter = mocker.patch("app.load_shedding.concurrent_request_counter")
34-
mock_counter.get.return_value = 20 # Below HIGH_WATER_MARK of 26
34+
mock_counter.get.return_value = 4 # Below HIGH_WATER_MARK of 6
3535
mock_gauge = mocker.patch("app.load_shedding.WORKER_LOAD_SHEDDING")
3636

3737
assert is_worker_overloaded() is False
@@ -41,7 +41,7 @@ def test_returns_false_when_below_high_water_mark(self, notify_api: "Flask", moc
4141

4242
def test_returns_true_when_above_high_water_mark(self, notify_api: "Flask", mocker: MockerFixture) -> None:
4343
mock_counter = mocker.patch("app.load_shedding.concurrent_request_counter")
44-
mock_counter.get.return_value = 28 # Above HIGH_WATER_MARK of 26
44+
mock_counter.get.return_value = 7 # Above HIGH_WATER_MARK of 6
4545
mock_gauge = mocker.patch("app.load_shedding.WORKER_LOAD_SHEDDING")
4646

4747
assert is_worker_overloaded() is True
@@ -51,7 +51,7 @@ def test_returns_true_when_above_high_water_mark(self, notify_api: "Flask", mock
5151

5252
def test_returns_false_at_boundary(self, notify_api: "Flask", mocker: MockerFixture) -> None:
5353
mock_counter = mocker.patch("app.load_shedding.concurrent_request_counter")
54-
mock_counter.get.return_value = 26 # At HIGH_WATER_MARK
54+
mock_counter.get.return_value = 6 # At HIGH_WATER_MARK
5555
mock_gauge = mocker.patch("app.load_shedding.WORKER_LOAD_SHEDDING")
5656

5757
# At the threshold should NOT trigger (uses > not >=)
@@ -73,32 +73,32 @@ def test_increments_activation_counter_on_state_transition(
7373

7474
ls_module._is_currently_load_shedding = False
7575

76-
# First call: healthy (10 < 26)
77-
mock_counter.get.return_value = 10
76+
# First call: healthy (3 < 6)
77+
mock_counter.get.return_value = 3
7878
is_worker_overloaded()
7979
assert mock_activation_counter.inc.call_count == 0
8080
assert mock_gauge.set.call_args[0][0] == 0 # Gauge set to 0
8181

82-
# Second call: enter overload (28 > 26) - should increment
83-
mock_counter.get.return_value = 28
82+
# Second call: enter overload (7 > 6) - should increment
83+
mock_counter.get.return_value = 7
8484
is_worker_overloaded()
8585
assert mock_activation_counter.inc.call_count == 1
8686
assert mock_gauge.set.call_args[0][0] == 1 # Gauge set to 1
8787

88-
# Third call: stay overloaded (30 > 26) - should NOT increment again
89-
mock_counter.get.return_value = 30
88+
# Third call: stay overloaded (8 > 6) - should NOT increment again
89+
mock_counter.get.return_value = 8
9090
is_worker_overloaded()
9191
assert mock_activation_counter.inc.call_count == 1 # Still 1, not 2
9292
assert mock_gauge.set.call_args[0][0] == 1 # Gauge still 1
9393

94-
# Fourth call: exit overload (10 < 26) - should NOT increment
95-
mock_counter.get.return_value = 10
94+
# Fourth call: exit overload (3 < 6) - should NOT increment
95+
mock_counter.get.return_value = 3
9696
is_worker_overloaded()
9797
assert mock_activation_counter.inc.call_count == 1
9898
assert mock_gauge.set.call_args[0][0] == 0 # Gauge back to 0
9999

100-
# Fifth call: re-enter overload (28 > 26) - should increment again
101-
mock_counter.get.return_value = 28
100+
# Fifth call: re-enter overload (7 > 6) - should increment again
101+
mock_counter.get.return_value = 7
102102
is_worker_overloaded()
103103
assert mock_activation_counter.inc.call_count == 2
104104
assert mock_gauge.set.call_args[0][0] == 1 # Gauge set to 1 again
@@ -115,7 +115,7 @@ def test_logs_activation_and_deactivation(self, notify_api: "Flask", mocker: Moc
115115
ls_module._is_currently_load_shedding = False
116116

117117
# Enter load shedding - should log warning
118-
mock_counter.get.return_value = 28
118+
mock_counter.get.return_value = 7
119119
with notify_api.app_context():
120120
mock_logger = mocker.patch("app.load_shedding.current_app.logger")
121121
is_worker_overloaded()
@@ -125,7 +125,7 @@ def test_logs_activation_and_deactivation(self, notify_api: "Flask", mocker: Moc
125125
assert "ACTIVATED" in mock_logger.warning.call_args[0][0]
126126

127127
# Exit load shedding - should log info
128-
mock_counter.get.return_value = 10
128+
mock_counter.get.return_value = 3
129129
with notify_api.app_context():
130130
mock_logger = mocker.patch("app.load_shedding.current_app.logger")
131131
is_worker_overloaded()

0 commit comments

Comments
 (0)