Per-request perf log
Instrumentation is opt-in: it is installed only when PIXIVFE_INSTRUMENT is set to any non-empty value. Without it, RequestPerf is not registered and trace.Phase records nothing, so Server-Timing keeps its previous shape.
With PIXIVFE_INSTRUMENT=1, middleware.RequestPerf writes one structured line per request:
WRN bytes=1653078 cpu_ms=197.6 dur=184.3 goroutines=24 method=GET
phases=["build index data=163ms@+0ms", "fetch landing page=4ms@+0ms",
"GET www.pixiv.net/ajax/top/illust?mode=all=4ms@+0ms",
"parse landing page=95ms@+3ms", "populate thumbnails=51ms@+98ms",
"build personalized sections=6ms@+149ms", "fetch rankings=8ms@+155ms",
"render index template=20ms@+163ms", "write response body=1ms@+183ms"]
request_id=... sched_ms=0.48 status=200 sys=perf url=/?l=1- Routine requests log at debug; requests at or over one second log at warn, so the default info level shows only slow ones.
phasesislabel=duration@offsetfrom the start of the request, oldest first. It contains the labelled Server-Timing metrics of the request.cpu_msis process user Go CPU consumed during the request (not the request's goroutine alone).sched_msis the summed run-queue latency of goroutines that ran in the window. Both are process-wide, so concurrent requests overlap; on a quiet server they are a fair approximation.- On streamed HTML routes such as
GET /, response headers (includingServer-Timing) are committed when the shell flushes before upstream fetches run, so post-flush phases appear in this perf log rather thanServer-Timing. - Enable the debug lines with
PIXIVFE_LOG_LEVEL=debug(both variables are read at startup).
Phase names
Application phases are recorded with trace.Phase:
| Name | Where |
|---|---|
index.data | routes.IndexPage, whole data build |
index.landing | core.GetIndex, landing fetch (cache hit or upstream) |
index.parse | landing JSON unmarshal |
index.thumbnails | thumbnail URL rewriting for every artwork |
index.sections | logged-in personalized sections |
index.rankings | fetchRankings |
ranking.list | ranking list fetch |
ranking.details | ranking detail batch fetch and unmarshal |
index.render | templ render into the response buffer |
response.write | writing the buffered body to the client |
Upstream requests carry a label such as GET www.pixiv.net/ajax/top/illust?mode=all instead of the base64 Server-Timing name. Queries longer than 48 bytes are elided.
Profiling
The existing debug routes are enabled by PIXIVFE_DEV=true:
sh
curl 'http://localhost:8282/debug/pprof/profile?seconds=30' -o cpu.pprof
go tool pprof -http=:8080 cpu.pprof
curl http://localhost:8282/debug/flight -o trace.out # past runtime trace
go tool trace trace.outSee pprof and trace.