refactoring
This commit is contained in:
@@ -34,16 +34,27 @@ def main():
|
||||
seed = (ROOT / "tests/fixtures/sample.png").read_bytes()
|
||||
payload = seed + b"\0" * (args.size_mib * 1024 * 1024 - len(seed))
|
||||
baseline, peak, samples, stop = api_memory(), {}, [], threading.Event()
|
||||
check(len(baseline) == 2, "memory experiment requires two running APIs")
|
||||
sampling_errors = []
|
||||
timestamps = []
|
||||
barrier = threading.Barrier(10)
|
||||
|
||||
def sampler():
|
||||
while not stop.is_set():
|
||||
values = api_memory()
|
||||
try:
|
||||
values = api_memory()
|
||||
check(set(values) == set(baseline), "API containers changed during measurement")
|
||||
except Exception as error:
|
||||
sampling_errors.append(type(error).__name__)
|
||||
return
|
||||
timestamps.append(time.monotonic())
|
||||
samples.append(values)
|
||||
for name, value in values.items():
|
||||
peak[name] = max(peak.get(name, 0), value)
|
||||
time.sleep(.1)
|
||||
|
||||
def upload(index):
|
||||
barrier.wait(timeout=15)
|
||||
parsed = urlsplit(client.base)
|
||||
connection = http.client.HTTPConnection(parsed.hostname, parsed.port, timeout=60)
|
||||
|
||||
@@ -73,13 +84,16 @@ def main():
|
||||
thread.join(timeout=5)
|
||||
elapsed = time.monotonic() - started
|
||||
check(len({item["id"] for item in attachments}) == 10, "uploads were not distinct")
|
||||
check(not sampling_errors and len(samples) >= 2 and not thread.is_alive(),
|
||||
"memory sampler failed or did not collect enough samples: " + repr(sampling_errors))
|
||||
report = {
|
||||
"uploads": 10, "file_bytes": len(payload), "concurrency": 10,
|
||||
"api_upload_concurrency_limit": 1, "elapsed_seconds": round(elapsed, 3),
|
||||
"baseline_memory_bytes": baseline, "peak_memory_bytes": peak,
|
||||
"peak_growth_bytes": {name: peak.get(name, 0) - baseline.get(name, 0) for name in baseline},
|
||||
"samples": len(samples),
|
||||
"method": "cgroup memory.current sampled through Docker every 0.1 seconds while clients send chunked 512 KiB blocks every 0.5 seconds; peak is not a continuous profiler.",
|
||||
"sample_intervals_seconds": [round(b-a, 3) for a, b in zip(timestamps, timestamps[1:])],
|
||||
"method": "cgroup memory.current via Docker; 0.1s pause AFTER each poll, actual intervals include Docker latency; ten clients start at a barrier and send chunked 512 KiB blocks every 0.5s. Peak is sampled, not continuous.",
|
||||
}
|
||||
destination = ROOT / args.output
|
||||
destination.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
Reference in New Issue
Block a user