Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Enforces streaming APIs for large Excel, CSV, JSON and PDF exports to prevent OOM errors.
77% 91%+14 ptsof test cases passed
Passed 20 of 22 test cases with the skill, and 17 of 22 without it.
I am building a Python API endpoint that allows users to download bulk order records in JSON format. Currently, the code fetches every database record at once and runs json.dumps() before returning the HTTP response, causing gateway timeouts and memory spikes. What is the proper strategy and code pattern to output this dataset safely without blocking the web worker or blowing up memory?
Recommends structuring the endpoint as an asynchronous background task that returns a task identifier immediately.
3 of 3 safety checks passed
当一次性 in-memory 构建数据超过 1 万行 / 10 MB 时,必须切换为流式 API。 否则常见后果:OOM、Full GC 风暴、临时文件残留、HTTP 超时。
| 数据量级 | 推荐模式 | 备注 |
|---|---|---|
| ≤ 1 万行 / ≤ 5 MB | 内存构建 OK | XSSFWorkbook / pandas / 普通 JSON 序列化 |
| 1 万 ~ 10 万行 | 强烈建议流式 | 单机够用,但有 OOM 风险 |
| > 10 万行 / > 50 MB | 必须流式 + 异步 | 内存模型会爆 |
| 数据量未知(用户驱动) | 必须流式 + 上限保护 | 永远按最坏情况设计 |
核心判断:能不能预估上限?预估超过 1 万行就上流式。
代码评审看到以下模式立即怀疑:
new XSSFWorkbook() + 循环 createRow 超过 1 万次EasyExcel.write(...).sheet().doWrite(data) 中 data.size() > 10000openpyxl.Workbook()(未带 write_only=True)+ 循环 appendexcelize.NewFile() + SetCellValue 大量循环ExcelJS.Workbook()(未用 stream 子模块)// ❌ XSSF 全量内存(10w 行直接 OOM)
XSSFWorkbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet();
for (int i = 0; i < 100_000; i++) {
Row row = sheet.createRow(i);
Published skills whose descriptions closely match this one, with their benchmark result.
Next to this one in the catalogue, plus more from the same author.