RemoteServer.handleRemoteRequestProtocol calls toString on every incoming message
When sending large messages between nodes, I noticed that the node receiving messages would consume lots ram. Digging through the code I noticed that some log.debug code in RemoteServer is forcing a toString on every incoming message. With large messages this is adds a significant memory and time overhead. The code in question can be found here: https://github.com/jboner/akka/blob/39783d/akka-remote/src/main/scala/remote/RemoteServer.scala#L500
Leave a comment
Turn off debug logging and then problem will disappear. It uses by-name-parameters so it won't be evaluated if debug is turned off.
Disassemble the method in question. You will find the following (taken from 0.10 - but master should be similar):
Notice at 15, toString is called on the request object prior to the debug call. The by-name only applies to the format variable not to any of the parameters. Please re-open.
// Method descriptor #238 (Lse/scalablesolutions/akka/remote/protocol/RemoteProtocol$RemoteRequestProtocol;Lorg/jboss/netty/channel/Channel;)Ljava/lang/Object;
// Stack: 5, Locals: 7
private java.lang.Object handleRemoteRequestProtocol(se.scalablesolutions.akka.remote.protocol.RemoteProtocol.RemoteRequestProtocol request, org.jboss.netty.channel.Channel channel);
0 aload_0 [this]
1 invokeinterface se.scalablesolutions.akka.util.Logging.log() : se.scalablesolutions.akka.util.Logger [96] [nargs: 1]
6 new se.scalablesolutions.akka.remote.RemoteServerHandler$$anonfun$handleRemoteRequestProtocol$1 [272]
9 dup
10 aload_0 [this]
11 invokespecial se.scalablesolutions.akka.remote.RemoteServerHandler$$anonfun$handleRemoteRequestProtocol$1(se.scalablesolutions.akka.remote.RemoteServerHandler) [273]
14 aload_1 [request]
15 invokevirtual se.scalablesolutions.akka.remote.protocol.RemoteProtocol$RemoteRequestProtocol.toString() : java.lang.String [274]
18 getstatic scala.Predef$.MODULE$ : scala.Predef. [114]
21 iconst_0
22 anewarray java.lang.Object [116]
25 invokevirtual scala.Predef$.genericWrapArray(java.lang.Object) : scala.collection.mutable.WrappedArray [120]
28 invokevirtual se.scalablesolutions.akka.util.Logger.debug(scala.Function0, java.lang.Object, scala.collection.Seq) : void [126]
Notice at 15, toString is called on the request object prior to the debug call. The by-name only applies to the format variable not to any of the parameters. Please re-open.
on 2010-11-12 04:37 *
By viktorklang
Assigned to set to viktorklang
Status changed from New to Accepted
Good catch, thanks for the debug session.
I'll switch that statement to log lazily so you can turn off the logging and not have the message toStringen.
I'll switch that statement to log lazily so you can turn off the logging and not have the message toStringen.