Files
2nd/10_Wiki/Topics/Domain_Programming/DevOps_and_Security/Efficiency.md
T
Antigravity Agent c24165b8bc refactor(topics): 멀티 에이전트용 지식 재편 — _Common(공통 기본기) + Domain_* 구조
에이전트 8종(대화형/프로그래머 C·S/디자이너/설계자/기획자/QA/PD/PM)에게
[공통 기본 능력 + 롤별 Specialty] 2층으로 지식을 주입하기 위한 재분류.
문서 내용·포맷은 무수정, 폴더 이동만 (6,372개 문서 수 보존 확인).

- Topic_Programming → Domain_Programming (내부 구조 보존)
- Topic_Graphic → Domain_Design
- Topic_Business → Domain_Product
- Topic_General → Domain_General
- _Common 신설: Math(구 Topic_Math_Specialty), Reasoning(구 General/From_Thinking & Reasoning),
  Reasoning_Creativity(구 General/From_창의성), Communication(Poetic_Blog_Writing + From_writing)
- 타 도메인의 From_* 폴더는 유지 (출처 표기일 뿐, 이미 도메인에 맞게 분류된 문서)
- 빈 폴더 정리 (memory/procedures)
- 에이전트→폴더 매핑은 workspace의 .astra/agent-knowledge-map.json (9개 에이전트)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-11 11:05:56 +09:00

4.8 KiB

id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id title category status canonical_id aliases duplicate_of source_trust_level confidence_score verification_status tags raw_sources last_reinforced github_commit tech_stack
wiki-2026-0508-efficiency Efficiency 10_Wiki/Topics verified self
Performance Efficiency
Resource Efficiency
Cost Efficiency
none A 0.88 applied
performance
efficiency
optimization
sre
cost
2026-05-10 pending
language framework
python prometheus

Efficiency

매 한 줄

"매 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

  1. Profile: hotspot 의 identify (flamegraph).
  2. Hypothesize: bottleneck 의 type (CPU? IO? Lock?).
  3. Optimize: targeted change.
  4. Verify: A/B with baseline, metric 의 statistical sig.

매 응용

  1. API: cold-start 의 reduce.
  2. ML inference: quantization, batching, KV cache.
  3. CI: cache hit rate 의 maximize.

💻 패턴

Latency histogram (Prometheus)

from prometheus_client import Histogram
LATENCY = Histogram('http_request_duration_seconds', 'HTTP latency',
                    buckets=[0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5])

@LATENCY.time()
def handle(req): ...

Cost-per-request rollup

-- BigQuery
SELECT
  service,
  SUM(billable_seconds * cpu_cost_per_sec) AS compute_usd,
  COUNT(*) AS requests,
  SUM(billable_seconds * cpu_cost_per_sec) / COUNT(*) AS usd_per_req
FROM service_metrics
WHERE _PARTITIONDATE = CURRENT_DATE() - 1
GROUP BY service
ORDER BY usd_per_req DESC;

CPU flamegraph (py-spy)

# 매 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

import asyncio, httpx

# BAD — sequential
async def fetch_seq(urls):
    async with httpx.AsyncClient() as c:
        return [await c.get(u) for u in urls]

# GOOD — concurrent
async def fetch_par(urls):
    async with httpx.AsyncClient() as c:
        return await asyncio.gather(*[c.get(u) for u in urls])

Carbon-aware scheduling

import httpx
async def carbon_intensity(region: str) -> float:
    r = await httpx.AsyncClient().get(
        f"https://api.electricitymaps.com/v3/carbon-intensity/latest?zone={region}",
        headers={"auth-token": "TOKEN"})
    return r.json()["carbonIntensity"]  # gCO2eq/kWh

# 매 batch job 매 low-carbon window 의 schedule
async def maybe_run(region):
    ci = await carbon_intensity(region)
    if ci < 200: await run_batch()
    else: await asyncio.sleep(900)

LLM inference batching

from vllm import LLM, SamplingParams
llm = LLM(model="meta-llama/Llama-3.3-70B-Instruct",
          tensor_parallel_size=4,
          max_num_seqs=256)  # 매 batch 의 throughput
sp = SamplingParams(max_tokens=256)
outs = llm.generate(prompts, sp)  # 매 single forward pass 로 batch

Cache efficiency dashboard

# Prometheus query — cache hit ratio
sum(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.

🔗 Graph

🤖 LLM 활용

언제: profile output → bottleneck classification, optimization 후보 ranking. 언제 X: 매 micro-benchmark 매 LLM 의 single-shot 평가 X — 매 측정 우선.

안티패턴

  • Premature optimization: profile 없이 optimize.
  • Single-metric obsession: latency 만 보고 cost 폭증.
  • Synthetic benchmark: production traffic shape 무시.
  • No baseline: 매 before 측정 없이 "fast" 주장.

🧪 검증 / 중복

  • Verified (SRE Workbook ch.4, AWS Well-Architected Performance pillar).
  • 신뢰도 A.

🕓 Changelog

날짜 변경
2026-05-08 Phase 1
2026-05-10 Manual cleanup — efficiency 4 dimension + measurement loop