forked from mtusi2026/mtusi2026lab7
29 lines
1.0 KiB
Python
29 lines
1.0 KiB
Python
"""Measure the configured per-replica Argon2id slot budget on the app image."""
|
|
from concurrent.futures import ThreadPoolExecutor
|
|
from math import ceil
|
|
import resource
|
|
from time import perf_counter
|
|
|
|
from src.auth import hash_password, iterations, memory, parallelism, verify_password
|
|
from src.login_limits import KDF_SLOTS
|
|
|
|
|
|
def timed_verify(encoded):
|
|
started = perf_counter()
|
|
assert not verify_password(encoded, "another synthetic password")
|
|
return (perf_counter() - started) * 1000
|
|
|
|
|
|
def main():
|
|
encoded = hash_password("synthetic benchmark password")
|
|
timed_verify(encoded)
|
|
with ThreadPoolExecutor(max_workers=KDF_SLOTS) as executor:
|
|
samples = sorted(executor.map(lambda _: timed_verify(encoded), range(24)))
|
|
print(f"Argon2id memory={memory} KiB time={iterations} lanes={parallelism} slots={KDF_SLOTS} "
|
|
f"samples={len(samples)} p50={samples[11]:.1f}ms p95={samples[ceil(.95 * len(samples)) - 1]:.1f}ms "
|
|
f"peak_rss={resource.getrusage(resource.RUSAGE_SELF).ru_maxrss} KiB")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|