Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

How I Kept AI Image Generation Costs Near Zero On A 2 GB Single-Core Server

说明与用途

在 2 GB 单核 VPS 上运行的 AI 图像生成管道,采用顺序处理、上传跟踪、正确的元数据头、峰值内存监控、子进程渲染和最终打包,以将 API 成本保持在接近零的水平。

问题

Running an AI image generation pipeline on a 2 GB single‑core VPS caused frequent out‑of‑memory crashes and wasted API credits due to repeated regenerations and metadata rejections.

结果

The pipeline processed 39 finished products, producing ~856 MB of output from ~19,000 lines of code, while keeping API costs near zero by eliminating duplicate uploads and metadata rejections.

工作流

  • 1. Maintain an upload ledger (upload_tracker.py) to skip already submitted assets.
  • 2. Generate platform‑specific CSV headers with make_metadata.py, optionally using titles.json.
  • 3. Process images sequentially on the single core, calling gc.collect() after each asset.
  • 4. Measure peak RSS with resource.getrusage(RUSAGE_SELF).ru_maxrss after each run.
  • 5. Render heavy steps (e.g., image resizing) in a child subprocess to reclaim memory.
  • 6. Render at the required resolution (e.g., 60 dpi for previews, 300 dpi for final).
  • 7. Package finished products with pack_product.py, creating a cover (1280×720) and thumbnail (600×600) using Pillow.
  • 8. Convert Markdown to styled PDF with md2pdf.py using reportlab.
  • 9. Store all research and logs in a permanent research/ folder to avoid re‑doing work.

证据

I killed a batch job at 2 AM because the server had 40 MB of RAM left and I could hear the fan spinning like it was trying to escape.

来源

When people talk about AI image costs they mean API credits. My costs stayed near zero for a different reason: I stopped throwing away work.

来源

All three big channels reject a wrong CSV header instantly.

来源

Four habits, all of them learned by hitting a wall first.

来源

  • 记录日期: 2026-10-15T16:41:34.759Z