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.
This commit is contained in:
zhangyi1357 2024-10-25 11:52:55 +08:00 committed by GitHub
parent 42ba5be784
commit 3594abc28e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 3 additions and 19 deletions

View File

@ -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
说明:
- 此示例创建了以下两个模块:

View File

@ -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()

View File

@ -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}")

View File

@ -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:

View File

@ -9,7 +9,6 @@ enum BenchmarkStatus {
Begin = 0;
End = 1;
WarmUp = 2;
ShutdownPeer = 3;
}
message BenchmarkSignal {