This tool allows you to benchmark WebSocket endpoints with multiple test scenarios. You can provide the test scenarios either through a YAML configuration file or via command-line parameters.
- Python 3.6+
websocketslibrarytqdmlibraryPyYAMLlibrary
You can install the required libraries using pip:
pip install websockets tqdm pyyaml
You can run the script either by specifying a configuration file or by providing individual parameters through the command line.
Create a YAML configuration file (e.g., config.yaml) with the following structure:
scenarios:
- url: "wss://url"
duration: 5
users: 2
workers: 1
method: "eth_subscribe"
- url: "http://url2"
duration: 5
users: 2
workers: 1
method: "eth_blockNumber"
# Add more scenarios as neededRun the script with the configuration file:
python main.py -c config.yamlAlternatively, you can provide individual parameters via the command line:
python main.py --url "wss://example.url" -t 5 -u 2 -w 1 -m "eth_subscribe"-c, --config: Path to the YAML configuration file.--url: WebSocket/Http URL to test.-t, --time: Duration of the test in minutes.-u, --users: Number of concurrent users.-w, --workers: Number of workers.-m, --method: Web3 method to test (eth_subscribeoreth_blockNumber).
The script will generate a metrics_statistics.csv file with the results of the test scenarios. The CSV file will contain the following columns:
ws_url: The URL tested.method: The Web3 method used.num_users: Number of concurrent users.num_workers: Number of workers.total_requests: Total number of requests made.max_response_time: Maximum response time.min_response_time: Minimum response time.avg_response_time: Average response time.test_duration_minutes: Duration of the test in minutes.failed_requests_number: Number of failed requests.failed_requests_percentage: Percentage of failed requests.
scenarios:
- url: "wss://url1"
duration: 5
users: 2
workers: 1
method: "eth_subscribe"
- url: "http/s://url2"
duration: 5
users: 2
workers: 1
method: "eth_blockNumber"python main.py -c config.yamlpython main.py --url "wss://url" -t 5 -u 2 -w 1 -m "eth_subscribe"This project is licensed under the MIT License.
Save this content to a `README.md` file in the same directory as your script. This file provides instructions on how to set up and use the WebSocket Benchmarking Tool.