C.W.K.
Stream
Lesson 05 of 07 · published

Monitoring & Testing

~12 min · production, k6, metrics

Level 0Poller
0 XP0/60 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

wscat / websocat 으로 수동 test

두 CLI 도구가 수동 WebSocket test 우세. wscat (Node.js) 가 가장 친절. websocat (Rust) 가 가장 강력 — custom header, TLS, subprotocol, binary framing 지원. 둘 다 도구함에 보유.

k6 로 load test

k6 가 first-class WebSocket 모듈 보유. JS test 짜고, virtual user ramp up, 수천 동시 connection 서버에 push. 결과가 connection rate, message throughput, error rate, latency percentile 커버. Production 변경 전마다 실행.

Production 에 monitor 할 다섯 metric

활성 connection (수, 서버별). 초당 message (in/out). Connection duration 분포. Close-code 히스토그램 (1006 spike = 문제). Heartbeat round-trip latency p95. Prometheus 또는 stack 에 wire. 절대 threshold 가 아니라 anomaly 에 alarm.

Code

websocat 으로 수동 test·shell
# brew install websocat  (or: cargo install websocat)

# Connect, send, receive
websocat ws://localhost:8000/ws
> {"type":"ping"}
{"type":"pong"}

# With headers (auth token)
websocat -H "Authorization: Bearer xxx" wss://api.example.com/ws

# Binary frames
echo -n -e '\x01\x02\x03' | websocat -b ws://localhost:8000/ws
k6 load test·javascript
import ws from 'k6/ws';
import { check } from 'k6';

export const options = {
  stages: [
    { duration: '30s', target: 100 },   // ramp up
    { duration: '1m',  target: 1_000 }, // sustained
    { duration: '30s', target: 0 },     // ramp down
  ],
};

export default function () {
  const url = 'ws://localhost:8000/ws';
  const res = ws.connect(url, {}, (socket) => {
    socket.on('open', () => {
      socket.send(JSON.stringify({ type: 'ping' }));
    });
    socket.on('message', (msg) => {
      check(msg, { 'got pong': (m) => m.includes('pong') });
    });
    socket.setTimeout(() => socket.close(), 10_000);
  });
  check(res, { 'status is 101': (r) => r && r.status === 101 });
}

// Run: k6 run k6-websocket-test.js

External links

Exercise

로컬 서버에 동시 1,000 WebSocket connection ramp 하는 k6 load test 실행. connection rate, message throughput, error rate plot. 서버 break point 찾아 — error 시작하는 connection 수. break point 의 OS-level signal (fd count, memory) 노트.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.