"매 useful output / resource consumed — 매 latency, throughput, $cost, watt 매 dimension 별 측정". 매 1972 Knuth "premature optimization" warning 후 신중함이 default, 매 2026 cloud cost + carbon footprint + energy efficiency 가 first-class metric.
매 핵심
매 Efficiency dimensions
Time: latency p50/p95/p99, throughput RPS.
Space: memory RSS, disk IOPS, network bytes.
Money: $/request, $/MAU.
Energy: watt/op, gCO2eq/request.
매 측정 → 개선 cycle
Profile: hotspot 의 identify (flamegraph).
Hypothesize: bottleneck 의 type (CPU? IO? Lock?).
Optimize: targeted change.
Verify: A/B with baseline, metric 의 statistical sig.
# 매 production-safe sampling profiler
py-spy record -o flame.svg -d 60 -p $(pgrep -f gunicorn)
py-spy top -p $(pgrep -f gunicorn)
Memory profiling (memray)
memray run --live ./app.py
memray flamegraph output.bin -o memflame.html
Async IO efficiency
importasyncio,httpx# BAD — sequentialasyncdeffetch_seq(urls):asyncwithhttpx.AsyncClient()asc:return[awaitc.get(u)foruinurls]# GOOD — concurrentasyncdeffetch_par(urls):asyncwithhttpx.AsyncClient()asc:returnawaitasyncio.gather(*[c.get(u)foruinurls])
Carbon-aware scheduling
importhttpxasyncdefcarbon_intensity(region:str)->float:r=awaithttpx.AsyncClient().get(f"https://api.electricitymaps.com/v3/carbon-intensity/latest?zone={region}",headers={"auth-token":"TOKEN"})returnr.json()["carbonIntensity"]# gCO2eq/kWh# 매 batch job 매 low-carbon window 의 scheduleasyncdefmaybe_run(region):ci=awaitcarbon_intensity(region)ifci<200:awaitrun_batch()else:awaitasyncio.sleep(900)
LLM inference batching
fromvllmimportLLM,SamplingParamsllm=LLM(model="meta-llama/Llama-3.3-70B-Instruct",tensor_parallel_size=4,max_num_seqs=256)# 매 batch 의 throughputsp=SamplingParams(max_tokens=256)outs=llm.generate(prompts,sp)# 매 single forward pass 로 batch
Cache efficiency dashboard
# Prometheus query — cache hit ratiosum(rate(cache_hits_total[5m]))/(sum(rate(cache_hits_total[5m]))+sum(rate(cache_misses_total[5m])))
매 결정 기준
상황
Approach
Latency-critical (real-time)
tail-latency optimize, drop p99 outliers
Throughput (batch)
parallelism, vectorize
Cost 제약
spot instance, autoscale, cache
Green ops
carbon-aware scheduling, region selection
기본값: 매 profile-first, 매 measure both before/after, 매 single-dimension fixation 매 X.