-
Notifications
You must be signed in to change notification settings - Fork 77
Re-enable benchmark #1245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Re-enable benchmark #1245
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,137 @@ | ||
# Benchmarks for ROS 2.0 clients | ||
# ROS 2 Client Library Benchmarks | ||
|
||
This folder contains code used to measure the performance between different ROS 2.0 clients. | ||
Performance benchmarks for comparing ROS 2 client libraries: C++ (rclcpp), Python (rclpy), and JavaScript (rclnodejs). | ||
|
||
## Prerequisites | ||
|
||
1.Install ROS 2.0 from binary | ||
1. **ROS 2**: Install from [ros.org](https://docs.ros.org/en/jazzy/Installation.html) | ||
2. **Node.js**: v16+ for rclnodejs (from [nodejs.org](https://nodejs.org/)) | ||
3. **rclnodejs**: Follow [installation guide](https://github.com/RobotWebTools/rclnodejs#installation) | ||
4. **Build Dependencies**: For C++ benchmarks: `sudo apt install libssl-dev cmake build-essential` | ||
|
||
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. | ||
## Benchmark Structure | ||
|
||
- [Linux](https://github.com/ros2/ros2/wiki/Linux-Install-Binary) | ||
- [macOS](https://github.com/ros2/ros2/wiki/OSX-Install-Binary) | ||
- [Windows](https://github.com/ros2/ros2/wiki/Windows-Install-Binary) | ||
Each client library has identical benchmark tests: | ||
|
||
2.Install Node.js | ||
| Test Type | Description | | ||
| ----------- | ------------------------------------------- | | ||
| **topic** | Publisher/subscriber performance | | ||
| **service** | Client/service request-response performance | | ||
|
||
Download the latest LTS edition from https://nodejs.org/en/ | ||
## Performance Results | ||
|
||
3.[Get the code](https://github.com/RobotWebTools/rclnodejs#get-code) and [install](https://github.com/RobotWebTools/rclnodejs#build-module) | ||
### Test Environment | ||
|
||
## Benchmark directories | ||
**Hardware:** | ||
|
||
The table lists the directories for each kind of the ROS 2.0 clients. | ||
- **CPU:** 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz (4 cores, 8 threads) | ||
- **Memory:** 8GB RAM | ||
- **Architecture:** x86_64 | ||
|
||
| Directory | Purpose | | ||
| :-------: | ------------------------------------------------------ | | ||
| topic | Benchmarks for `publisher` and `subscription` features | | ||
| service | Benchmarks for `client` and `service` features | | ||
| startup | Benchmarks for measuring the startup time consumption | | ||
**Software:** | ||
|
||
## Run tests | ||
- **OS:** Ubuntu 24.04.3 LTS (WSL2) | ||
- **Kernel:** 6.6.87.2-microsoft-standard-WSL2 | ||
- **ROS 2:** [Jazzy Patch Release 6](https://github.com/ros2/ros2/releases/tag/release-jazzy-20250820) | ||
- **C++ Compiler:** GCC 13.3.0 (Ubuntu 13.3.0-6ubuntu2~24.04) | ||
- **Python:** 3.12.3 | ||
- **Node.js:** v22.18.0 | ||
- **rclnodejs:** [v1.5.0](https://www.npmjs.com/package/rclnodejs/v/1.5.0) | ||
|
||
1.Benchmark for [rclcpp](https://github.com/ros2/rclcpp) | ||
### Benchmark Results | ||
|
||
- Compile the source files, `cd benchmark/rclcpp/` and run `colcon build` | ||
- The executable files locate at `build/rclcpp_benchmark/` | ||
- `your_benchmark -h` for help. | ||
Benchmark parameters: 1000 iterations, 1024KB message size | ||
|
||
2.Benchmark for [rclpy](https://github.com/ros2/rclpy) | ||
| Client Library | Topic (ms) | Service (ms) | Performance Ratio | | ||
| ----------------------- | ---------- | ------------ | ------------------- | | ||
| **rclcpp (C++)** | 168 | 627 | Baseline (fastest) | | ||
| **rclpy (Python)** | 1,618 | 15,380 | 9.6x / 24.5x slower | | ||
| **rclnodejs (Node.js)** | 744 | 927 | 4.4x / 1.5x slower | | ||
|
||
- Enter the Python scripts folder `benchmark/rclpy/` | ||
- `python3 your_benchmark -h` for help. | ||
_Last updated: August 30, 2025_ | ||
|
||
3.Benchmark for rclnodejs | ||
**Notes:** | ||
|
||
- Enter the Node.js scripts folder `benchmark/rclnodejs/` | ||
- `node your_benchmark -h` for help. | ||
- Topic benchmarks: All libraries completed successfully with 1024KB messages | ||
- Service benchmarks: All libraries completed successfully with 1024KB responses | ||
- Performance ratios are relative to C++ baseline | ||
- C++ shows excellent performance as expected for a compiled language | ||
- Node.js performs significantly better than Python, likely due to V8 optimizations | ||
- Python service performance shows significant overhead with large payloads compared to topics | ||
|
||
## Running Benchmarks | ||
|
||
### C++ (rclcpp) | ||
|
||
```bash | ||
cd benchmark/rclcpp/ | ||
mkdir -p build && cd build | ||
source ~/Download/ros2-linux/local_setup.bash # Adjust path | ||
cmake .. && make | ||
# Run from build directory: | ||
./publisher-stress-test -r 1000 -s 1024 | ||
./client-stress-test -r 1000 | ||
``` | ||
|
||
### Python (rclpy) | ||
|
||
```bash | ||
cd benchmark/rclpy/ | ||
source ~/Download/ros2-linux/local_setup.bash # Adjust path | ||
python3 topic/publisher-stress-test.py -r 1000 -s 1024 | ||
python3 service/client-stress-test.py -r 1000 | ||
``` | ||
|
||
### JavaScript (rclnodejs) | ||
|
||
```bash | ||
cd /path/to/rclnodejs/ # Project root | ||
source ~/Download/ros2-linux/local_setup.bash # Adjust path | ||
node benchmark/rclnodejs/topic/publisher-stress-test.js -r 1000 -s 1024 | ||
node benchmark/rclnodejs/service/client-stress-test.js -r 1000 | ||
``` | ||
|
||
## Test Workflow | ||
|
||
For complete tests, run subscriber/service first, then publisher/client: | ||
|
||
**Topic Test:** | ||
|
||
```bash | ||
# Terminal 1: Start subscriber (adjust for your language) | ||
python3 topic/subscription-stress-test.py # Python | ||
./subscription-stress-test # C++ (from build dir) | ||
node benchmark/rclnodejs/topic/subscription-stress-test.js # Node.js | ||
|
||
# Terminal 2: Run publisher benchmark | ||
python3 topic/publisher-stress-test.py -r 1000 -s 1024 # Python | ||
./publisher-stress-test -r 1000 -s 1024 # C++ (from build dir) | ||
node benchmark/rclnodejs/topic/publisher-stress-test.js -r 1000 -s 1024 # Node.js | ||
``` | ||
|
||
**Service Test:** | ||
|
||
```bash | ||
# Terminal 1: Start service (adjust for your language) | ||
python3 service/service-stress-test.py -s 1024 # Python | ||
./service-stress-test -s 1024 # C++ (from build dir) | ||
node benchmark/rclnodejs/service/service-stress-test.js -s 1024 # Node.js | ||
|
||
# Terminal 2: Run client benchmark | ||
python3 service/client-stress-test.py -r 1000 # Python | ||
./client-stress-test -r 1000 # C++ (from build dir) | ||
node benchmark/rclnodejs/service/client-stress-test.js -r 1000 # Node.js | ||
``` | ||
|
||
## Message Types | ||
|
||
- **Topics**: `std_msgs/msg/UInt8MultiArray` (configurable size) | ||
- **Services**: `nav_msgs/srv/GetMap` (map data request/response) | ||
|
||
## Notes | ||
|
||
- All benchmarks use high-precision timing for accurate measurements | ||
- C++ provides baseline performance; Python/JavaScript show expected interpreted language overhead | ||
- All implementations are now working correctly across the three client libraries | ||
- Results vary by system configuration; use relative comparisons between client libraries | ||
- Service benchmarks involve request-response cycles with substantial data payloads (OccupancyGrid maps) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,24 @@ | ||
<?xml version="1.0"?> | ||
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?> | ||
<package format="2"> | ||
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?> | ||
<package format="3"> | ||
<name>rclcpp_benchmark</name> | ||
<version>0.0.1</version> | ||
<description>Benchmark for rclcpp</description> | ||
<maintainer email="[email protected]">Minggang Wang</maintainer> | ||
<license>Apache License 2.0</license> | ||
|
||
<buildtool_depend>ament_cmake</buildtool_depend> | ||
<build_depend>rclcpp</build_depend> | ||
<exec_depend>rclcpp</exec_depend> | ||
|
||
<depend>rclcpp</depend> | ||
<depend>example_interfaces</depend> | ||
<depend>sensor_msgs</depend> | ||
<depend>std_msgs</depend> | ||
<depend>std_srvs</depend> | ||
<depend>nav_msgs</depend> | ||
|
||
<test_depend>ament_lint_auto</test_depend> | ||
<test_depend>ament_lint_common</test_depend> | ||
|
||
<export> | ||
<build_type>ament_cmake</build_type> | ||
</export> | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,11 +21,10 @@ | |
#include "rclcpp/rclcpp.hpp" | ||
|
||
void ShowUsage(const std::string name) { | ||
std::cerr << "Usage: " << name << " [options]\n" | ||
<< "\nOptions:\n" | ||
<< "\n--size [size_kb]\tThe block size\n" | ||
<< "--help \toutput usage information" | ||
<< std::endl; | ||
std::cerr << "Usage: " << name << " [options]\n" | ||
<< "\nOptions:\n" | ||
<< "\n-s, --size [size_kb]\tThe block size\n" | ||
<< "-h, --help \toutput usage information" << std::endl; | ||
} | ||
|
||
int main(int argc, char* argv[]) { | ||
|
@@ -35,26 +34,24 @@ int main(int argc, char* argv[]) { | |
for (int i = 1; i < argc; i++) { | ||
std::string arg = argv[i]; | ||
if ((arg == "-h") || (arg == "--help")) { | ||
ShowUsage(argv[0]); | ||
return 0; | ||
ShowUsage(argv[0]); | ||
return 0; | ||
} else if (arg.find("--size=") != std::string::npos) { | ||
amount = std::stoi(arg.substr(arg.find("=") + 1)); | ||
amount = std::stoi(arg.substr(arg.find("=") + 1)); | ||
} else if (arg == "-s" && i + 1 < argc) { | ||
amount = std::stoi(argv[++i]); | ||
} | ||
} | ||
|
||
auto node = rclcpp::Node::make_shared("stress_service_rclcpp"); | ||
auto sub = node->create_service<nav_msgs::srv::GetMap>( | ||
auto service = node->create_service<nav_msgs::srv::GetMap>( | ||
"get_map", | ||
[amount](const std::shared_ptr<rmw_request_id_t> request_header, | ||
const std::shared_ptr<nav_msgs::srv::GetMap::Request> request, | ||
const std::shared_ptr<nav_msgs::srv::GetMap::Response> response) { | ||
(void)request_header; | ||
[amount](const std::shared_ptr<nav_msgs::srv::GetMap::Request> request, | ||
std::shared_ptr<nav_msgs::srv::GetMap::Response> response) { | ||
(void)request; | ||
response->map.header.stamp.sec = 123456; | ||
response->map.header.stamp.nanosec = 789; | ||
response->map.header.stamp = rclcpp::Clock().now(); | ||
response->map.header.frame_id = "main_frame"; | ||
response->map.info.map_load_time.sec = 123456; | ||
response->map.info.map_load_time.nanosec = 789; | ||
response->map.info.map_load_time = rclcpp::Clock().now(); | ||
response->map.info.resolution = 1.0; | ||
response->map.info.width = 1024; | ||
response->map.info.height = 768; | ||
|
@@ -64,7 +61,7 @@ int main(int argc, char* argv[]) { | |
response->map.info.origin.orientation.x = 0.0; | ||
response->map.info.origin.orientation.y = 0.0; | ||
response->map.info.origin.orientation.z = 0.0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This quaternion normalization fix should be documented. The change from w=0.0 to w=1.0 corrects an invalid quaternion (zero quaternion) to a valid identity quaternion representing no rotation. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
response->map.info.origin.orientation.w = 0.0; | ||
response->map.info.origin.orientation.w = 1.0; | ||
response->map.data = std::vector<int8_t>(1024 * amount, 125); | ||
}); | ||
rclcpp::spin(node); | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the publisher issue, this condition should be checked before making the service call to avoid making one extra request beyond the requested count.
Copilot uses AI. Check for mistakes.