You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by "Maarten Bosteels (JIRA)" <ji...@apache.org> on 2007/09/24 16:37:50 UTC

[jira] Commented: (DIRMINA-445) SessionLog improvement

    [ https://issues.apache.org/jira/browse/DIRMINA-445?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12529874 ] 

Maarten Bosteels commented on DIRMINA-445:
------------------------------------------

Some remarks:

* MINA uses the SLF4J API (not log4j) and for some reason SLF4J does not have the logger.debug(Object obj) API
   So while we could change the API of SessionLog, we would have to call toString() anyway
   (unless we would do the isDebugEnabled check in SessionLog)
   
* Have you looked at the MdcInjectionFilter ?
   IMHO it covers the functionality of SessionLog, with much more flexibility 

* SLF4J supports the elegant Marker mechanism, which you can use to avoid the expensive toString() call :
   logger.debug("message received: {}", new RequestDumper(req));
   => toString() will only be called when the LoggingEvent is actually generated

> 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.