serve tests: a stopped server stops its hardware sampler (21 samplers leaked after test_responses skewed test_parallel's timing)
This commit is contained in:
1 parent
b7dd070d96
commit
bad9a8f22e
3 files changed
+36
-2
No files matched your search
@@ -5024,6 +5024,14 @@ class Server(ThreadingHTTPServer):
|
||||
if not isinstance(sys.exc_info()[1], ConnectionError): # a client that hangs up needs no stack trace
|
||||
super().handle_error(request, client_address)
|
||||
|
||||
def server_close(self):
|
||||
# the hardware sampler serve() started for this server stops with it (test isolation: every Service a test
|
||||
# started used to leave its sampler running, 21 of them after test_responses, which slowed test_parallel's timing)
|
||||
tel = getattr(getattr(self, "svc", None), "telemetry", None)
|
||||
if tel is not None and hasattr(tel, "close"):
|
||||
tel.close()
|
||||
super().server_close()
|
||||
|
||||
|
||||
def warn_tight_ram(arena_mib) -> None:
|
||||
"""The model's experts live in RAM (INFO arena_mib, engine 0.1.10+). With less than ~6 GB left beside them for the
|
||||
@@ -5251,6 +5259,7 @@ def serve(svc: Service, host="127.0.0.1", port=8095) -> ThreadingHTTPServer:
|
||||
svc.host_names = host_names_for(host, svc.allowed_hosts, svc.trusted_origins)
|
||||
svc.start_telemetry()
|
||||
httpd = Server((host, port), make_handler(svc))
|
||||
httpd.svc = svc
|
||||
threading.Thread(target=httpd.serve_forever, daemon=True).start()
|
||||
return httpd
|
||||
|
||||
|
||||
+7
-2
@@ -297,6 +297,7 @@ class Telemetry:
|
||||
"psutil": self.ps is not None,
|
||||
}
|
||||
self._disk_prev = None
|
||||
self._stop = threading.Event()
|
||||
threading.Thread(target=self._loop, daemon=True).start()
|
||||
|
||||
def _disk(self):
|
||||
@@ -350,8 +351,12 @@ class Telemetry:
|
||||
pass
|
||||
return s
|
||||
|
||||
def close(self):
|
||||
"""Ends the sampler thread (a server that stops, a test's service): it used to run for the life of the process."""
|
||||
self._stop.set()
|
||||
|
||||
def _loop(self):
|
||||
while True:
|
||||
while not self._stop.is_set():
|
||||
s = self.sample()
|
||||
with self.lock:
|
||||
self.now = s
|
||||
@@ -359,7 +364,7 @@ class Telemetry:
|
||||
"disk_read_mb", "tok_s", "prefill_tok_s_mean"):
|
||||
v = s.get(k)
|
||||
self.hist[k].append(round(v, 2) if isinstance(v, float) else v)
|
||||
time.sleep(1.0)
|
||||
self._stop.wait(1.0)
|
||||
|
||||
def snapshot(self):
|
||||
with self.lock:
|
||||
|
||||
@@ -271,6 +271,26 @@ class CodexCompaction(unittest.TestCase):
|
||||
self.assertEqual(tools_of(codex_request("compaction", meta=odd)), (None, None)) # not a compaction: as sent
|
||||
|
||||
|
||||
class NoLeakedSampler(unittest.TestCase):
|
||||
"""Test isolation: a stopped server stops its hardware sampler. Every Service these tests started used to leave one
|
||||
running (21 after this file), polling NVML and psutil every second, which skewed serve/test_parallel's timings."""
|
||||
|
||||
def test_server_close_ends_the_sampler(self):
|
||||
import threading
|
||||
import time
|
||||
tok = ByteTokenizer()
|
||||
before = sum(1 for t in threading.enumerate() if t.name.endswith("(_loop)"))
|
||||
httpd = serve(Service(MockEngine(tok, ANSWER, max_context=16384), tok, TEMPLATE), port=0)
|
||||
self.assertEqual(sum(1 for t in threading.enumerate() if t.name.endswith("(_loop)")), before + 1)
|
||||
httpd.shutdown()
|
||||
httpd.server_close()
|
||||
for _ in range(50):
|
||||
if sum(1 for t in threading.enumerate() if t.name.endswith("(_loop)")) == before:
|
||||
break
|
||||
time.sleep(0.1)
|
||||
self.assertEqual(sum(1 for t in threading.enumerate() if t.name.endswith("(_loop)")), before)
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------------------------ over HTTP
|
||||
class Server(unittest.TestCase):
|
||||
script = ANSWER
|
||||
|
||||
Reference in new issue
Block a user