Skip to content

Commit

Permalink
style: 调整格式
Browse files Browse the repository at this point in the history
  • Loading branch information
youngledo committed May 27, 2024
1 parent b2882b3 commit cc53652
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions docs/java/troubleshoot/memory-performance-optimization.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
![img_1.png](assets/memory-performance-optimization/img_1.png)

#### 分析
可见,CPU的使用率很低,主要集中在内存和线程上
可见,CPU的使用率很低,主要集中在内存和GC上
- 内存:内存的消耗递增,且中间过程有多次GC。可以进一步分析哪处的内存占用最高。
- 线程:这里展示了活动、守护状态的线程
- GC:可以明显看到“下载阶段”和“解压阶段”存在多次的GC

### 2. 使用IDEA官方自带的`Profiler`
> 其实是IDEA整合了[async-profiler](https://github.com/async-profiler/async-profiler)
Expand All @@ -48,6 +48,7 @@ CPU消耗主要集中在下载安装包上面。
**备注**:关于`jfr`的分配为何这么大,参考此文章:[关于使用IDEA的profiler的内存分配的疑问 : IDEA-340722 (jetbrains.com)](https://youtrack.jetbrains.com/issue/IDEA-340722/IDEAprofiler)

## 三、优化方案
### 内存
1. 减少buffer的new的次数,只需要new一个即可;
2. 改造压缩流到文件的使用方式。

Expand All @@ -56,17 +57,25 @@ CPU消耗主要集中在下载安装包上面。
- 优化前:[StartApplication_2023_12_12_204042-FileUtils#copyToFile.jfr](https://drive.weixin.qq.com/s?k=AIsAVQcAABIhUcQNyy)

![img_8.png](assets/memory-performance-optimization/img_8.png)

- 单独测试解压(频繁的GC)

![img_9.png](assets/memory-performance-optimization/img_9.png)

- 优化后:[StartApplication_2023_12_13_103851-IOUtils#copyLarge.jfr.zip](https://drive.weixin.qq.com/s?k=AIsAVQcAABIksyYgLC)
![img_10.png](assets/memory-performance-optimization/img_10.png)
- 解压内存分配减少100MB

![img_11.png](assets/memory-performance-optimization/img_11.png)
- 单独测试解压(只GC了一次,后面的一次是我二次点击)

### GC
- 优化前
- 解压阶段

![img_9.png](assets/memory-performance-optimization/img_9.png)

- 优化后(只GC了一次)
- 解压阶段

![img_12.png](assets/memory-performance-optimization/img_12.png)

另外说明下,上述内存图中`下载阶段`有多次GC的情况,这是因为使用的是Java原生的`HttpURLConnection`,而使用minio的SDK自带的`okhttp`则没有此情况:
![img_13.png](assets/memory-performance-optimization/img_13.png)
- 下载阶段

上述内存图中`下载阶段`有多次GC的情况,这是因为使用的是Java原生的`HttpURLConnection`,而使用minio的SDK自带的`okhttp`则没有此情况:

![img_13.png](assets/memory-performance-optimization/img_13.png)

0 comments on commit cc53652

Please sign in to comment.