[
https://issues.apache.org/jira/browse/DIRMINA-445?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12529886
]
Emmanuel Lecharny commented on DIRMINA-445:
-------------------------------------------
I have looked at the trunk. It seems that SessionLog has been moved to a
IoSessionLogger, but Vincent proposal is still valid.
The code looks like :
public static void trace(Logger log, IoSession session, String message) {
if (log.isTraceEnabled()) {
log.trace(String.valueOf(getPrefix(session)) + message);
}
}
Two remarks there :
1) using the Marker mechanism, it could be written like :
public static void trace(Logger log, IoSession session, String message) {
if (log.isTraceEnabled()) {
log.trace( "{} {}", getPrefix(session), message); // No need to
call the String.valueOf( getPrefix()), getprefix already returns a String
}
}
2) As soon as you encapsulate the log method in such a wrapper, then suddenly
you can pass an Object instead of a String, and transform the methods to looks
like :
public static void trace(Logger log, IoSession session, Object message) {
if (log.isTraceEnabled()) {
log.trace( "{} {}", getPrefix(session), message);
}
}
It comes at no cost, and will save a lot of CPU
Regarding 1.1.2, we have almost the same code :
public static void debug(IoSession session, String message) {
Logger log = getLogger(session);
if (log.isDebugEnabled()) {
log.debug(String.valueOf(session.getAttribute(PREFIX)) + message);
}
}
which can be written like :
public static void debug(IoSession session, Object message) {
Logger log = getLogger(session);
if (log.isDebugEnabled()) {
log.debug( "{} {}", session.getAttribute(PREFIX), message); // No
need either to call String.valueOf(), slf4j will handle the object itself.
}
}
> SessionLog improvement
> ----------------------
>
> Key: DIRMINA-445
> URL: https://issues.apache.org/jira/browse/DIRMINA-445
> Project: MINA
> Issue Type: Improvement
> Components: Core
> Affects Versions: 1.1.3, 2.0.0-M1
> Environment: Use Object instead of String inSessionLog logging method
> to allow for massive perfs improvement on production running instances (when
> logs filtering is used).
> Reporter: vincent bourdaraud
> Priority: Minor
>
> SessionLog.debug(IoSession,String), info(IoSession,String),
> warn(IoSession,String) and error(IoSession,String) should be changed to
> SessionLog.debug(IoSession,Object), info(IoSession,Object),
> warn(IoSession,Object) and error(IoSession,Object), as in log4j.
> The reason for this is that if passing Objects instead of String allow to
> delay the composition of the logging message (.toString() call) until really
> needed and that could greatly improve performance. This kind of feature is
> needed to build SW able to be turned in debug while in production using
> NDC/MDC filters (using log4j e.g.).
> Some code snippet the illustrate this:
> public void messageReceived(IoSession session, Object o) throws Exception
> {
> MyProtocolRequest req = (MyProtocolRequest) o;
> NDC.put(req.getUserId());
> SessionLog.debug(session, new RequestDumper(req));
> NDC.pop();
> }
>
> class RequestDumper()
> {
> public RequestDumper(MyProtocolRequest req)
> {
> this.req = req;
> }
>
> public String toString()
> {
> return req.toString();
> }
>
> private MyProtocolRequest req;
> }
> In that snippet, the cost of converting MyProtocolRequest to a String is not
> paied when SessionLog.debug() is called, but when the underlying logging
> framework needs the string for logging. The perf improvement could be massive
> if the underlying protocol uses some kind of filtering to filter-out most
> debug logs; in that example, the logging framework would be configured to
> filter-in only logs with a NDC set to a specific user.
> With this feature, we could enable debug in production for some few users
> only, without killing the overall performances.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.