微服务优化实战指南
1. 微服务性能测试工具
可以通过发送根据脚本规则构建的 HTTP 请求来对微服务进行负载测试,并输出如下报告:
Threads 4
Iterations 5
Rampup 2
Base URL http://localhost:8080
Index Page http://localhost:8080/ 200 OK 7ms
Index Page http://localhost:8080/ 200 OK 8ms
...
Index Page http://localhost:8080/ 200 OK 1ms
Concurrency Level 4
Time taken for tests 0.2 seconds
Total requests 20
Successful requests 20
Failed requests 0
Requests per second 126.01 [#/sec]
Median time per request 1ms
Average time per request 3ms
Sample standard deviation 3ms
有两个工具适合测试微服务性能:
- Welle:若要优化指定处理程序,它适合测量单一请求类型的性能。
- Drill:适合产生复杂负载,以衡量应用程序可服务的用户数量。
2. 性能测量与优化示例
我们将测量一个示例微服务在两种编译选项下的性能:无优化和编译器