sless-primer/POSTGRES/code/chaos-bigpayload/chaos_bigpayload.py
2026-03-22 17:08:18 +04:00

28 lines
935 B
Python

# 2026-03-21 — chaos-bigpayload: генерирует/принимает большой JSON.
# Тестирует: большие ответы (64KB+), память рантайма.
import json, time
def bigpayload(event):
size_kb = min(int(event.get("size_kb", 16)), 256) # cap 256KB
word = str(event.get("word", "x"))[:32]
# Генерируем список строк нужного размера
chunk = word * 32 # ~32+ байт на запись
items = []
total = 0
target = size_kb * 1024
i = 0
while total < target:
entry = f"{chunk}-{i}"
items.append(entry)
total += len(entry) + 3 # 3 байта JSON overhead
i += 1
return {
"items_count": len(items),
"size_kb_approx": round(total / 1024, 1),
"first": items[0] if items else "",
"last": items[-1] if items else "",
"ts": int(time.time()),
}