Skip to content

Commit 341a992

Browse files
committed
test
1 parent 10720a3 commit 341a992

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

class/src/main/java/jvm/oom/DirectMemoryGlibcGrow.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ public static void fragment() throws InterruptedException {
2929
List<ByteBuffer> buffers = new ArrayList<>();
3030
// Allocate large buffers and release them to see memory impact
3131
for (int i = 0; i < 50; i++) {
32-
int delta = ThreadLocalRandom.current().nextInt(100) + 33;
32+
// int delta = ThreadLocalRandom.current().nextInt(40) + 33;
33+
int delta = 37;
3334
System.out.print(delta + ", ");
3435
buffers.add(ByteBuffer.allocateDirect(delta * 1024 * 1024)); // 100 MB each
3536

@@ -46,7 +47,7 @@ public static void loopFragment() throws InterruptedException {
4647
Runnable run = () -> {
4748
try {
4849
for (int i = 0; i < 1000; i++) {
49-
TimeUnit.MILLISECONDS.sleep(2000 + ThreadLocalRandom.current().nextInt(1000));
50+
TimeUnit.MILLISECONDS.sleep(1000 + ThreadLocalRandom.current().nextInt(1000));
5051
fragment();
5152
System.out.println("loop " + i);
5253
}
@@ -56,6 +57,7 @@ public static void loopFragment() throws InterruptedException {
5657
};
5758
xo.submit(run);
5859
xo.submit(run);
60+
xo.submit(run);
5961

6062
}
6163

class/src/test/java/jvm/oom/DirectMemoryGlibcGrowTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ public void testFragment() throws Exception {
1818
* pmap -x 259296 | jvm-tool -s 查看块数量
1919
* 注意,IDE启动,则是使用全部的核心,最大thread arena数量是 cpu核数*8
2020
* 可复制IDE第一行命令,创建shell脚本,删除-agentlib:jdwp的参数,命令前添加 taskset -c 0,1 来限制CPU核心数,可以看到数量就变成17了 1+8*2, 1是 main arena
21+
* <p>
22+
* 替换为jemalloc export LD_PRELOAD=/usr/lib/libjemalloc.so,固定37M块并行分配的情况 两种malloc都是RSS内存在1-7G内存浮动,glibc可以看到17个arena
23+
* 所以这个测试场景不能充分展示 大对象导致 大量thread arena 占用
2124
*/
2225
@Test
2326
public void testLoopFragment() throws Exception {

0 commit comments

Comments
 (0)