编年史:为什么忙碌的尾巴在旋转时会产生垃圾(没有什么可阅读的)?

发布于 2025-01-26 14:28:57 字数 1436 浏览 3 评论 0原文

我有一个忙碌的循环,其中尾巴人不断地试图从队列中阅读:

final Bytes<ByteBuffer> bbb = Bytes.elasticByteBuffer(MAX_SIZE, MAX_SIZE);

// Busy wait loop.
while (true) {
    tailer.readDocument(wire -> {
        wire.read().marshallable(m -> {
            m.read(DATA).bytes(bbb, true);
            long rcvAt = m.read(RCVAT).int64();

            System.out.println(rcvAt);
        });
    });
}

为什么即使没有排队没什么可阅读的,为什么此代码会产生垃圾?

相关的JVM标志: :maxheapsize = 64M

-Server -XX:initialheapsize =

64m -xx

GC日志充满了这样的日志:

...
[30.071s][info][gc     ] GC(1755) Pause Young (Normal) (G1 Evacuation Pause) 23M->6M(30M) 0.250ms
[30.084s][info][gc     ] GC(1756) Pause Young (Normal) (G1 Evacuation Pause) 23M->7M(30M) 0.386ms
[30.096s][info][gc     ] GC(1757) Pause Young (Normal) (G1 Evacuation Pause) 24M->7M(30M) 0.544ms
[30.109s][info][gc     ] GC(1758) Pause Young (Normal) (G1 Evacuation Pause) 24M->7M(30M) 0.759ms
[30.122s][info][gc     ] GC(1759) Pause Young (Normal) (G1 Evacuation Pause) 24M->7M(30M) 0.808ms
[30.135s][info][gc     ] GC(1760) Pause Young (Normal) (G1 Evacuation Pause) 24M->7M(30M) 0.937ms
...

I have a busy-waiting loop in which a tailer is constantly trying to read from a queue:

final Bytes<ByteBuffer> bbb = Bytes.elasticByteBuffer(MAX_SIZE, MAX_SIZE);

// Busy wait loop.
while (true) {
    tailer.readDocument(wire -> {
        wire.read().marshallable(m -> {
            m.read(DATA).bytes(bbb, true);
            long rcvAt = m.read(RCVAT).int64();

            System.out.println(rcvAt);
        });
    });
}

Why does this code generate garbage even when there is nothing to read from the queue?

Relevant JVM flags:
-server -XX:InitialHeapSize=64m -XX:MaxHeapSize=64m

GC logs and memory profile:

VisualVM
enter image description here

GC logs is flooded with logs like this:

...
[30.071s][info][gc     ] GC(1755) Pause Young (Normal) (G1 Evacuation Pause) 23M->6M(30M) 0.250ms
[30.084s][info][gc     ] GC(1756) Pause Young (Normal) (G1 Evacuation Pause) 23M->7M(30M) 0.386ms
[30.096s][info][gc     ] GC(1757) Pause Young (Normal) (G1 Evacuation Pause) 24M->7M(30M) 0.544ms
[30.109s][info][gc     ] GC(1758) Pause Young (Normal) (G1 Evacuation Pause) 24M->7M(30M) 0.759ms
[30.122s][info][gc     ] GC(1759) Pause Young (Normal) (G1 Evacuation Pause) 24M->7M(30M) 0.808ms
[30.135s][info][gc     ] GC(1760) Pause Young (Normal) (G1 Evacuation Pause) 24M->7M(30M) 0.937ms
...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

违心° 2025-02-02 14:28:57

您已经捕获了Lambda。他们对BBB有一个引用,因此在每个中间的关系中都会创建。
您可以将它们存储在循环外部的本地变量中,以避免每次创建它们。

我建议使用飞行记录器,因为它使用的垃圾较少来监视应用程序

You have capturing lambda. They hold a reference to the bbb and thus get created on every interation.
You can store them in local variables outside the loop to avoid them being created each time.

I suggest using Flight Recorder as it uses far less garbage to monitor the application

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文