Skip to main content

Posts

Showing posts from September, 2010

Python adding pid file

I have a thumbnail generator that launches multiple processes and the correct way to shut it down is to send kill -HUP to the parent process. To automate I had to write a pid file from python, it was a piece of cake def writePidFile(): pid = str(os.getpid()) f = open('thumbnail_rabbit_consumer.pid', 'w') f.write(pid) f.close()

Use Log5j to eliminate isDebugEnabled checks

we use log4j and the code is proliferated with if(logger.isDebugEnabled()) check to avoid string concatenation if the log level is INFO, but many developers forget to add this check and most of the time this problem is not noticed. Every penny counts when the system is under heavy pounding. I ran across Log5j and this solves this problem by delegating string interpolation to the log5j api which can discard the interpolation if log level is not met. From Log5j website in log4j: log . debug ( "This thing broke: " + foo + " due to bar" ); in log5j: log . debug ( "This thing broke: %s due to bar" , foo );

Disabling Tomcat session persistence across restart

Tomcat default standard manager preserves sessions across tomcat restart, we had a special requirement to disable this feature. The way to do this is to introduce a Manager tag with pathname="" as shown below in server.xml under context element <Context path="" docBase="ROOT" debug="0" privileged="true"> <Manager pathname="" /> ......... </Context>

Missing exception traces

This was an interesting issue. We were seeing exceptions in log with empty traces, this was happening even though we had done logger.error(e); or e.printStackTrace. Our CTO found out that aparently its some JVM optimization by sun (now oracle lol). From http://java.sun.com/j2se/1.5.0/relnotes.html he found <<< The compiler in the server VM now provides correct stack backtraces for all "cold" built-in exceptions. For performance purposes, when such an exception is thrown a few times, the method may be recompiled. After recompilation, the compiler may choose a faster tactic using preallocated exceptions that do not provide a stack trace. To disable completely the use of preallocated exceptions, use this new flag: -XX:-OmitStackTraceInFastThrow. >>> Kudos to him as we were thinking its some DWR library issue eating the trace.

Little annoyances in middle of important work

I get annoyed when I am in middle of some coding session and people ask same question that they had asked few days back. Seems like if you answer it for them then they wont put an effort to look for answer. Some of the questions people ask me are:  How do I signup a new account on this branch   How do i revert a changelist  How do I restart tomcat on QA env  I have noticed it that instead of asking the question on IM immediately if you wait 2 mins then they would probably for 90% of the times figured out the solution themselves. Another thing that has worked for me is to create a wiki page for common questions and solutions and refer them to the page.