diff --git a/messung/motor/rnr/richter2/lauf.py b/messung/motor/rnr/richter2/lauf.py index b18eaf90..ce5cca89 100644 --- a/messung/motor/rnr/richter2/lauf.py +++ b/messung/motor/rnr/richter2/lauf.py @@ -49,6 +49,15 @@ FEST = os.path.join(HIER, "schnappschuss.json") # 29.11. 17:05: Hybrid live (n EXE_FEST = os.path.join(W, "entscheiden", "motor", "target", "release", "pokerbench-rnr-richter2.exe") +def eco_aus(pid): + """Power Throttling (EcoQoS) fuer einen Prozess aus (ProcessPowerThrottling, wie live_motor/rueck).""" + import ctypes + class Q(ctypes.Structure): _fields_ = [(x, ctypes.c_ulong) for x in "VCM"] + k = ctypes.windll.kernel32; h = k.OpenProcess(0x0200 | 0x1000, False, pid) + if h: + k.SetProcessInformation(ctypes.c_void_p(h), 4, ctypes.byref(Q(1, 1, 0)), 12); k.CloseHandle(h) + + def starte_fest(arm): """Neustart eines Arms genau mit Befehl und Schaltern aus schnappschuss.json (Exe-Kopie, md5 geprueft), nie mit dem Live-Stand von jetzt.""" import subprocess, queue, threading, re @@ -59,6 +68,7 @@ def starte_fest(arm): env.update(A["schalter"]); env["RAYON_NUM_THREADS"] = FAEDEN p = subprocess.Popen([EXE_FEST] + A["befehl"][1:], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, encoding="utf-8", bufsize=1, creationflags=0x08004000, env=env) + eco_aus(p.pid) # 29.11. 17:2x: ohne das bekam der Motor unter EcoQoS ~0,1 Kerne, Anfragen liefen in die 600-s-Frist out = queue.Queue(); threading.Thread(target=lambda: [out.put(z) for z in p.stdout], daemon=True).start() return p, out, [], {"befehl": [EXE_FEST] + A["befehl"][1:], "schalter": A["schalter"], "fest": True} @@ -73,6 +83,13 @@ def lauf(arm): def lauf_mit(arm, m): + try: + _lauf_mit(arm, m) + finally: + m[0].kill() # nie einen Motor als Waise zuruecklassen (17:2x: zwei Waisen zu je 8 GB) + + +def _lauf_mit(arm, m): F, N = anfragen(); print("Haende", N, "Turn/River-Anfragen", len(F), "Arm", arm, flush=True) aus = os.path.join(HIER, "antworten_%s.jsonl" % arm) fertig = set(x["i"] for x in lesen(arm)) diff --git a/messung/motor/rnr/richter2/wache.py b/messung/motor/rnr/richter2/wache.py new file mode 100644 index 00000000..385dc82f --- /dev/null +++ b/messung/motor/rnr/richter2/wache.py @@ -0,0 +1,39 @@ +"""Waechter fuer richter2 (29.11. 17:04 starben alle Arme ohne Fehler): stirbt ein Arm vor dem Ende, startet er ihn aus dem +Schnappschuss neu (lauf.py setzt fort, nur anhaengend). Ende, wenn alle Arme fertig sind. Schreibt wache.log. + python -X utf8 wache.py""" +import json, os, subprocess, sys, time +HIER = os.path.dirname(os.path.abspath(__file__)); sys.path.insert(0, HIER) +import lauf as L +F, _ = L.anfragen() +ziel = {"live": sum(q["street"] == "RIVER" for _, q in F)} +ziel["k2"] = ziel["ohne"] = ziel["live"]; ziel["live_k"] = sum(q["street"] == "RIVER" and i % 10 == 0 for i, (_, q) in enumerate(F)) +FAEDEN = {"live": "8", "k2": "8", "ohne": "8", "live_k": "4"} +log = lambda t: open(os.path.join(HIER, "wache.log"), "a", encoding="utf-8").write(time.strftime("%H:%M:%S ") + t + "\n") +def laeuft(arm): + o = subprocess.run(["powershell", "-c", "Get-CimInstance Win32_Process -Filter \"Name='python.exe'\" | ? { $_.CommandLine -match 'lauf.py lauf %s$|lauf.py lauf %s\"' } | measure | select -expand Count" % (arm, arm)], capture_output=True, text=True) + return o.stdout.strip() not in ("", "0") +def commit_frei_gb(): + o = subprocess.run(["powershell", "-c", "(Get-CimInstance Win32_OperatingSystem).FreeVirtualMemory"], capture_output=True, text=True) + try: return int(o.stdout.strip()) / 2**20 + except ValueError: return 0.0 +COMMIT_MIN = 12.0 # 29.11. 17:07: Commit-Grenze voll -> Prozesse starben ohne Meldung; nur starten, wenn so viel frei ist +HAUPT = ("live", "k2", "ohne") +log("Ziel " + json.dumps(ziel)) +while True: + offen = [a for a in ziel if len({x["i"] for x in L.lesen(a)}) < ziel[a]] + if not offen: log("alle fertig"); break + for a in offen: + if a == "live_k" and all(h in offen for h in HAUPT): continue # Rauschkontrolle erst, wenn ein Hauptarm fertig ist + if not laeuft(a): + c = commit_frei_gb() + if c < COMMIT_MIN: log("warte mit %s: Commit frei %.1f GB" % (a, c)); continue + n = 1 + while os.path.exists(os.path.join(HIER, "lauf_%s_%d.log" % (a, n))): n += 1 + for e in ("log", "err"): + if os.path.exists(os.path.join(HIER, "lauf_%s.%s" % (a, e))): os.replace(os.path.join(HIER, "lauf_%s.%s" % (a, e)), os.path.join(HIER, "lauf_%s_%d.%s" % (a, n, e))) + env = dict(os.environ, RICHTER_FAEDEN=FAEDEN[a]) + p = subprocess.Popen([sys.executable, "-X", "utf8", "lauf.py", "lauf", a], cwd=HIER, env=env, stdout=open(os.path.join(HIER, "lauf_%s.log" % a), "w"), + stderr=open(os.path.join(HIER, "lauf_%s.err" % a), "w"), creationflags=0x00004000 | 0x00000008) + log("Neustart %s pid %d (%d fertig, Commit frei %.1f GB)" % (a, p.pid, len({x["i"] for x in L.lesen(a)}), c)) + time.sleep(90) # nacheinander: der Motor waechst in ~1 min auf ~8 GB + time.sleep(60)