atproto pds pds.zat.dev
zds docs energy.md
3.3 kB · 78 lines
Markdown
at main

energy #

/energy (the energy tab of /stats) shows what this server draws, where it goes, and what a day of it is in everyday terms. It is an estimate built from measured use, not a meter reading.

what zds measures #

  • CPU time per request. Each request reads its thread's CPU clock (CLOCK_THREAD_CPUTIME_ID) when it starts and ends. The difference is added to the request's minute and hour rows in the telemetry tables, beside its count and latency, and so is the size of its response body.
  • CPU time and memory of the process. Every 20 seconds the telemetry flusher reads zds's own /proc/<pid>/stat (user and system time, resident pages) and stores what changed in telemetry_process, by minute (kept two days) and by hour (kept ninety). Process CPU beyond the requests' own is background work: the firehose, flushes and housekeeping.
  • Helpers. Processes named in helpers (default litestream) that zds can see in /proc are counted the same way. In the container image litestream runs beside zds, so its backups are part of the bill.
  • Bytes. Response bodies and firehose frames. Traffic that a proxy or tunnel in front of zds adds is not seen.
  • Storage. The database file and blob bytes from the hourly storage snapshot.

from use to joules #

For each minute or hour:

part joules
requests request CPU seconds × core_w
background (process CPU − request CPU) seconds × core_w
helpers helper CPU seconds × core_w
memory average resident GB × memory_w_per_gb × seconds
storage stored TB × storage_wh_per_tb_hour × seconds
idle share idle_w × seconds

All of these are multiplied by pue. Network energy, sent GB × network_kwh_per_gb, is shown beside the total and not inside it, because energy per byte on the internet is a rough industry average.

Minutes or hours before readings existed (an older release, or the server down) are left out rather than guessed. A day's figure scales the range's energy by the seconds the readings cover.

defaults #

key default source
core_w 3 W per busy core about the span between idle and full load per vCPU in Cloud Carbon Footprint's server coefficients; a desktop or laptop core is nearer 5–15 W
idle_w 0 marginal accounting: the machine runs anyway
memory_w_per_gb 0.392 Cloud Carbon Footprint
storage_wh_per_tb_hour 1.2 (SSD) Cloud Carbon Footprint
network_kwh_per_gb 0.001 Cloud Carbon Footprint
pue 1 no datacenter overhead; cloud hosts are often 1.1–1.5
helpers litestream

price is empty by default. Set it ($0.20, 0.25 €) and the page prices a year at this rate.

setting it #

ZDS_ENERGY="core_w=10; price=$0.20"

An unknown key or a value out of range stops zds at startup with a message naming ZDS_ENERGY. On a machine whose RAPL counters are readable (/sys/class/powercap/intel-rapl:*/energy_uj), an operator can measure core_w by reading package energy while one core is busy and while it is idle.

everyday terms #

The page puts a day of the server beside a 15 Wh phone charge, a 100 W solar panel in full sun and a wall outlet at about 1.8 kW, and gives a year at the same rate.