编年史:为什么忙碌的尾巴在旋转时会产生垃圾(没有什么可阅读的)?
我有一个忙碌的循环,其中尾巴人不断地试图从队列中阅读:
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 =
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:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已经捕获了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