Etherpad Socket.IO Load Test Client
`etherpad-load-test-socket-io` is a client library providing the core logic for programmatically load testing an Etherpad instance via its Socket.IO API. It simulates various user activities, such as "lurkers" (viewers) and "active authors" (editors), to gauge the performance and scalability of an Etherpad server. While this package provides the underlying client functionality, it is typically consumed by higher-level command-line tools, such as `etherpad-load-test`, which offer a more user-friendly interface for executing load tests. The current stable version is 1.0.3, with a Node.js engine requirement of `>=18.0.0`. Its release cadence aligns with the development of the `etherpad-load-test` CLI and the broader Etherpad project, focusing on stability and compatibility with Etherpad Lite. Its key differentiator is its direct, low-level interaction with Etherpad's Socket.IO protocol, enabling deep customization of load testing scenarios.
Common errors
-
Connection refused
cause The Etherpad instance is not running, the URL/port provided to the client is incorrect, or the `"loadTest": true` setting is missing on the server, causing the server to reject the specialized load test connection.fixVerify your Etherpad instance is running and accessible at the specified `etherpadUrl`. Double-check that `"loadTest": true` is set in `settings.json` and the Etherpad server has been restarted. Ensure no firewall is blocking the connection. -
Cannot find module 'etherpad-load-test-socket-io'
cause The package `etherpad-load-test-socket-io` is not installed as a dependency in your project, or there's a mismatch between CommonJS `require` and ES Module `import` syntax in your environment.fixInstall the package using `npm install etherpad-load-test-socket-io` or `yarn add etherpad-load-test-socket-io`. If using TypeScript or a bundler, ensure your configuration (e.g., `tsconfig.json`) supports ES module imports for Node.js modules, or use `const Client = require(...)` for CommonJS. -
Client received unexpected message format or no activity after connection.
cause The Etherpad server might be configured incorrectly, or the specific pad ID is invalid/non-existent, leading to a lack of expected Socket.IO traffic. This can also happen if the client expects a specific protocol version or feature not supported by the Etherpad instance.fixEnsure the `padId` is valid on your Etherpad instance. Review the Etherpad server logs for any errors related to Socket.IO connections or pad access. Verify compatibility between the client library version and your Etherpad Lite server version, especially regarding Socket.IO protocol changes.
Warnings
- breaking To enable load testing functionality and allow clients to connect, the Etherpad Lite server *must* have `"loadTest": true` configured in its `settings.json` file. Failure to do so will prevent clients from establishing a proper connection or interacting with the server.
- gotcha Forgetting to disable `"loadTest": true` in `settings.json` after completing load tests can leave your Etherpad instance vulnerable or impact its normal operation due to potential resource consumption or exposed internal APIs.
- gotcha This package, `etherpad-load-test-socket-io`, is a client *library* for programmatic use. The command-line interface (CLI) described in the provided README (`etherpad-load-test` command) refers to a separate wrapper package, `etherpad-load-test`, which consumes this library. Direct CLI execution is not provided by `etherpad-load-test-socket-io` itself.
Install
-
npm install etherpad-load-test-socket-io -
yarn add etherpad-load-test-socket-io -
pnpm add etherpad-load-test-socket-io
Imports
- Client
const Client = require('etherpad-load-test-socket-io');import Client from 'etherpad-load-test-socket-io';
- Client (CommonJS)
import Client from 'etherpad-load-test-socket-io';
const Client = require('etherpad-load-test-socket-io'); - Client (Type)
import { Client } from 'etherpad-load-test-socket-io';import type Client from 'etherpad-load-test-socket-io';
Quickstart
import Client from 'etherpad-load-test-socket-io';
// Configuration for your Etherpad instance and the load test
const etherpadUrl = 'http://127.0.0.1:9001'; // Ensure your Etherpad instance is running here
const padId = 'myLoadTestPad';
const userId = 'testUser123';
const userName = 'Load Tester';
const readOnly = false; // true for lurkers, false for active authors
async function runSingleClientTest() {
console.log(`Starting client for pad: ${padId}`);
try {
// Instantiate the client with Etherpad details
const client = new Client(etherpadUrl, padId, userId, userName, readOnly);
// Event listeners for client lifecycle and messages
client.on('connect', () => {
console.log(`Client ${userId} connected to ${etherpadUrl}/p/${padId}`);
// Additional actions can be performed here, e.g., typing or sending messages
// For a basic connection test, just connecting and waiting is sufficient.
});
client.on('disconnect', (reason: string) => {
console.log(`Client ${userId} disconnected: ${reason}`);
});
client.on('error', (err: Error) => {
console.error(`Client ${userId} error: ${err.message}`);
});
client.on('message', (msg: any) => {
// console.log(`Client ${userId} received message:`, msg); // Can be very verbose for active pads
});
// Establish the connection to the Etherpad instance
client.connect();
// Keep the client connected for a duration (e.g., 30 seconds)
console.log(`Keeping client ${userId} connected for 30 seconds...`);
await new Promise(resolve => setTimeout(resolve, 30000));
// Disconnect after the test duration
client.disconnect();
console.log(`Client ${userId} test finished.`);
} catch (error) {
console.error('Failed to initialize or run client:', error);
}
}
runSingleClientTest();