본문 바로가기
C.W.K.
Stream
Lesson 05 of 07 · published

관측과 시험

~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 으로 수동 시험하기

수동 WebSocket 시험에는 두 명령줄 도구가 뛰어나. Node.js 기반 wscat 은 가장 친절하고, Rust 기반 websocat 은 사용자 지정 헤더, TLS, 하위 프로토콜, 바이너리 프레임까지 지원해 가장 강력해. 둘 다 도구함에 넣어 둬.

k6 로 부하 시험하기

k6 에는 WebSocket 을 정식으로 지원하는 모듈이 있어. JavaScript 로 시험을 작성하고 가상 사용자를 점차 늘려 서버에 동시 연결 수천 개를 밀어 넣을 수 있지. 결과에는 연결 속도, 메시지 처리량, 오류율, 지연 시간 백분위가 포함돼. 운영 변경 전마다 실행해.

운영에서 관측할 다섯 가지 지표

서버별 활성 연결 수, 들어오고 나가는 초당 메시지 수, 연결 지속 시간 분포, 닫기 코드 히스토그램, 심박 왕복 지연의 p95 를 추적해. 1006 이 갑자기 늘면 문제가 있다는 뜻이야. Prometheus 나 사용하는 관측 체계에 연결하고 절대 기준보다 평소와 다른 이상 징후에 경보를 걸어.

Code

websocat 으로 수동 시험하기·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 부하 시험·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

로컬 서버에 동시 WebSocket 연결을 1,000개까지 늘리는 k6 부하 시험을 실행해. 연결 속도, 메시지 처리량, 오류율을 그래프로 그리고 오류가 시작되는 연결 수인 서버 한계점을 찾아. 그때의 fd 수와 메모리 같은 운영체제 수준 신호도 기록해.

Progress

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

댓글 0

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

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