|
39 | 39 | from zimfarm_worker.task.zim import get_zim_info |
40 | 40 |
|
41 | 41 | 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) |
43 | 43 |
|
44 | 44 |
|
45 | 45 | PENDING = "pending" |
@@ -123,7 +123,7 @@ def __init__( |
123 | 123 |
|
124 | 124 | self.max_memory_usage: int = 0 # maximum memory used by scraper |
125 | 125 | 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 |
127 | 127 | self.max_cpu_usage: float = 0.0 # maximum cpu percentage used by scraper |
128 | 128 |
|
129 | 129 | # register stop/^C |
@@ -230,11 +230,12 @@ def _compute_scraper_cpu_stats(self, scraper_stats: dict[str, Any]) -> float: |
230 | 230 | cpu_sample = (delta_cpu / float(delta_system)) * float(online_cpus) * 100.0 |
231 | 231 |
|
232 | 232 | # 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 |
235 | 235 | 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 |
238 | 239 | ) |
239 | 240 | return cpu_sample |
240 | 241 |
|
@@ -271,7 +272,7 @@ def submit_scraper_progress(self): |
271 | 272 | }, |
272 | 273 | "cpu": { |
273 | 274 | "max_usage": self.max_cpu_usage, |
274 | | - "ewma": round(self.cpu_ewma, 2), |
| 275 | + "avg_usage": round(self.avg_cpu_usage, 2), |
275 | 276 | }, |
276 | 277 | "disk": { |
277 | 278 | "max_usage": self.max_disk_usage, |
|
0 commit comments