File tree Expand file tree Collapse file tree 1 file changed +16
-6
lines changed
Expand file tree Collapse file tree 1 file changed +16
-6
lines changed Original file line number Diff line number Diff line change 44import time
55
66
7- def wait_loadavg (target , check_ival = 30 , stable_cnt = 4 ):
7+ def get_dirty_mem ():
8+ with open ("/proc/meminfo" , "r" ) as fp :
9+ lines = fp .read ().split ("\n " )
10+ dirty = list (filter (lambda a : "Dirty" in a , lines ))[0 ]
11+ return int (dirty .split (" " )[- 2 ])
12+
13+
14+ def wait_loadavg (target , dirty_max = 100000 , check_ival = 30 , stable_cnt = 4 ):
815 """
916 Wait for loadavg to drop but be careful at the start, the load
1017 may have not ramped up, yet, so if we ungate early whoever is waiting
1118 will experience the overload.
1219 """
20+
21+ seen_stable = 0
1322 while target is not None :
1423 load , _ , _ = os .getloadavg ()
24+ dirty = get_dirty_mem ()
1525
16- if load <= target :
17- if stable_cnt == 0 :
26+ if load <= target and dirty <= dirty_max :
27+ if seen_stable >= stable_cnt :
1828 break
19- stable_cnt - = 1
29+ seen_stable + = 1
2030 else :
21- stable_cnt = 0
31+ seen_stable = 0
2232
23- print (f"Waiting for loadavg to decrease: { load } > { target } ({ stable_cnt } )" )
33+ print (f"Waiting for loadavg to decrease: CPU: { load } > { target } Dirty Mem: { dirty } > { dirty_max } ({ stable_cnt } )" )
2434 time .sleep (check_ival )
You can’t perform that action at this time.
0 commit comments