idea 修改配置,模拟分析 OOM

背景

写了个功能,线上一跑,pod 就重启了。估计是 OOM 了。

调查过程

于是本地准备模拟一下场景,分析下大对象。

修改运行时参数

-Xms200m
-Xmx200m
-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=/Users/chenchuxin/Documents/dgw/km-deployer-service/

这样可以得到 hprof 文件,idea 就可以分析

很容易发现大对象是 bson 文件,看起来是 1000 一批还是太多了,因为是 document 对象,所以可能存储很多内容。

调下批次处理数量就可以了。

Calcite支持benchmark函数

需求

想支持下 https://dev.mysql.com/doc/refman/8.4/en/information-functions.html#function_benchmark

1
2
3
4
5
6
7
mysql> SELECT BENCHMARK(1000000,AES_ENCRYPT('hello','goodbye'));
+---------------------------------------------------+
| BENCHMARK(1000000,AES_ENCRYPT('hello','goodbye')) |
+---------------------------------------------------+
|                                                 0 |
+---------------------------------------------------+
1 row in set (4.74 sec)

得先了解下嵌套函数的实现

又折腾了一周 polardbx 的启动,终于能启动了。

试一下 它是否能支持。 嗯,暂不支持,不过错误提示的挺好的。

mysql> SELECT BENCHMARK(1000000,AES_ENCRYPT('hello','goodbye'));
ERROR 4998 (HY000): [1900df69ae400000][192.168.200.77:8527][sharding_db]ERR-CODE: [PXC-4998][ERR_NOT_SUPPORT] function BENCHMARK not support yet!

接下来做些啥呢? 看看嵌套函数咋实现的。

本地测试可以运行,但是环境上 mockito java.lang.VerifyError

问题描述

org.mockito.exceptions.base.MockitoException: 

Mockito cannot mock this class: class com.digiwin.athena.datamap.service.inner.DataMapPickService.

If you're not sure why you're getting this error, please open an issue on GitHub.


Java               : 1.8
JVM vendor name    : Oracle Corporation
JVM vendor version : 25.11-b03
JVM name           : Java HotSpot(TM) 64-Bit Server VM
JVM version        : 1.8.0_11-b12
JVM info           : mixed mode
OS name            : Mac OS X
OS version         : 10.16


You are seeing this disclaimer because Mockito is configured to create inlined mocks.
You can learn about inline mocks and their limitations under item #39 of the Mockito class javadoc.

Underlying exception : java.lang.IllegalArgumentException: Could not create type
Caused by: java.lang.IllegalArgumentException: Could not create type
Caused by: java.lang.VerifyError

一直报错,但是本地却没有。

单元测试单独运行ok, mvn test 却失败

现象

单独运行单元测试都是通过的,但是 mvn test 一起运行时就报错了。

调查过程

开启 debug 模式,执行mvn test 时,发现 threadLocal 对象的值来自于其它 case.

由于同一个模块执行 test 时是单线程串行的。所以应该是 treadLocal 泄漏。

从而发现是测试用例没有清理 treadLocal.

增加清理逻辑后正常。

Slf4j 控制台日志丢失问题调查

今天本地调试项目发现长日志始终打不出来,然后 debug 发现, flush 之后,原来打出来一半的日志就会消失

1
2
3
4
5
6
protected void directEncodeEvent(final LogEvent event) {
    getLayout().encode(event, manager);
    if (this.immediateFlush || event.isEndOfBatch()) {
        manager.flush();
    }
}

然后我发现超过 2048 之后,会分批输出,奇怪的事为啥输出一半,后一半继续输出之后,就消失了呢。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
static void encodeText(final CharsetEncoder charsetEncoder, final CharBuffer charBuf, final ByteBuffer byteBuf,
        final StringBuilder text, final ByteBufferDestination destination)
        throws CharacterCodingException {
    charsetEncoder.reset();
    if (text.length() > charBuf.capacity()) {
        encodeChunkedText(charsetEncoder, charBuf, byteBuf, text, destination);
        return;
    }
    charBuf.clear();
    text.getChars(0, text.length(), charBuf.array(), charBuf.arrayOffset());
    charBuf.limit(text.length());
    final CoderResult result = charsetEncoder.encode(charBuf, byteBuf, true);
    writeEncodedText(charsetEncoder, charBuf, byteBuf, destination, result);
}

最后发现这里有个折叠标志,原来超过之后 idea 自动折叠了。。哈哈一个小乌龙