我的项目是在Springboot中使用eureka,zuul,功能区开发的,它部署在GCP kubernetes集群上。如果我尝试通过邮递员休息电话它工作正常,但需要很长时间(1s-2s)才能得到答复。我曾尝试对服务器进行负载测试。以下显示了负载测试的结果。但是考虑到这个请求没有连接到数据库,它只是点击并返回硬编码值。
Running 30s test @ https://xxx.coo:443/api/v1/lo/test/test1
100 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 1.23s 162.00ms 1.42s 45.45%
Req/Sec 0.00 0.00 0.00 100.00%
333 requests in 30.07s, 168.96KB read
Socket errors: connect 0, read 0, write 0, timeout 300
Non-2xx or 3xx responses: 200
Requests/sec: 11.08
Transfer/sec: 5.62KB
为什么请求/秒这么低?我应该如何配置服务器以处理更多负载?
这是我的配置。考虑发现服务器,zuul api和其他客户端服务器作为不同的springboot项目运行。
Discovery Server application.properties文件
spring:
application:
name: eureka-server
server:
port: 8070
eureka:
environment: production
client:
register-with-eureka: false
fetch-registry: false
server:
waitTimeInMsWhenSyncEmpty: 0
service-url:
defaultZone : ${DIS_SERVER}
Zuul Gateway application.properties文件
zuul:
prefix: /api/v1
routes:
g1-server:
path: /g1/**
serviceId: G1-SERVER
g2-server:
path: /g2/**
serviceId: G2-SERVER
spring:
application:
name: zuul-server
server:
port: 5000
eureka:
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone : ${DIS_SERVER}
spring:
cloud:
inetutils:
ignored-interfaces:
- eth0
- eth1
- eth2
- eth3
- lo
- veth.*
ribbon:
ConnectTimeout: 200000
ReadTimeout: 200000
我使用restTemplate来调用其他微服务。下面的代码显示了我如何使用restTemplate来调用其他微服务。
String g1Url = "http://g1-server/ud/{id}";
String g1Response = restTemplate.getForObject(g1Url, String.class, id);