Files

32 lines
820 B
Python

import os, sys, time
path = sys.argv[1] if len(sys.argv) > 1 else "/tmp/reval-storage-load.bin"
duration = float(sys.argv[2]) if len(sys.argv) > 2 else 8.0
chunk = 64 * 1024
payload = b"z" * chunk
deadline = time.monotonic() + duration
writes = 0
bytes_written = 0
fd = os.open(path, os.O_CREAT | os.O_TRUNC | os.O_WRONLY, 0o600)
try:
while time.monotonic() < deadline:
os.write(fd, payload)
os.fsync(fd)
writes += 1
bytes_written += chunk
if bytes_written >= 64 * 1024 * 1024:
os.ftruncate(fd, 0)
os.lseek(fd, 0, os.SEEK_SET)
bytes_written = 0
finally:
os.close(fd)
try:
os.unlink(path)
except FileNotFoundError:
pass
print("fsync_writes", writes)
print("chunk_bytes", chunk)
print("duration_sec", duration)