WebSockets & Realtime Systems Programming · レッスン

WebSocketsの負荷テストとキャパシティプランニング

数千件の同時WebSocket接続をシミュレーションし、サーバーの限界を測定します。予期せぬ問題なくリアルタイムシステムをスケールできるよう、容量を計画します。

レッスン 4/413 ステップ

「WebSocketsの負荷テストとキャパシティプランニング」はCoddyKit上の無料WebSockets & Realtime Systems Programmingレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはWebSockets & Realtime Systems Programming学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 WebSockets & Realtime Systems Programmingコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Why Load Testing Matters

Benchmarking tells you how a single connection behaves, but load testing tells you what happens when thousands of clients connect at once.

  • Find the breaking point before users do
  • Validate horizontal scaling assumptions
  • Size your infrastructure budget accurately

Connections vs Messages

Two independent dimensions stress a realtime server differently:

  • Connection count drives memory and file-descriptor usage
  • Message throughput drives CPU and network bandwidth

Always test both axes separately and combined.

Choosing a Load Tool

Popular WebSocket load tools include artillery, k6, and websocket-bench. They open many sockets and report latency percentiles.

# Install artillery
npm install -g artillery
artillery --version

A Basic Artillery Scenario

This YAML config ramps up to 500 new connections per second for 60 seconds and sends a join message.

config:
  target: 'ws://localhost:8080'
  phases:
    - duration: 60
      arrivalRate: 500
scenarios:
  - engine: ws
    flow:
      - send: '{"type":"join","room":"load"}'

Scripting Connections in Node

You can also script load tests manually for full control over message timing.

const WebSocket = require('ws');
const TOTAL = 1000;
let open = 0;
for (let i = 0; i < TOTAL; i++) {
  const ws = new WebSocket('ws://localhost:8080');
  ws.on('open', () => { open++; if (open === TOTAL) console.log('all connected'); });
}

Measuring Latency Percentiles

Averages hide pain. Report p50, p95, and p99 latency. A good p50 with a terrible p99 means some users have a bad experience.

Watching Server Resources

During a test, monitor the server side too: CPU, RSS memory, open file descriptors, and event-loop lag.

# Count open sockets for a process
lsof -p $(pgrep -f node) | grep -c TCP

File Descriptor Limits

Each connection consumes a file descriptor. The default OS limit (often 1024) will cap your connections long before CPU does.

# Inspect and raise the soft limit
ulimit -n
ulimit -n 100000

Finding the Breaking Point

Increase load in steps until latency spikes or connections start dropping. That inflection point is your per-node capacity.

  • Record the connection count at first failure
  • Leave a safety margin of 30-50%

From Capacity to Node Count

Capacity planning is arithmetic once you know per-node limits.

const peakUsers = 80000;
const perNode = 10000;
const safety = 0.6; // use 60% of measured max
const nodes = Math.ceil(peakUsers / (perNode * safety));
console.log('nodes needed:', nodes);

Testing in a Realistic Environment

Run load tests against staging hardware that mirrors production, and generate load from multiple machines so the client is never the bottleneck.

Quick Check

Which OS limit most commonly caps WebSocket connection counts first?

Recap

You learned to load test and plan capacity for WebSocket systems:

  • Test connection count and message throughput separately
  • Report p95/p99 latency, not averages
  • Raise file descriptor limits before testing
  • Find the breaking point and size node count with a safety margin
無料で開始

AI チューターと学ぶ WebSockets & Realtime Systems Programming — 無料

ブラウザでリアルコードを書いて実行し、24/7 の AI チューターから瞬時にサポートを受け、ウェブまたはアプリで続きから学習できます。

コース
12
レッスン
47

よくある質問

「WebSocketsの負荷テストとキャパシティプランニング」レッスンは無料ですか?

はい。「WebSocketsの負荷テストとキャパシティプランニング」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、WebSockets & Realtime Systems Programmingコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 WebSockets & Realtime Systems Programmingコースには全4レッスンが含まれています。

「WebSocketsの負荷テストとキャパシティプランニング」で何を学びますか?

数千件の同時WebSocket接続をシミュレーションし、サーバーの限界を測定します。予期せぬ問題なくリアルタイムシステムをスケールできるよう、容量を計画します。 ブラウザで直接実行するハンズオンコードでWebSockets & Realtime Systems Programmingを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

WebSockets & Realtime Systems Programmingを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのWebSockets & Realtime Systems Programmingは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「WebSocketsの負荷テストとキャパシティプランニング」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このWebSockets & Realtime Systems Programmingレッスンでコードを書いて実行できますか?

はい。すべてのWebSockets & Realtime Systems Programmingレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. WebSocketパフォーマンスのベンチマーク
  2. リアルタイム問題のプロファイリングとデバッグ
  3. リアルタイム監視とアラート
  4. WebSocketsの負荷テストとキャパシティプランニング
← WebSockets & Realtime Systems Programmingに戻る