[英]Akka - GC overhead limit exceeded
I am getting a: 我得到:
java.lang.OutOfMemoryError: GC overhead limit exceeded
at java.nio.HeapByteBuffer.asReadOnlyBuffer(HeapByteBuffer.java:117)
at akka.util.ByteString$ByteString1.asByteBuffer(ByteString.scala:153)
at akka.util.ByteString$ByteString1C.asByteBuffer(ByteString.scala:104)
With this Akka code: 使用此Akka代码:
var buffer = ByteString.apply()
val MsgSize = 208
protected def onMessage(rawMsg: ByteString) = {
// Messages under the size are not processed in while loop. This line appends them
// to be processed when enough data is present.
buffer ++= rawMsg
// Process multiple messages if present.
while (buffer.size >= MsgSize) {
// Process each message, leaves remainder for later processing.
}
// To prevent the buffer from growing uncontrollably.
// It is possible that at some point this fails to run for a long time
// which could cause the out of memory exception.
if (buffer.isEmpty) buffer = ByteString.apply()
}
It looks like the concatenation may be the problem. 看起来串联可能是问题所在。 Is this the right way to do this? 这是正确的方法吗?
Turns out we have to do something like this: 原来我们必须做这样的事情:
while (buffer.size >= MsgSize) {
val (msg, rem) = buffer.splitAt(MsgSize)
// Process msg
// buffer is now what remains
buffer = rem
}
Because reading from the buffer does not increment a position. 因为从缓冲区读取不会增加位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.