.toXML() Logging Overhead

Hi guys,

we have profiled our own plugin and discovered some performance issues in openfire and in the tinder library.

In both projects there are many log entries for packets. That is good, but on every call the packet.toXML() is executed, even if the log level is higher then the log method.

In our case the execution of .toXML() costs up to 80% of the execution time of handling presences.

as an example:

in the file:

tinder/AbstractComponent.java at master · igniterealtime/tinder · GitHub

there is the line:

log.trace("(serving component ‘{}’) Processing presence stanza: {}",getName(), presence.toXML());

Possible solution:

if (log.isTraceEnabled()){

  • log.trace("(serving component ‘{}’) Processing presence stanza: {}",getName(), presence.toXML());*

}

or better: just omit the .toXML(), so the toString() Method is called only when needed (GC: Packet - org.xmpp.packet.Packet (.java) - GrepCode Class Source )

log.trace("(serving component ‘{}’) Processing presence stanza: {}",getName(), presence);

Best Regards

Thanks for your suggestion. It’s a quite valid one. I’ve raised this issue to track it: [TINDER-71] Reduce logging overhead - IgniteRealtime JIRA

If you can spare the time, we’d love to accept a pull request!