Hi,
You can use SL4J framework to "lazily" log messages. Better yet, use
parameterized log messages to boost performance.
For eg -
Object entry = new SomeObject();
logger.debug("The entry is {}.", entry);
The message will be constructed and logged only if the logging is
enabled. More useful information can be found at [1].
[1] http://www.slf4j.org/faq.html#logging_performance
On Tue, Sep 2, 2014 at 9:11 PM, Sagara Gunathunga <[email protected]> wrote:
>
>
>
> On Tue, Sep 2, 2014 at 3:06 PM, Tharindu Edirisinghe <[email protected]>
> wrote:
>>
>> Hi,
>>
>> I'm going through the identity.provider source and found a possible
>> performance issue. (However this has to be verified with some tool like
>> JProfiler)
>>
>>
>>
>> turing/components/identity/org.wso2.carbon.identity.provider/4.2.2/src/main/java/org/wso2/carbon/identity/provider/openid/cache/OpenIDAssociationCache.java
>>
>>
>> /**
>> * Add the entry to the cache.
>> *
>> * @param association
>> */
>> public void addToCache(Association association) {
>> if (log.isDebugEnabled()) {
>> log.debug("Trying to add to cache.");
>> }
>> if (association != null && association.getHandle() != null) {
>> OpenIDIdentityCacheKey cacheKey = new
>> OpenIDIdentityCacheKey(0, association.getHandle());
>> OpenIDIdentityCacheEntry cacheEntry =
>> new
>> OpenIDIdentityCacheEntry(association.getType(),
>>
>> association.getMacKey(),
>>
>> association.getExpiry());
>> associationCache.addToCache(cacheKey, cacheEntry);
>> if (log.isDebugEnabled()) {
>> log.debug("New entry is added to cache : " +
>> association.getHandle());
>> }
>> }
>> }
>>
>>
>> The addToCache method is frequently called when creating OpenID
>> associations. Every time a new association is created, it checks two times
>> whether the debug log is enabled (shown in red above) by calling
>> isDebugEnabled() method. (Assuming that the method call is costly than
>> reading a local boolean variable)
>>
>> My suggestion is since the enabling or disabling the debug log is not
>> happening during the runtime of the server, we keep a boolean variable
>> inside the OpenIDAssociationCache class and assign value to that in the
>> constructor of the class. Then each time the addToCache method is called, it
>> will check that boolean value instead of always calling the
>> log.isDebugEnabled() method.
>>
>> Any thoughts ??
>
>
> +1 you could use a boolean variable in above code and eliminate duplicate
> isDebugEnabled() calls.
>
> BTW unless you call toString() method or String concatenations you can avoid
> isDebugEnabled() calls when logging String constants.
>
> e.g - log.debug("Trying to add to cache.");
>
> Thanks !
>
>
>>
>> --
>>
>> Thanks & Best Regards,
>>
>> Tharindu Edirisinghe
>> Software Engineer
>> WSO2 Inc
>> email : [email protected]
>> mobile : +94 775 181586
>> www: :http://wso2.com
>> lean . enterprise . middleware
>>
>>
>>
>> _______________________________________________
>> Architecture mailing list
>> [email protected]
>> https://mail.wso2.org/cgi-bin/mailman/listinfo/architecture
>>
>
>
>
> --
> Sagara Gunathunga
>
> Senior Technical Lead; WSO2, Inc.; http://wso2.com
> V.P Apache Web Services; http://ws.apache.org/
> Linkedin; http://www.linkedin.com/in/ssagara
> Blog ; http://ssagara.blogspot.com
>
>
> _______________________________________________
> Architecture mailing list
> [email protected]
> https://mail.wso2.org/cgi-bin/mailman/listinfo/architecture
>
--
Akila Ravihansa Perera
Software Engineer, WSO2
Committer & PMC Member, Apache Stratos
Blog: http://ravihansa3000.blogspot.com
_______________________________________________
Architecture mailing list
[email protected]
https://mail.wso2.org/cgi-bin/mailman/listinfo/architecture