Skip to content

Commit

Permalink
压力测试
Browse files Browse the repository at this point in the history
  • Loading branch information
deipss committed Jan 23, 2024
1 parent 90a5f09 commit f181769
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 2 deletions.
20 changes: 18 additions & 2 deletions docs/Solution/记一次库存优化.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ parent: Solution

- job频率过高,导致FGC?

在使用CMS作为老年代的GC器,默认maxTenuringThreshold=4,(G1=16)的前提下,
在使用CMS作为老年代的GC器,默认[maxTenuringThreshold=6](https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html#BABFAFAE),(G1=16)的前提下,
YGC会更快速的晋升到OLD区; 再者,本地缓存使用的强引用,在第二次全量同步前,
就进入了OLD区

Expand Down Expand Up @@ -90,6 +90,9 @@ Mixed GC不是Full GC,它只能回收部分老年代的Region,如果Mixed GC
parnew+cms收集器,parnew使用复制算法回收年轻代,cms使用标记清除算法回收old区。
cms回收old区会产生内存碎片,导致内存不连续。

CMS是在STW时期做的碎片整理
G1在回收内存后,马上在碎片整理

G1 mixed gc使用复制算法回收年轻代+老年代,没有内存碎片的问题。


Expand All @@ -101,12 +104,21 @@ G1 mixed gc使用复制算法回收年轻代+老年代,没有内存碎片的

InitiatingHeapOccupancyPercent

> itiatingHeapOccupancyPercent,他的默认是45%,他的含义就是老年代到了45%的时候,就会进行混合回收,比如有2048个region,其中老年代占据了有1000个region,就会混合回收.


G1HeapWastePercent
> 在global concurrent marking结束之后,我们可以知道old gen regions中有多少空间要被回收,在每次YGC之后和再次发生Mixed GC之前,会检查垃圾占比是否达到此参数,只有达到了,下次才会发生Mixed GC
G1OldCSetRegionThresholdPercent

> 一次Mixed GC中能被选入CSet的最多old generation region数量
G1MixedGCCountTarget

> G1MixedGCCountTarget:一次global concurrent marking之后,最多执行Mixed GC的次数
## 4.5. G1 常见问题

- G1什么时候触发mixed gc?
Expand All @@ -121,4 +133,8 @@ G1MixedGCCountTarget

- G1什么时候触发young gc?

G1YGC在Eden充满时触发,在回收之后所有之前属于Eden的区块全部变成空白,即不属于任何一个分区。
G1YGC在Eden充满时触发,在回收之后所有之前属于Eden的区块全部变成空白,即不属于任何一个分区。

# 总结
- G1弱化了分代的概念,重视分区的重要性,
- 合适的应用场景:大内存,多核心的硬件条件,如ElasticSearch、
79 changes: 79 additions & 0 deletions docs/test/压力测试.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
layout: default
title: 压力测试
parent: Test
---

# arthas thrace命令分析耗时

```text
[arthas@82]$ trace com.test.web.controller.OrderUniteController queryOrderPage -n 5 --skipJDKMethod false
Press Q or Ctrl+C to abort.
Affect(class count: 1 , method count: 1) cost in 655 ms, listenerId: 1
`---ts=2024-01-22 11:02:30;thread_name=http-nio-9166-exec-6;id=122;is_daemon=true;priority=5;TCCL=org.springframework.boot.web.embedded.tomcat.TomcatEmbeddedWebappClassLoader@5ea0f263
`---[197.718153ms] com.test.web.controller.OrderUniteController:queryOrderPage()
+---[0.16% 0.321685ms ] org.slf4j.Logger:info() #83
+---[0.01% 0.014182ms ] com.test.web.request.OrderUnitePageDTO:getOrderType() #84
+---[0.01% 0.010145ms ] com.test.common.to.PaginationRequest:<init>() #101
+---[0.02% 0.043364ms ] com.test.web.mapstruct.OrderUniteMapStruct:pageDtoToRequest() #102
+---[8.46% 16.728599ms ] com.test.web.controller.OrderUniteController:setDataAuthByOrderType() #104
+---[0.01% 0.011294ms ] com.test.common.to.PaginationRequest:setConditions() #107
+---[0.00% 0.008099ms ] com.test.web.request.OrderUnitePageDTO:getPageSize() #108
+---[0.00% 0.008459ms ] com.test.common.to.PaginationRequest:setPageSize() #108
+---[0.00% 0.009668ms ] com.test.web.request.OrderUnitePageDTO:getPageIndex() #109
+---[0.00% 0.007329ms ] com.test.common.to.PaginationRequest:setPageNum() #109
+---[87.44% 172.885494ms ] com.test.web.client.OrderUniteClient:queryOrderPage() #110
+---[0.04% 0.070558ms ] com.test.web.mapstruct.OrderUniteMapStruct:dtoFaceToPageVO() #112
`---[3.14% 6.209232ms ] com.test.web.controller.OrderUniteController:doVoucherPageSumAmt() #115
```

```text
Affect(class count: 2 , method count: 2) cost in 374 ms, listenerId: 7
`---ts=2024-01-22 11:46:05;thread_name=DubboServerHandler-10.253.68.210:9165-thread-56;id=9150;is_daemon=true;priority=5;TCCL=org.springframework.boot.loader.LaunchedURLClassLoader@3c8a7e38
`---[26.0524ms] com.test.core.accounting.impl.TestServiceImpl:queryTestPage()
+---[0.13% 0.034457ms ] com.test.facade.api.request.accounting.TestPageRequest:getPage() #136
+---[0.03% 0.007267ms ] com.test.facade.api.request.accounting.TestPageRequest:getRows() #136
+---[0.04% 0.010735ms ] com.baomidou.mybatisplus.extension.plugins.pagination.Page:<init>() #136
+---[1.94% 0.50524ms ] com.test.core.accounting.impl.TestServiceImpl:buildWrapper() #137
+---[79.70% 20.763484ms ] com.test.repository.mapper.voucher.TestMapper:selectPage() #137
+---[0.05% 0.012289ms ] com.baomidou.mybatisplus.extension.plugins.pagination.Page:getRecords() #137
+---[0.04% 0.010785ms ] com.test.common.to.PaginationResponse:<init>() #138
+---[0.02% 0.005444ms ] org.apache.commons.collections4.CollectionUtils:isEmpty() #141
+---[0.11% 0.028614ms ] java.util.Comparator:comparing() #145
+---[0.10% 0.026304ms ] java.util.Comparator:thenComparingInt() #145
+---[0.37% 0.096225ms ] java.util.List:sort() #145
+---[0.72% 0.187958ms ] com.test.repository.mapStruct.TestMapStruct:entityListToDtoList() #147
+---[0.03% 0.008859ms ] com.test.common.to.PaginationResponse:setList() #147
+---[0.03% 0.006987ms ] com.baomidou.mybatisplus.extension.plugins.pagination.Page:getTotal() #148
`---[0.03% 0.007384ms ] com.test.common.to.PaginationResponse:setTotal() #148
```

1. java一般的ger/set方法,比如**getPageSize**,消耗的是0.008099ms,就是8.099ns,非常短
2. java的(小规模)集合操作,会耗时一小会,[0.37% 0.096225ms ] java.util.List:sort() #145
3. IO消耗的时间长[79.70% 20.763484ms ] com.test.repository.mapper.voucher.TestMapper:selectPage() #137

综合上面的测试及描述。一些核心接口在压力测试时,就要评估好QPS以及TPS。评估时要全面考虑接口的
复杂度,后续调用链路的长短。一般情况下。电商各条业务线的TPS和QPS可以粗略评估如下

# 支付

一般支付有读写操作都频繁的核心接口如下

- 核心支付
- 取消订单
- 订单查询

# 交易

一般支付有读写操作都频繁的核心接口如下

- 创建
- 取消订单
- 订单查询

# 风控

风控更多的是查询接口,而且一般是使用多级缓存(本地缓存、分布式缓存)来降低调用链路的时延

- 黑名单查询
- 灰产询

0 comments on commit f181769

Please sign in to comment.