Skip to content

Commit

Permalink
feat: add aimrt_py benchmark publisher and subscriber applications (A…
Browse files Browse the repository at this point in the history
…imRT#28)

* feat: add aimrt_py benchmark publisher and subscriber applications

Introduce new benchmark publisher and subscriber modules, enabling performance testing with custom configuration. Includes necessary YAML configuration files and scripts for simulation of message publishing and receiving.

* style: correct message size formatting

Update the log message to use "bytes" for clarity and consistency in reporting metrics.

* feat: add python benchmark example and update dependencies

Introduce an aimrt_py benchmark example for Python testing. Replace boost dependency with the standalone asio library to reduce overall dependencies and enhance configuration options for zenoh and mqtt.

* feat: add aimrt_py channel benchmark example

Introduce a new benchmark example for aimrt_py to enhance Python benchmarking capabilities and provide clearer insights into performance metrics.

* format code

* style: format loss rate output

Remove the percentage symbol from the loss rate display for a cleaner presentation.

* docs: update release notes for v0.9.0

Clarify new features, config options, and dependency changes, including the addition of the aimrt_py channel benchmark example and removal of boost dependencies in favor of asio.

* docs: add benchmark example to Python interfaces section

Include a new link for the pb_chn_bench example to enhance the documentation and provide users with more comprehensive usage scenarios.

* docs: add README for protobuf channel benchmark example

Provide instructions on setting up and running a Python channel benchmark using protobuf with HTTP backend. Include details on core modules, configuration, and execution steps to enhance usability and understanding.

* docs: update installation instructions to link to quick start guide

Enhance user experience by providing direct access to the installation guide for the `aimrt_py` package, improving clarity and reducing search time for new users.

* docs: correct grpc reference in README

Update the section title to accurately reflect the protocol being used, enhancing clarity for users.
  • Loading branch information
zhangyi1357 authored Oct 16, 2024
1 parent 85ca6fb commit 036bd5b
Show file tree
Hide file tree
Showing 18 changed files with 712 additions and 11 deletions.
2 changes: 1 addition & 1 deletion document/sphinx-cn/release_notes/v0_9_0.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
- mqtt 新增配置项以支持加密传输;
- 新增了第三方库 asio,runtime::core 不再引用 boost,改为引用独立的 asio 库,以减轻依赖;


**次要修改**
- 缩短了一些 examples 的文件路径长度;
- 修复了一些轻微问题;
- 优化代码结构,移动代码 src/runtime/common/net 至新位置 src/common/net;
- 升级 jsoncpp 至 1.9.6 版本以优化一些 cmake 问题;
- 新增了 aimrt_py channel benchmark 示例;
1 change: 1 addition & 0 deletions document/sphinx-cn/tutorials/examples/examples_py.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ AimRT 提供了以下 Python 接口使用示例:
- {{ '[helloworld]({}/src/examples/py/helloworld)'.format(code_site_root_path_url) }}
- {{ '[pb_chn]({}/src/examples/py/pb_chn)'.format(code_site_root_path_url) }}
- {{ '[pb_rpc]({}/src/examples/py/pb_rpc)'.format(code_site_root_path_url) }}
- {{ '[pb_chn_bench]({}/src/examples/py/pb_chn_bench)'.format(code_site_root_path_url) }}

关于这些示例的说明:
- 每个示例都有自己独立的 readme 文档,详情请点击示例链接进入后查看;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ void BenchmarkSubscriberModule::Evaluate() const {
AIMRT_INFO(R"str(Benchmark plan {} completed, report:
frequency: {} hz
topic number: {}
msg size: {} byte
msg size: {} bytes
msg count per topic: {}
send count : {}
recv count: {}
Expand Down
4 changes: 2 additions & 2 deletions src/examples/py/helloworld/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


运行方式(linux):
- 安装 `aimrt_py` 包;
- [安装 `aimrt_py`](../../../../document/sphinx-cn/tutorials/quick_start/installation_py.md)
- 直接运行本目录下[start_examples_py_helloworld_app_mode.sh](./start_examples_py_helloworld_app_mode.sh)脚本启动进程;
- 键入`ctrl-c`停止进程;

Expand Down Expand Up @@ -45,7 +45,7 @@


运行方式(linux):
- 安装 `aimrt_py` 包;
- [安装 `aimrt_py`](../../../../document/sphinx-cn/tutorials/quick_start/installation_py.md)
- 直接运行本目录下[start_examples_py_helloworld_registration_mode.sh](./start_examples_py_helloworld_registration_mode.sh)脚本启动进程;
- 键入`ctrl-c`停止进程;

Expand Down
2 changes: 1 addition & 1 deletion src/examples/py/parameter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


运行方式(linux):
- 安装 `aimrt_py` 包;
- [安装 `aimrt_py`](../../../../document/sphinx-cn/tutorials/quick_start/installation_py.md)
- 直接运行本目录下[start_examples_py_parameter_app.sh](./start_examples_py_parameter_app.sh)脚本启动进程;
- 键入`ctrl-c`停止进程;

Expand Down
4 changes: 2 additions & 2 deletions src/examples/py/pb_chn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


运行方式(linux):
- 安装 `aimrt_py` 包;
- [安装 `aimrt_py`](../../../../document/sphinx-cn/tutorials/quick_start/installation_py.md)
- 运行本目录下的[build_examples_py_pb_chn.sh](./build_examples_py_pb_chn.sh)脚本,生成协议桩代码文件;
- 如果本地没有 protoc 或者 protoc 版本小于 3.20,请安装或升级 protoc,或直接修改脚本中的 `protoc_cmd` 变量指向合适的路径;
- 运行本目录下的[start_examples_py_pb_chn_http_sub.sh](./start_examples_py_pb_chn_http_sub.sh)脚本,启动 subscriber;
Expand Down Expand Up @@ -60,7 +60,7 @@


运行方式(linux):
- 安装 `aimrt_py` 包;
- [安装 `aimrt_py`](../../../../document/sphinx-cn/tutorials/quick_start/installation_py.md)
- 运行本目录下的[build_examples_py_pb_chn.sh](./build_examples_py_pb_chn.sh)脚本,生成协议桩代码文件;
- 如果本地没有 protoc 或者 protoc 版本小于 3.20,请安装或升级 protoc,或直接修改脚本中的 `protoc_cmd` 变量指向合适的路径;
- 运行本目录下的[start_examples_py_pb_chn_ros2_sub.sh](./start_examples_py_pb_chn_ros2_sub.sh)脚本,启动 subscriber;
Expand Down
34 changes: 34 additions & 0 deletions src/examples/py/pb_chn_bench/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# protobuf channel benchmark


一个基于 protobuf 协议与 http 后端的 python channel benchmark 示例,演示内容包括:
- 如何在 python 中使用 protobuf 协议作为 channel 传输协议;
- 如何基于 aimrt_py 注册模块的方式使用 Channel publish 和 subscribe 功能;
- 如何使用 http 类型的 channel 后端;

核心代码:
- [benchmark.proto](../../../protocols/example/benchmark.proto)
- [benchmark_publisher_module.py](./benchmark_publisher_module.py)
- [benchmark_publisher_app.py](./benchmark_publisher_app.py)
- [benchmark_subscriber_module.py](./benchmark_subscriber_module.py)
- [benchmark_subscriber_app.py](./benchmark_subscriber_app.py)

配置文件:
- [benchmark_publisher_cfg.yaml](./cfg/benchmark_publisher_cfg.yaml)
- [benchmark_subscriber_cfg.yaml](./cfg/benchmark_subscriber_cfg.yaml)


运行方式(linux):
- [安装 `aimrt_py`](../../../../document/sphinx-cn/tutorials/quick_start/installation_py.md)
- 运行本目录下的[build_examples_py_pb_chn_bench.sh](./build_examples_py_pb_chn_bench.sh)脚本,生成协议桩代码文件;
- 如果本地没有 protoc 或者 protoc 版本小于 3.20,请安装或升级 protoc,或直接修改脚本中的 `protoc_cmd` 变量指向合适的路径;
- 运行本目录下的[start_benchmark_subscriber.sh](./start_benchmark_subscriber.sh)脚本,启动 subscriber;
- 在新终端里运行本目录下的[start_benchmark_publisher.sh](./start_benchmark_publisher.sh)脚本,启动 publisher;
- Benchmark 运行结束后会输出 benchmark 结果并自动结束进程;


说明:
- 此示例创建了以下两个模块:
- `BenchmarkPublisherModule`:会在启动后根据配置好的 bench plan 向指定的 test_topic_xx 中发布类型为 `BenchmarkMsg` 的消息,每个 bench plan 前后会发送一个 `BenchmarkSignal` 类型的消息通知 subscriber 当前的 benchmark 状态,所有 bench plan 结束后会发送一个 `BenchmarkSignal` 类型的消息通知 subscriber 当前的 benchmark 结束;
- `BenchmarkSubscriberModule`:会订阅 channel 中的 test_topic_xx 消息,并统计接收到的消息的延迟分布;
- 此示例使用 http 类型的 channel 后端进行通信,请确保相关端口未被占用;
61 changes: 61 additions & 0 deletions src/examples/py/pb_chn_bench/benchmark_publisher_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright (c) 2024 The AimRT Authors.
# AimRT is licensed under Mulan PSL v2.

import argparse
import signal
import sys
import threading

import aimrt_py
import benchmark_publisher_module

global_aimrt_core = None


def signal_handler(sig, _):
global global_aimrt_core

if (global_aimrt_core and (sig == signal.SIGINT or sig == signal.SIGTERM)):
global_aimrt_core.Shutdown()
return

sys.exit(0)


def main():
parser = argparse.ArgumentParser(description='Example helloworld registration mode.')
parser.add_argument('--cfg_file_path', type=str, default="", help='config file path')
args = parser.parse_args()

signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)

print("AimRT start.")

aimrt_core = aimrt_py.Core()

global global_aimrt_core
global_aimrt_core = aimrt_core

module = benchmark_publisher_module.BenchmarkPublisher()
aimrt_core.RegisterModule(module)

core_options = aimrt_py.CoreOptions()
core_options.cfg_file_path = args.cfg_file_path
aimrt_core.Initialize(core_options)

thread = threading.Thread(target=aimrt_core.Start)
thread.start()

while thread.is_alive():
thread.join(1.0)

aimrt_core.Shutdown()

global_aimrt_core = None

print("AimRT exit.")


if __name__ == '__main__':
main()
Loading

0 comments on commit 036bd5b

Please sign in to comment.