load testing

Guide for load testing

Load Testing Guide

This guide details how to perform mass simulations and stress tests on the loh-game server using the load-test-client.

Prerequisites

  1. Game Server Running: Ensure loh-game is running (default ws://localhost:8080/ws).
  2. Observability Stack: (Optional but recommended) Run Prometheus/Grafana to visualize metrics. See observability.md.

Load Test Client

The load test client is a headless bot harness capable of simulating thousands of players with scripted behaviors.
Location: loh-backend/rust-engine/crates/load-test-client/

Features

  • Headless: No rendering overhead.
  • WebSocket: Connects to game server like a real client.
  • State Machine: Bots have states (Idle, Moving, Combat, Interacting).
  • Roles: Bots are assigned logic roles (Miner, Woodcutter, Pker, PveAttacker).

Running Mass Simulations

Use the spawn_bots.sh script to launch multiple instances of the client. This is necessary because OS thread limits might bottleneck a single process before the server is stressed.
Script Location: loh-backend/rust-engine/spawn_bots.sh

Usage

./spawn_bots.sh <total_bots> <bots_per_instance> <server_url> <scenario>
  • total_bots: Total number of connected clients to simulate.
  • bots_per_instance: How many bots each OS process should handle (Recommend 50-100).
  • server_url: WebSocket URL of the game server.
  • scenario: The behavior pattern to test (see below).

Scenarios

ScenarioDescriptionUse Case
mixedDefault. Randomly assigns Miner, Woodcutter, Pker, and Idle roles.General server stability, DB writes, pathfinding load.
pve_singleAll bots become PveAttacker and target random NPCs individually.Testing NPC AI processing and combat logic throughput.
pve_multiAll bots become PveAttacker (same as single, but conceptually used for swarming).Stressing entity update broadcasting in dense areas.
pvp_singleAll bots become Pker and target random Players.Testing Player-vs-Player damage calc and death flows.
pvp_multiAll bots become Pker. High intensity combat."Clan War" simulation. Extreme stress on spatial partitioning.

Example Commands

1. General Stress Test (1000 players)
./spawn_bots.sh 1000 100 ws://localhost:8080/ws mixed
2. PvP Clan War Simulation (500 players)
./spawn_bots.sh 500 50 ws://localhost:8080/ws pvp_multi

Monitoring Results

Use the SRE Dashboard in Grafana (http://localhost:6006) to monitor:
  • Game Tick Duration: Should remain near target (e.g., 600ms or 400ms). Spikes indicate logic bottlenecks.
  • Connected Players: Verify the server handles the concurrent connections.
  • Messages Processed: Throughput of the networking layer.
  • Database Query Duration: Latency of persistence (saving player state).
See observability.md for setup details.