Skip to content

Commit 908e268

Browse files
committed
set ewma factor to 0.01
1 parent 6165814 commit 908e268

File tree

2 files changed

+9
-8
lines changed
  • backend/src/zimfarm_backend/common/schemas
  • worker/src/zimfarm_worker/task

2 files changed

+9
-8
lines changed

backend/src/zimfarm_backend/common/schemas/orms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class TaskResourceUsageSchema(BaseModel):
115115

116116

117117
class TaskCPUUsageSchema(TaskResourceUsageSchema):
118-
ewma: float | None = Field(default=None, alias="avg")
118+
avg_usage: float | None = Field(default=None, alias="avg")
119119

120120

121121
class TaskStatsSchema(BaseModel):

worker/src/zimfarm_worker/task/worker.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
from zimfarm_worker.task.zim import get_zim_info
4040

4141
SLEEP_INTERVAL = 60 # nb of seconds to sleep before watching
42-
CPU_EWMA_ALPHA = 0.25 # EWMA smoothing factor for CPU percentage samples (0..1)
42+
CPU_EWMA_ALPHA = 0.01 # EWMA smoothing factor for CPU percentage samples (0..1)
4343

4444

4545
PENDING = "pending"
@@ -123,7 +123,7 @@ def __init__(
123123

124124
self.max_memory_usage: int = 0 # maximum memory used by scraper
125125
self.max_disk_usage: int = 0 # maximum disk used by scraper
126-
self.cpu_ewma: float = 0.0 # cpu exponential moving weighted average
126+
self.avg_cpu_usage: float = 0.0 # cpu exponential moving weighted average
127127
self.max_cpu_usage: float = 0.0 # maximum cpu percentage used by scraper
128128

129129
# register stop/^C
@@ -230,11 +230,12 @@ def _compute_scraper_cpu_stats(self, scraper_stats: dict[str, Any]) -> float:
230230
cpu_sample = (delta_cpu / float(delta_system)) * float(online_cpus) * 100.0
231231

232232
# apply EWMA smoothing to reduce effect of short spikes
233-
if self.cpu_ewma == 0.0:
234-
self.cpu_ewma = cpu_sample
233+
if self.avg_cpu_usage == 0.0:
234+
self.avg_cpu_usage = cpu_sample
235235
else:
236-
self.cpu_ewma = (
237-
CPU_EWMA_ALPHA * cpu_sample + (1.0 - CPU_EWMA_ALPHA) * self.cpu_ewma
236+
self.avg_cpu_usage = (
237+
CPU_EWMA_ALPHA * cpu_sample
238+
+ (1.0 - CPU_EWMA_ALPHA) * self.avg_cpu_usage
238239
)
239240
return cpu_sample
240241

@@ -271,7 +272,7 @@ def submit_scraper_progress(self):
271272
},
272273
"cpu": {
273274
"max_usage": self.max_cpu_usage,
274-
"ewma": round(self.cpu_ewma, 2),
275+
"avg_usage": round(self.avg_cpu_usage, 2),
275276
},
276277
"disk": {
277278
"max_usage": self.max_disk_usage,

0 commit comments

Comments
 (0)