From 3594abc28efcafad23b5b648aa3ae35bd21250a7 Mon Sep 17 00:00:00 2001 From: zhangyi1357 <34409786+zhangyi1357@users.noreply.github.com> Date: Fri, 25 Oct 2024 11:52:55 +0800 Subject: [PATCH] refactor: remove shutdown peer logic from publisher and subscriber (#52) * refactor: remove shutdown peer logic from publisher and subscriber Streamline benchmarking process by eliminating shutdown peer signal handling, simplifying the code and improving clarity. * docs: clarify benchmark termination process Update the README to specify that benchmark results will be output in the subscriber terminal and that the process can be terminated in both terminals using `Ctrl+C`. This improves user guidance for smoother execution. --- src/examples/py/pb_chn_bench/README.md | 4 ++-- .../py/pb_chn_bench/benchmark_publisher_module.py | 11 ----------- .../py/pb_chn_bench/benchmark_subscriber_module.py | 4 ---- .../py/pb_rpc_bench/benchmark_rpc_client_module.py | 2 +- src/protocols/example/benchmark.proto | 1 - 5 files changed, 3 insertions(+), 19 deletions(-) diff --git a/src/examples/py/pb_chn_bench/README.md b/src/examples/py/pb_chn_bench/README.md index 814234e73..1b3be7bf7 100644 --- a/src/examples/py/pb_chn_bench/README.md +++ b/src/examples/py/pb_chn_bench/README.md @@ -24,8 +24,8 @@ - 如果本地没有 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 结果并自动结束进程; - +- Benchmark 运行结束后在 subscriber 终端中会输出 benchmark 结果; +- 在两个终端中分别按 `Ctrl+C` 键结束 benchmark; 说明: - 此示例创建了以下两个模块: diff --git a/src/examples/py/pb_chn_bench/benchmark_publisher_module.py b/src/examples/py/pb_chn_bench/benchmark_publisher_module.py index abaa4dab9..a1a945e1f 100644 --- a/src/examples/py/pb_chn_bench/benchmark_publisher_module.py +++ b/src/examples/py/pb_chn_bench/benchmark_publisher_module.py @@ -158,8 +158,6 @@ class BenchmarkPublisher(aimrt_py.ModuleBase): time.sleep(self.bench_interval) - self.ShutdownPeer() - except Exception as e: aimrt_py.error(self.logger, f"Exit MainLoop with exception: {e}") @@ -220,15 +218,6 @@ class BenchmarkPublisher(aimrt_py.ModuleBase): if self.completed_tasks == self.total_tasks: self.publish_complete_event.set() - def ShutdownPeer(self) -> None: - shutdown_peer_signal = benchmark_pb2.BenchmarkSignal() - shutdown_peer_signal.status = benchmark_pb2.BenchmarkStatus.ShutdownPeer - aimrt_py.info(self.logger, f"Publish benchmark shutdown peer signal, data: {shutdown_peer_signal}") - aimrt_py.Publish(self.signal_publisher, shutdown_peer_signal) - - time.sleep(self.shutdown_delay) - os.kill(os.getpid(), signal.SIGINT) - @staticmethod def GenerateRandomString(length: int) -> bytes: return ''.join(random.choices(string.ascii_letters + string.digits, k=length)).encode() diff --git a/src/examples/py/pb_chn_bench/benchmark_subscriber_module.py b/src/examples/py/pb_chn_bench/benchmark_subscriber_module.py index a4e934894..1a6bbf432 100644 --- a/src/examples/py/pb_chn_bench/benchmark_subscriber_module.py +++ b/src/examples/py/pb_chn_bench/benchmark_subscriber_module.py @@ -120,10 +120,6 @@ class BenchmarkSubscriber(aimrt_py.ModuleBase): case benchmark_pb2.BenchmarkStatus.End: self.Evaluate() - case benchmark_pb2.BenchmarkStatus.ShutdownPeer: - aimrt_py.info(self.logger, f"Received shutdown peer signal, shutdown aimrt core now.") - os.kill(os.getpid(), signal.SIGINT) - case _: aimrt_py.error(self.logger, f"Unknown signal status: {signal_msg.status}") diff --git a/src/examples/py/pb_rpc_bench/benchmark_rpc_client_module.py b/src/examples/py/pb_rpc_bench/benchmark_rpc_client_module.py index f3161171e..e9fed44c6 100644 --- a/src/examples/py/pb_rpc_bench/benchmark_rpc_client_module.py +++ b/src/examples/py/pb_rpc_bench/benchmark_rpc_client_module.py @@ -194,7 +194,7 @@ class BenchmarkRpcClientModule(aimrt_py.ModuleBase): result_str += f"\navg latency: {avg_latency:.2f} us" result_str += f"\np90 latency: {p90_latency:.2f} us" result_str += f"\np99 latency: {p99_latency:.2f} us" - result_str += f"\np999 latency: {p999_latency:.2f} us" + result_str += f"\np999 latency: {p999_latency:.2f} us\n" aimrt_py.info(self.logger, result_str) def StartBenchPlan(self, plan: dict) -> None: diff --git a/src/protocols/example/benchmark.proto b/src/protocols/example/benchmark.proto index aa31e0027..52df1ea7a 100644 --- a/src/protocols/example/benchmark.proto +++ b/src/protocols/example/benchmark.proto @@ -9,7 +9,6 @@ enum BenchmarkStatus { Begin = 0; End = 1; WarmUp = 2; - ShutdownPeer = 3; } message BenchmarkSignal {