zhaoguangqin opened a new issue, #4181:
URL: https://github.com/apache/hertzbeat/issues/4181
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Current Behavior
导出hertzbeat dump文件,分析如下:
Class Name | Objects | Shallow Heap |
Retained Heap
----------------------------------------------------------------------------------------
| | |
byte[] | 396,159 | 49.56 MB |
>= 49.56 MB
org.postgresql.jdbc.PgConnection | 819 | 0.10 MB |
>= 38.84 MB
java.lang.ref.Finalizer | 1,149 | 0.04 MB |
>= 38.41 MB
java.lang.Object[] | 59,737 | 6.01 MB |
>= 30.34 MB
java.util.concurrent.ConcurrentHashMap | 5,735 | 0.35 MB |
>= 26.61 MB
java.util.concurrent.ConcurrentHashMap$Node[]| 3,296 | 1.54 MB |
>= 26.31 MB
java.lang.String | 377,327 | 8.64 MB |
>= 25.11 MB
java.util.HashMap$Node[] | 41,292 | 5.56 MB |
>= 24.98 MB
java.util.HashMap | 22,951 | 1.05 MB |
>= 24.38 MB
java.util.concurrent.ConcurrentHashMap$Node | 125,723 | 3.84 MB |
>= 23.15 MB
java.util.ArrayList | 29,540 | 0.68 MB |
>= 22.96 MB
java.util.HashMap$Node | 467,433 | 14.26 MB |
>= 19.48 MB
org.postgresql.core.v3.QueryExecutorImpl | 819 | 0.17 MB |
>= 18.77 MB
org.postgresql.jdbc.TypeInfoCache | 819 | 0.07 MB |
>= 18.36 MB
java.util.zip.ZipFile$Source | 437 | 0.03 MB |
>= 17.49 MB
----------------------------------------------------------------------------------------
PgConnection 的对象高达819个,占用38MB的空间,随着时间的增长还会越来越多
查看持有PgConnection对象的引用如下:
Class Name | Objects | Shallow Heap
-------------------------------------------------------------------
org.postgresql.jdbc.PgConnection | 819 | 0.10 MB
|- org.postgresql.jdbc.TypeInfoCache | 819 | 0.07 MB
|- org.postgresql.jdbc.PgPreparedStatement| 457 | 0.05 MB
|- java.lang.ref.Finalizer | 819 | 0.03 MB
|- com.zaxxer.hikari.pool.PoolEntry | 10 | 0.00 MB
'- Total: 4 entries | |
-------------------------------------------------------------------
从上可以看出,819个PgConnection处于未关闭,对象一直未释放
修改如下:
`spring:
datasource:
hikari:
maximum-pool-size: 20 # 限制最大连接数
minimum-idle: 5 # 最小空闲连接
idle-timeout: 60000 # 空闲 60s 回收
max-lifetime: 120000 # 连接最长存活 120s (保留)
connection-timeout: 30000 # 获取连接超时 30s
leak-detection-threshold: 5000 # ⚠️ 泄漏检测 5s (之前是 60s,建议 5s)
connection-test-query: SELECT 1 # 连接测试查询
`
添加以上配置之后,连接池PgConnection对象个数稳定下来,内存利用率稳定下来
### Expected Behavior
_No response_
### Steps To Reproduce
_No response_
### Environment
```markdown
HertzBeat version(s):1.8.0
```
### Debug logs
_No response_
### Anything else?
_No response_
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail:
notifications-unsubscr...@hertzbeat.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@hertzbeat.apache.org
For additional commands, e-mail: notifications-h...@hertzbeat.apache.org