Files
o2o-weather/backend/scripts/load_test.py
T
minaChoi ddf05aeb5c feat: 로딩 스켈레톤·행사 사진·전시·주말 예상 점수·노을 탭 재정리 등 화면 전반 개선
- 화면 전체 스켈레톤, 로딩·완료·실패 사이 레이아웃 고정, 값 없음은 '?'
- 행사 사진·출처 표시, 문화정보 API 전시 연결, 행사 30km 거리 기준
- 각 상세 점수 칸 오늘/내일/토/일, 단기예보 밖 주말은 중기예보 예상 점수
- 6각 차트 축 이름을 좋은 방향으로, 계산 근거 문구 정리
- 아이콘 오용·뜻 모를 표시·빈 데이터·포스트 본문 반복 수정
- 미세먼지 별도 포스트, 노을 명소 전국 155곳 거리 기준, 노을 탭 결론 중심 재구성
- 밤 다크 테마·별똥별, 댓글·좋아요 대기·실패 표시
- 주말 전국 랭킹·당일치기 카드, 계절 이야기 사진 수집
- 문서: 포스트 타입별 내용, 각 데이터 정리, TODO 진행 순서
2026-10-06 16:36:11 +09:00

59 lines
2.5 KiB
Python

"""피드·날씨 API 동시 접속 부하 측정. 예: python scripts/load_test.py --base http://localhost:9810 --regions 1114000000,4113500000 --users 10,50,100"""
import argparse
import asyncio
import statistics
import time
import httpx
PATHS = ["/v1/feed", "/v1/weather/now", "/v1/weather/today", "/v1/index/list", "/v1/sky", "/v1/week"]
async def _user(client: httpx.AsyncClient, regions: list[str], deadline: float, out: list[tuple[str, float, int]]) -> None:
i = 0
while time.perf_counter() < deadline:
path, region = PATHS[i % len(PATHS)], regions[i % len(regions)]
i += 1
start = time.perf_counter()
try:
res = await client.get(path, params={"region": region})
code = res.status_code if res.status_code != 200 or res.json()["result"]["success"] else 299
except (httpx.HTTPError, ValueError):
code = 0
out.append((path, time.perf_counter() - start, code))
def _pct(xs: list[float], p: float) -> float:
return sorted(xs)[min(len(xs) - 1, int(len(xs) * p))] * 1000
async def run(base: str, regions: list[str], users: int, seconds: float) -> None:
out: list[tuple[str, float, int]] = []
limits = httpx.Limits(max_connections=users, max_keepalive_connections=users)
async with httpx.AsyncClient(base_url=base, timeout=120, limits=limits) as client:
deadline = time.perf_counter() + seconds
await asyncio.gather(*[_user(client, regions[u % len(regions):] + regions[:u % len(regions)], deadline, out) for u in range(users)])
lat = [d for _, d, _ in out]
bad = sum(1 for *_, c in out if c != 200)
print(f"users {users:>3} req {len(out):>5} rps {len(out) / seconds:6.1f} p50 {_pct(lat, .5):6.0f}ms p95 {_pct(lat, .95):6.0f}ms "
f"p99 {_pct(lat, .99):6.0f}ms max {max(lat) * 1000:6.0f}ms 실패 {bad} ({bad / len(out):.1%})")
for path in PATHS:
xs = [d for p, d, _ in out if p == path]
if xs:
print(f" {path:<20} p50 {statistics.median(xs) * 1000:6.0f}ms p95 {_pct(xs, .95):6.0f}ms")
def main() -> None:
ap = argparse.ArgumentParser()
ap.add_argument("--base", default="http://localhost:9810")
ap.add_argument("--regions", required=True)
ap.add_argument("--users", default="10,50,100")
ap.add_argument("--seconds", type=float, default=20)
a = ap.parse_args()
for n in (int(x) for x in a.users.split(",")):
asyncio.run(run(a.base, a.regions.split(","), n, a.seconds))
if __name__ == "__main__":
main()