Java Akka-超出GC开销限制
我得到一个:Java Akka-超出GC开销限制,java,scala,akka,Java,Scala,Akka,我得到一个: 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
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)
使用此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()
}
看起来连接可能是问题所在。这是正确的方法吗?事实证明我们必须这样做:
while (buffer.size >= MsgSize) {
val (msg, rem) = buffer.splitAt(MsgSize)
// Process msg
// buffer is now what remains
buffer = rem
}
因为从缓冲区读取不会增加位置。缓冲区是否会在某个点减少或清空?可能是环路?在我看来,这不是保证。您是否可以使用更严格定义的消息类型,而不影响字节?即使有注释,我也看不到if(buffer.isEmpty)buffer=ByteString.apply()的意义。此外,您还说您处理多条消息(如果存在)。缓冲区中不应存在多条消息的情况。您可以自行处理rawMsg,处理后,下一个将从邮箱中提取。@AleksandarStojadinovic,请稍候。缓冲区没有正确清空。