# opensearch-test **Repository Path**: yangchen01/opensearch-test ## Basic Information - **Project Name**: opensearch-test - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-09-12 - **Last Updated**: 2025-09-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # OpenSearch压力测试方案 基于OpenSearch压力测试方案,对现有脚本进行了全面增强,提供了完整的压力测试解决方案。 ## 功能特性 ### 1. 数据生成器增强 (data_credit_generator.py) - ✅ 批量索引性能测试 - ✅ 实时写入性能测试 - ✅ 系统性能监控 - ✅ 详细的性能指标收集 - ✅ 多线程并发支持 - ✅ 错误处理和重试机制 ### 2. 查询测试增强 (opensearch_credit_test.py) - ✅ 基于ids的查询场景测试 - ✅ 聚合查询性能测试 - ✅ 并发查询测试 - ✅ 稳定性测试(长时间运行) - ✅ 集群健康状态检查 - ✅ 实时性能监控 ### 3. 综合测试运行器 (run_comprehensive_test.py) - ✅ 自动化测试流程 - ✅ 多种测试场景支持 - ✅ 测试结果汇总和报告生成 - ✅ 优化建议生成 - ✅ 依赖检查和环境验证 ### 4. 配置文件支持 (test_config.json) - ✅ 预定义测试场景 - ✅ 性能阈值配置 - ✅ 监控参数配置 - ✅ 集群配置管理 ## 快速开始 ### 1. 环境准备 ```bash # 安装Python依赖 pip3 install requests psutil statistics # 确保脚本有执行权限 chmod +x run_stress_test.sh ``` ### 2. 基本使用 #### 使用Shell脚本(推荐) ```bash # 轻负载测试 ./run_stress_test.sh --scenario light_load # 中负载测试 ./run_stress_test.sh --scenario medium_load # 重负载测试 ./run_stress_test.sh --scenario heavy_load # 极限负载测试 ./run_stress_test.sh --scenario extreme_load # 稳定性测试(24小时) ./run_stress_test.sh --scenario stability_test ``` #### 使用Python脚本 ```bash # 运行综合测试 python3 run_comprehensive_test.py --scenario medium_load # 自定义参数 python3 run_comprehensive_test.py \ --scenario heavy_load \ --bulk-docs 50000 \ --concurrent-users 100 \ --include-stability ``` ### 3. 单独测试组件 #### 数据生成和索引测试 ```bash # 批量索引测试 python3 data_credit_generator.py --test-bulk --count 10000 # 实时写入测试 python3 data_credit_generator.py --test-realtime --realtime-threads 10 # 运行所有数据测试 python3 data_credit_generator.py --test-all ``` #### 查询性能测试 ```bash # 基于ids的查询测试 python3 opensearch_credit_test.py --test-ids --ids-queries 1000 # 聚合查询测试 python3 opensearch_credit_test.py --test-agg --agg-queries 100 # 并发查询测试 python3 opensearch_credit_test.py --test-concurrent --concurrent-users 50 # 稳定性测试 python3 opensearch_credit_test.py --test-stability --stability-hours 2 # 运行所有查询测试 python3 opensearch_credit_test.py --test-all # 检查集群健康状态 python3 opensearch_credit_test.py --check-health ``` ## 测试场景说明 ### 1. light_load - 轻负载测试 - **用途**: 验证基本功能,适合开发环境 - **特点**: 低并发、小数据量、短时间 - **参数**: 5000文档,25并发用户,0.5小时稳定性 ### 2. medium_load - 中负载测试 - **用途**: 日常性能评估,适合测试环境 - **特点**: 中等并发、中等数据量、适中时间 - **参数**: 10000文档,50并发用户,1小时稳定性 ### 3. heavy_load - 重负载测试 - **用途**: 生产环境容量规划 - **特点**: 高并发、大数据量、长时间 - **参数**: 20000文档,75并发用户,2小时稳定性 ### 4. extreme_load - 极限负载测试 - **用途**: 压力极限测试,寻找性能瓶颈 - **特点**: 极高并发、超大数据量、长时间 - **参数**: 50000文档,100并发用户,4小时稳定性 ### 5. stability_test - 稳定性测试 - **用途**: 长时间运行验证,适合生产环境 - **特点**: 持续负载、长时间运行 - **参数**: 10000文档,50并发用户,24小时稳定性 ## 性能指标 ### 索引性能指标 - **批量索引吞吐量**: documents/second - **实时写入吞吐量**: documents/second - **索引成功率**: percentage - **平均响应时间**: seconds - **P95/P99响应时间**: seconds ### 查询性能指标 - **查询QPS**: queries/second - **查询成功率**: percentage - **平均响应时间**: seconds - **P95/P99响应时间**: seconds ### 系统资源指标 - **CPU使用率**: percentage - **内存使用率**: percentage - **磁盘使用率**: percentage - **网络I/O**: bytes/second ## 测试报告 测试完成后会生成详细的JSON报告,包含: 1. **测试信息**: 时间戳、集群信息、测试配置 2. **测试结果**: 各项测试的详细结果 3. **性能摘要**: 总体性能指标 4. **优化建议**: 基于测试结果的改进建议 ### 报告示例 ```json { "test_info": { "timestamp": "2024-01-15T10:30:00", "hosts": ["10.94.158.46:9200", "10.94.158.13:9200"], "username": "opensearch" }, "test_results": { "bulk_index": { "status": "success", "duration": 120.5, "throughput": 5000.0 } }, "summary": { "total_tests": 5, "successful_tests": 5, "success_rate": 100.0, "recommendations": [ "批量索引性能良好,可以适当增加批次大小", "建议定期监控集群健康状态" ] } } ``` ## 配置说明 ### test_config.json 配置文件 ```json { "test_scenarios": { "medium_load": { "bulk_docs": 10000, "batch_size": 1000, "concurrent_users": 50 } }, "performance_thresholds": { "bulk_index_throughput": { "min": 1000, "target": 5000 } } } ``` ## 故障排除 ### 常见问题 1. **连接失败** ```bash # 检查集群健康状态 python3 opensearch_credit_test.py --check-health ``` 2. **认证失败** - 检查用户名和密码 - 确认用户权限 3. **性能不佳** - 检查系统资源使用情况 - 调整测试参数 - 检查网络延迟 4. **内存不足** - 减少并发线程数 - 减少批次大小 - 增加系统内存 ### 日志文件 - 测试日志保存在 `logs/` 目录 - 报告文件保存在 `reports/` 目录 - 详细错误信息在控制台输出 ## 最佳实践 1. **测试前准备** - 确保集群健康状态为绿色 - 检查系统资源充足 - 备份重要数据 2. **测试执行** - 从轻负载开始,逐步增加 - 监控系统资源使用情况 - 记录测试结果和配置 3. **结果分析** - 对比不同场景的性能指标 - 识别性能瓶颈 - 制定优化方案 4. **定期测试** - 系统升级后重新测试 - 配置变更后验证性能 - 定期进行稳定性测试 ## 扩展功能 ### 自定义测试场景 可以通过修改 `test_config.json` 或使用命令行参数来自定义测试场景: ```bash python3 run_comprehensive_test.py \ --bulk-docs 30000 \ --batch-size 1500 \ --bulk-threads 8 \ --concurrent-users 80 \ --stability-hours 3 ``` ### 集成到CI/CD 可以将测试脚本集成到持续集成流程中: ```bash # 在CI中运行轻负载测试 ./run_stress_test.sh --scenario light_load ``` ## 技术支持 如有问题或建议,请参考: 1. OpenSearch官方文档 2. 测试脚本中的详细注释 3. 生成的测试报告和日志 --- **注意**: 请在生产环境运行测试前,确保有足够的系统资源和备份策略。