性能优化
机构挂靠接口性能优化
问题/需求
- 【机构挂靠】sfe-affiliate-api/affiliate/open-list接口响应时间慢
- 药店挂靠,接口有点慢,451条数据,3分钟左右。
性能分析
机构挂靠服务
sfe-affiliate-api
服务调用关系
java
@ApiOperation("开放挂靠列表")
@PostMapping(AffiliateRouter.LIST_OPEN_AFFILIATE)
ActionResult<IPage<AffiliateRelationInfo>> getAffiliateRelationOpen(@SpringQueryMap Page page, @RequestBody @Validated AffiliateRelationOpenQO query);
接口监控
近一个月接口监控
抓取对应日志 获取入参
json
{
url: http://10.66.8.197/affiliate/open-list?pages=1&size=1000,
method: POST,
headers: [
host:sfe-affiliate-api.stable:8080,
tm-header-tenantid:df2c39341afd4ea7bc5c3d7e27c33b67,
spring-cloud-request-nonce:779104,
spring-cloud-request-sign:F6C1B9586683C1FFCABDF912A1C57F512004F920B18CAB1BC9872B1BCC1C966D,
traceparent:00-af99aca185386f2263a7e52bcdf1536c-66dd6081528be55a-00,
content-type:application/json; charset=utf-8,
x-request-id:4d013d8c-0de3-41cb-8f4c-6638ddcdaa40,
x-envoy-attempt-count:1,
x-envoy-original-path:/gw/open/sfe-affiliate-api/affiliate/open-list?pages=1&size=1000,
content-length:72,
forwarded:proto=http;host=10.66.8.197;for="192.168.84.177:37060",
x-forwarded-client-cert:By=spiffe://cluster.local/ns/stable/sa/default;Hash=0b0446fbc3606fe738b8f314c12f79d36238e143cb8b2c1644b9c00f4e3d976f;Subject="";URI=spiffe://cluster.local/ns/stable/sa/default,
x-forwarded-proto:http,http,
x-forwarded-prefix:/open/sfe-affiliate-api,
x-forwarded-port:80,
x-forwarded-host:10.66.8.197,
user-agent:ReactorNetty/1.0.10,
accept:*/*
],
body: {"pages":1,"size":1000,"periodIds":["8ac2ae5e82fe851e0187b2238fa0022e"]},
protocol: HTTP/1.1
}
接口性能
采用 Arthas排查接口耗时
步骤 | 执行 | 备注 |
---|---|---|
1 | marketing-sfe-affiliate-api-latest-558fbf674-lkjw4 | pod |
2 | kubectl exec -it marketing-sfe-affiliate-api-latest-558fbf674-lkjw4 -c marketing-sfe-affiliate-api -n stable -- /bin/sh | |
3 | wget https://alibaba.github.io/arthas/arthas-boot.jar | arthas |
4 | java -jar arthas-boot.jar |
json
curl --location 'localhost:8080/affiliate/open-list?pages=1&size=1000' \
--header 'tm-header-tenantid: df2c39341afd4ea7bc5c3d7e27c33b67' \
--header 'spring-cloud-request-nonce: 779104' \
--header 'spring-cloud-request-sign: F6C1B9586683C1FFCABDF912A1C57F512004F920B18CAB1BC9872B1BCC1C966D' \
--header 'traceparent: 00-af99aca185386f2263a7e52bcdf1536c-66dd6081528be55a-00' \
--header 'content-type: application/json; charset=utf-8' \
--header 'x-request-id: 4d013d8c-0de3-41cb-8f4c-6638ddcdaa40' \
--header 'x-envoy-attempt-count: 1' \
--header 'content-length: 72' \
--header 'Cookie: JSESSIONID=4D81FAFACD926C8A2D036F2784388BFC; XSRF-TOKEN=0fd2143d-5210-4fcd-a15f-434d0a1b690d' \
--data '{
"pages": 1,
"size": 1000,
"periodIds": [
"8ac2ae5e82fe851e0187b2238fa0022e"
]
}'
json
trace com.taimei.sfe.affiliate.api.facade.AffiliateRelationFacade getAffiliateRelationByPage -n 5 --skipJDKMethod false
json
trace com.taimei.sfe.core.affiliate.biz.AffiliateRelationService getAffiliateRelationByPage -n 5 --skipJDKMethod false
json
trace com.taimei.sfe.core.affiliate.biz.AffiliateRelationService fillDisplayData -n 5 --skipJDKMethod false
解决方案
批量查询字典数据后赋值,避免在大循环体内批量调用外部接口