|
1 | | -# Benchmarks for ROS 2.0 clients |
| 1 | +# ROS 2 Client Library Benchmarks |
2 | 2 |
|
3 | | -This folder contains code used to measure the performance between different ROS 2.0 clients. |
| 3 | +Performance benchmarks for comparing ROS 2 client libraries: C++ (rclcpp), Python (rclpy), and JavaScript (rclnodejs). |
4 | 4 |
|
5 | 5 | ## Prerequisites |
6 | 6 |
|
7 | | -1.Install ROS 2.0 from binary |
| 7 | +1. **ROS 2**: Install from [ros.org](https://docs.ros.org/en/jazzy/Installation.html) |
| 8 | +2. **Node.js**: v16+ for rclnodejs (from [nodejs.org](https://nodejs.org/)) |
| 9 | +3. **rclnodejs**: Follow [installation guide](https://github.com/RobotWebTools/rclnodejs#installation) |
| 10 | +4. **Build Dependencies**: For C++ benchmarks: `sudo apt install libssl-dev cmake build-essential` |
8 | 11 |
|
9 | | -You can download the latest binary package of ROS2 from [here](http://ci.ros2.org/view/packaging/) and follow the instructions to setup the environment. |
| 12 | +## Benchmark Structure |
10 | 13 |
|
11 | | -- [Linux](https://github.com/ros2/ros2/wiki/Linux-Install-Binary) |
12 | | -- [macOS](https://github.com/ros2/ros2/wiki/OSX-Install-Binary) |
13 | | -- [Windows](https://github.com/ros2/ros2/wiki/Windows-Install-Binary) |
| 14 | +Each client library has identical benchmark tests: |
14 | 15 |
|
15 | | - 2.Install Node.js |
| 16 | +| Test Type | Description | |
| 17 | +| ----------- | ------------------------------------------- | |
| 18 | +| **topic** | Publisher/subscriber performance | |
| 19 | +| **service** | Client/service request-response performance | |
16 | 20 |
|
17 | | -Download the latest LTS edition from https://nodejs.org/en/ |
| 21 | +## Performance Results |
18 | 22 |
|
19 | | -3.[Get the code](https://github.com/RobotWebTools/rclnodejs#get-code) and [install](https://github.com/RobotWebTools/rclnodejs#build-module) |
| 23 | +### Test Environment |
20 | 24 |
|
21 | | -## Benchmark directories |
| 25 | +**Hardware:** |
22 | 26 |
|
23 | | -The table lists the directories for each kind of the ROS 2.0 clients. |
| 27 | +- **CPU:** 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz (4 cores, 8 threads) |
| 28 | +- **Memory:** 8GB RAM |
| 29 | +- **Architecture:** x86_64 |
24 | 30 |
|
25 | | -| Directory | Purpose | |
26 | | -| :-------: | ------------------------------------------------------ | |
27 | | -| topic | Benchmarks for `publisher` and `subscription` features | |
28 | | -| service | Benchmarks for `client` and `service` features | |
29 | | -| startup | Benchmarks for measuring the startup time consumption | |
| 31 | +**Software:** |
30 | 32 |
|
31 | | -## Run tests |
| 33 | +- **OS:** Ubuntu 24.04.3 LTS (WSL2) |
| 34 | +- **Kernel:** 6.6.87.2-microsoft-standard-WSL2 |
| 35 | +- **ROS 2:** [Jazzy Patch Release 6](https://github.com/ros2/ros2/releases/tag/release-jazzy-20250820) |
| 36 | +- **C++ Compiler:** GCC 13.3.0 (Ubuntu 13.3.0-6ubuntu2~24.04) |
| 37 | +- **Python:** 3.12.3 |
| 38 | +- **Node.js:** v22.18.0 |
| 39 | +- **rclnodejs:** [v1.5.0](https://www.npmjs.com/package/rclnodejs/v/1.5.0) |
32 | 40 |
|
33 | | -1.Benchmark for [rclcpp](https://github.com/ros2/rclcpp) |
| 41 | +### Benchmark Results |
34 | 42 |
|
35 | | -- Compile the source files, `cd benchmark/rclcpp/` and run `colcon build` |
36 | | -- The executable files locate at `build/rclcpp_benchmark/` |
37 | | -- `your_benchmark -h` for help. |
| 43 | +Benchmark parameters: 1000 iterations, 1024KB message size |
38 | 44 |
|
39 | | - 2.Benchmark for [rclpy](https://github.com/ros2/rclpy) |
| 45 | +| Client Library | Topic (ms) | Service (ms) | Performance Ratio | |
| 46 | +| ----------------------- | ---------- | ------------ | ------------------- | |
| 47 | +| **rclcpp (C++)** | 168 | 627 | Baseline (fastest) | |
| 48 | +| **rclpy (Python)** | 1,618 | 15,380 | 9.6x / 24.5x slower | |
| 49 | +| **rclnodejs (Node.js)** | 744 | 927 | 4.4x / 1.5x slower | |
40 | 50 |
|
41 | | -- Enter the Python scripts folder `benchmark/rclpy/` |
42 | | -- `python3 your_benchmark -h` for help. |
| 51 | +_Last updated: August 30, 2025_ |
43 | 52 |
|
44 | | - 3.Benchmark for rclnodejs |
| 53 | +**Notes:** |
45 | 54 |
|
46 | | -- Enter the Node.js scripts folder `benchmark/rclnodejs/` |
47 | | -- `node your_benchmark -h` for help. |
| 55 | +- Topic benchmarks: All libraries completed successfully with 1024KB messages |
| 56 | +- Service benchmarks: All libraries completed successfully with 1024KB responses |
| 57 | +- Performance ratios are relative to C++ baseline |
| 58 | +- C++ shows excellent performance as expected for a compiled language |
| 59 | +- Node.js performs significantly better than Python, likely due to V8 optimizations |
| 60 | +- Python service performance shows significant overhead with large payloads compared to topics |
| 61 | + |
| 62 | +## Running Benchmarks |
| 63 | + |
| 64 | +### C++ (rclcpp) |
| 65 | + |
| 66 | +```bash |
| 67 | +cd benchmark/rclcpp/ |
| 68 | +mkdir -p build && cd build |
| 69 | +source ~/Download/ros2-linux/local_setup.bash # Adjust path |
| 70 | +cmake .. && make |
| 71 | +# Run from build directory: |
| 72 | +./publisher-stress-test -r 1000 -s 1024 |
| 73 | +./client-stress-test -r 1000 |
| 74 | +``` |
| 75 | + |
| 76 | +### Python (rclpy) |
| 77 | + |
| 78 | +```bash |
| 79 | +cd benchmark/rclpy/ |
| 80 | +source ~/Download/ros2-linux/local_setup.bash # Adjust path |
| 81 | +python3 topic/publisher-stress-test.py -r 1000 -s 1024 |
| 82 | +python3 service/client-stress-test.py -r 1000 |
| 83 | +``` |
| 84 | + |
| 85 | +### JavaScript (rclnodejs) |
| 86 | + |
| 87 | +```bash |
| 88 | +cd /path/to/rclnodejs/ # Project root |
| 89 | +source ~/Download/ros2-linux/local_setup.bash # Adjust path |
| 90 | +node benchmark/rclnodejs/topic/publisher-stress-test.js -r 1000 -s 1024 |
| 91 | +node benchmark/rclnodejs/service/client-stress-test.js -r 1000 |
| 92 | +``` |
| 93 | + |
| 94 | +## Test Workflow |
| 95 | + |
| 96 | +For complete tests, run subscriber/service first, then publisher/client: |
| 97 | + |
| 98 | +**Topic Test:** |
| 99 | + |
| 100 | +```bash |
| 101 | +# Terminal 1: Start subscriber (adjust for your language) |
| 102 | +python3 topic/subscription-stress-test.py # Python |
| 103 | +./subscription-stress-test # C++ (from build dir) |
| 104 | +node benchmark/rclnodejs/topic/subscription-stress-test.js # Node.js |
| 105 | + |
| 106 | +# Terminal 2: Run publisher benchmark |
| 107 | +python3 topic/publisher-stress-test.py -r 1000 -s 1024 # Python |
| 108 | +./publisher-stress-test -r 1000 -s 1024 # C++ (from build dir) |
| 109 | +node benchmark/rclnodejs/topic/publisher-stress-test.js -r 1000 -s 1024 # Node.js |
| 110 | +``` |
| 111 | + |
| 112 | +**Service Test:** |
| 113 | + |
| 114 | +```bash |
| 115 | +# Terminal 1: Start service (adjust for your language) |
| 116 | +python3 service/service-stress-test.py -s 1024 # Python |
| 117 | +./service-stress-test -s 1024 # C++ (from build dir) |
| 118 | +node benchmark/rclnodejs/service/service-stress-test.js -s 1024 # Node.js |
| 119 | + |
| 120 | +# Terminal 2: Run client benchmark |
| 121 | +python3 service/client-stress-test.py -r 1000 # Python |
| 122 | +./client-stress-test -r 1000 # C++ (from build dir) |
| 123 | +node benchmark/rclnodejs/service/client-stress-test.js -r 1000 # Node.js |
| 124 | +``` |
| 125 | + |
| 126 | +## Message Types |
| 127 | + |
| 128 | +- **Topics**: `std_msgs/msg/UInt8MultiArray` (configurable size) |
| 129 | +- **Services**: `nav_msgs/srv/GetMap` (map data request/response) |
| 130 | + |
| 131 | +## Notes |
| 132 | + |
| 133 | +- All benchmarks use high-precision timing for accurate measurements |
| 134 | +- C++ provides baseline performance; Python/JavaScript show expected interpreted language overhead |
| 135 | +- All implementations are now working correctly across the three client libraries |
| 136 | +- Results vary by system configuration; use relative comparisons between client libraries |
| 137 | +- Service benchmarks involve request-response cycles with substantial data payloads (OccupancyGrid maps) |
0 commit comments