Document scaling experiment, measured database boundary and verified failure recovery
This commit is contained in:
+40
-15
@@ -1,4 +1,5 @@
|
||||
"""Stop each real API process under traffic; retain confirmed writes and source aliases."""
|
||||
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
@@ -19,10 +20,17 @@ def compose(*args):
|
||||
def aliases():
|
||||
result = {}
|
||||
for cid in compose("ps", "-q", "api").split():
|
||||
alias = subprocess.check_output([
|
||||
"docker", "exec", cid, "python", "-c",
|
||||
"import urllib.request; print(urllib.request.urlopen('http://127.0.0.1:8080/health/live').headers['X-Instance-Id'])",
|
||||
], text=True).strip()
|
||||
alias = subprocess.check_output(
|
||||
[
|
||||
"docker",
|
||||
"exec",
|
||||
cid,
|
||||
"python",
|
||||
"-c",
|
||||
"import urllib.request; print(urllib.request.urlopen('http://127.0.0.1:8080/health/live').headers['X-Instance-Id'])",
|
||||
],
|
||||
text=True,
|
||||
).strip()
|
||||
result[cid] = alias
|
||||
return result
|
||||
|
||||
@@ -43,8 +51,13 @@ def main():
|
||||
while not stop.is_set():
|
||||
try:
|
||||
response = c.message(actor, chat, "failover-proof")
|
||||
successful.append({"at": time.monotonic(), "id": response["json"]["id"],
|
||||
"instance": response["headers"]["X-Instance-Id"]})
|
||||
successful.append(
|
||||
{
|
||||
"at": time.monotonic(),
|
||||
"id": response["json"]["id"],
|
||||
"instance": response["headers"]["X-Instance-Id"],
|
||||
}
|
||||
)
|
||||
except Failure:
|
||||
errors.append(time.monotonic())
|
||||
|
||||
@@ -53,8 +66,12 @@ def main():
|
||||
thread.start()
|
||||
time.sleep(1)
|
||||
stopped_at = time.monotonic()
|
||||
subprocess.run(["scripts/stop-one.sh"], cwd=ROOT,
|
||||
env={**os.environ, "TARGET_INSTANCE_ID": target_alias}, check=True)
|
||||
subprocess.run(
|
||||
["scripts/stop-one.sh"],
|
||||
cwd=ROOT,
|
||||
env={**os.environ, "TARGET_INSTANCE_ID": target_alias},
|
||||
check=True,
|
||||
)
|
||||
time.sleep(4)
|
||||
stop.set()
|
||||
thread.join()
|
||||
@@ -62,14 +79,22 @@ def main():
|
||||
after = [x for x in successful if x["at"] > stopped_at]
|
||||
assert after and all(x["instance"] != target_alias for x in after[-5:])
|
||||
assert min(x["at"] for x in after) - stopped_at <= 10
|
||||
state = json.loads(subprocess.check_output(["docker", "inspect", target_container], text=True))[0]["State"]
|
||||
state = json.loads(
|
||||
subprocess.check_output(["docker", "inspect", target_container], text=True)
|
||||
)[0]["State"]
|
||||
assert not state["Running"]
|
||||
runs.append({"target_container": target_container, "target_alias": target_alias,
|
||||
"successful_writes": len(successful), "failed_attempts": len(errors),
|
||||
"successful_rps": len(successful) / elapsed,
|
||||
"recovery_seconds": min(x["at"] for x in after) - stopped_at,
|
||||
"observed_after": sorted({x["instance"] for x in after[-5:]}),
|
||||
"target_running_after_hook": state["Running"]})
|
||||
runs.append(
|
||||
{
|
||||
"target_container": target_container,
|
||||
"target_alias": target_alias,
|
||||
"successful_writes": len(successful),
|
||||
"failed_attempts": len(errors),
|
||||
"successful_rps": len(successful) / elapsed,
|
||||
"recovery_seconds": min(x["at"] for x in after) - stopped_at,
|
||||
"observed_after": sorted({x["instance"] for x in after[-5:]}),
|
||||
"target_running_after_hook": state["Running"],
|
||||
}
|
||||
)
|
||||
subprocess.run(["docker", "start", target_container], check=True, stdout=subprocess.DEVNULL)
|
||||
subprocess.run([sys.executable, "scripts/wait_replicas.py", "2"], cwd=ROOT, check=True)
|
||||
# Verify every acknowledged write, without assuming failed requests did not commit.
|
||||
|
||||
Reference in New Issue
Block a user