Skip to main content

Latency Simulation

RPG-JS provides built-in latency simulation capabilities to test how your game behaves under various network conditions. This feature allows you to simulate realistic network delays between the server and clients.

Overview

Latency simulation adds configurable delays to outgoing messages from the server to clients, helping you:
  • Test game responsiveness under poor network conditions
  • Validate client-side prediction and reconciliation systems
  • Ensure smooth gameplay even with high latency
  • Debug synchronization issues

Configuration

Environment Variables

You can configure latency simulation using environment variables:

Programmatic Configuration

You can also configure latency simulation programmatically:

Usage Examples

Basic Latency Simulation

Selective Latency

Combined with Packet Loss

You can use latency simulation together with packet loss simulation:

Monitoring

The server logs will show latency simulation activity:

Best Practices

1. Realistic Latency Values

Use realistic latency ranges based on your target network conditions:
  • Local/LAN: 1-10ms
  • Good Internet: 20-100ms
  • Poor Internet: 100-500ms
  • Mobile/3G: 200-1000ms

2. Selective Application

Use filters to apply latency only to specific message types:

3. Testing Different Scenarios

Test various latency scenarios:

4. Client-Side Considerations

When latency simulation is enabled, ensure your client:
  • Implements proper client-side prediction
  • Uses interpolation for smooth movement
  • Handles message ordering correctly
  • Provides visual feedback for network conditions

API Reference

PartyConnection.configureLatency()

Configures latency simulation settings. Parameters:
  • enabled (boolean): Whether to enable latency simulation
  • minMs (number): Minimum latency in milliseconds
  • maxMs (number): Maximum latency in milliseconds
  • filter (string, optional): Only apply latency to messages containing this string

PartyConnection.getLatencyStatus()

Returns current latency simulation configuration. Returns:

Troubleshooting

Messages Not Being Delayed

  1. Check if latency simulation is enabled: PartyConnection.getLatencyStatus()
  2. Verify the filter string matches your message content
  3. Ensure maxMs is greater than 0

Performance Issues

  1. High latency values may affect server performance
  2. Consider using filters to limit which messages are delayed
  3. Monitor server logs for excessive delay messages

Client Disconnections

  1. Very high latency may cause client timeouts
  2. Adjust client-side timeout settings accordingly
  3. Consider implementing heartbeat mechanisms