主函数
()
| 318 | |
| 319 | |
| 320 | def main(): |
| 321 | """主函数""" |
| 322 | parser = argparse.ArgumentParser( |
| 323 | description="分布式Master-Worker服务器架构", |
| 324 | formatter_class=argparse.RawDescriptionHelpFormatter, |
| 325 | epilog=""" |
| 326 | 示例用法: |
| 327 | |
| 328 | 1. 启动Master服务器 (动态工具发现): |
| 329 | python cli.py --mode master --port 8000 |
| 330 | |
| 331 | 2. 启动Master服务器 (预配置工具): |
| 332 | python cli.py --mode master --tools_yaml_path config.yaml --port 8000 |
| 333 | |
| 334 | 3. 在其他机器上启动Worker: |
| 335 | python cli.py --mode worker --tools_yaml_path config.yaml --master_url http://master_ip:8000 --port 8001 --num_workers 3 |
| 336 | |
| 337 | 4. 启动统一服务器(单机Master+多Worker模式): |
| 338 | python cli.py --mode unified --tools_yaml_path config.yaml --port 8000 --num_workers 8 |
| 339 | python cli.py --mode unified --tools_yaml_path config.yaml --port 8000 --keep_running --num_workers 8 |
| 340 | python cli.py --mode unified --tools_yaml_path config.yaml --port 8000 --test_servers --keep_running --timeout_per_query 600 --num_workers 5 |
| 341 | """ |
| 342 | ) |
| 343 | |
| 344 | parser.add_argument( |
| 345 | "--mode", |
| 346 | choices=["master", "worker", "unified"], |
| 347 | required=True, |
| 348 | help="运行模式: master(Master服务器), worker(Worker服务器), unified(统一服务器)" |
| 349 | ) |
| 350 | parser.add_argument( |
| 351 | "--tools_yaml_path", |
| 352 | required=False, |
| 353 | help="工具配置YAML文件路径" |
| 354 | ) |
| 355 | parser.add_argument( |
| 356 | "--bootcamp_registry", |
| 357 | required=False, |
| 358 | help="bootcamp注册表,提供后可将注册表里所有bootcamp的tool挂载到woker server" |
| 359 | ) |
| 360 | parser.add_argument( |
| 361 | "--port", |
| 362 | type=int, |
| 363 | default=None, |
| 364 | help="服务器端口号 (默认: 随机分配可用端口)" |
| 365 | ) |
| 366 | parser.add_argument( |
| 367 | "--host", |
| 368 | default="0.0.0.0", |
| 369 | help="服务器主机地址 (默认: 0.0.0.0)" |
| 370 | ) |
| 371 | parser.add_argument( |
| 372 | "--master_url", |
| 373 | help="Master服务器URL (Worker模式必需)" |
| 374 | ) |
| 375 | parser.add_argument( |
| 376 | "--worker_id", |
| 377 | help="Worker ID (Worker模式使用,默认自动生成)" |
no test coverage detected