Thursday, February 28, 2008

load balance & fail-over with tomcat using apache proxy_ajp_module proxy_balancer_module

In the past, we have been using mod_jk as the connector to front apache http server for tomcat, it does load balance and fail-over nicely. Now apache has modules such as proxy_ajp_module and proxy_balancer_module that would serve the same purpose, but with simpler configuration. Below is the VirtualHost config in apache httpd:
NameVirtualHost *:8080
<VirtualHost *:8080>

<Location /balancer-manager>
SetHandler balancer-manager
</Location>

<Proxy balancer://ajpCluster>
BalancerMember ajp://localhost:8109 route=jvm1
BalancerMember ajp://localhost:8209 route=jvm2
</Proxy>

ProxyPass /balancer-manager !
ProxyPass / balancer://ajpCluster/ stickysession=JSESSIONID nofailover=On
</VirtualHost>

On the tomcat end there are a few things needs to be changed in server.xml:

Uncomment the section where it defines the AJP connector and change the port number:
<!– Define an AJP 1.3 Connector on port 8009 –->
<Connector port=”8109″ enableLookups=”false” redirectPort=”18443″ protocol=”AJP/1.3″ />

This part I totally forgot which took me a while to realize that I did not define the jvmRoute name in tomcat. This would be appended to the JSESSIONID cookie so it knows which tomcat to route to:
<Engine name=”Catalina” defaultHost=”localhost” jvmRoute=”jvm1">

Now when you hit http://hostname:8080/ it hits the apache httpd server and it would route you to the least loaded tomcat that is up running.
http://hostname:8080/balancer-manager
would show you the status of the load balancer and tomcat servers.

I have tested this worked well with JIRA.

Tuesday, February 26, 2008

revert back to an old revision in subversion

Someone restructured the code and directories then committed into the repository, but it was discovered what has been done is on the wrong track. Now we want to revert back to a revision before all these bad changes. The changes were between revisions 2737 - 2738, we wanted to go back to revision 2736 to start over, issue the command:

svn merge -rHEAD:2736 .

Now we can start over from revision 2736, commit it into the repository as revision 2739, the missing files and directories would be copies from revision 2736.

Friday, February 15, 2008

sort process on linux by memory/cpu usage

sort by memory usage:
ps -eo pid,ppid,rss,vsize,pcpu,pmem,cmd -ww –sort=pmem

sorty by cpu usage:
ps -eo pid,ppid,rss,vsize,pcpu,pmem,cmd -ww –sort=pcpu

Thursday, February 14, 2008

response headers that prevents browser to cache JSP

// Set to expire far in the past.response.setHeader(”Expires”, “Tue, 23 May 1995 12:00:00 GMT”);
// Set standard HTTP/1.1 no-cache headers.response.setHeader(”Cache-Control”, “no-store, no-cache, must-revalidate”);
// Set IE extended HTTP/1.1 no-cache headersresponse.addHeader(”Cache-Control”, “post-check=0, pre-check=0″);
// Set standard HTTP/1.0 no-cache header.response.setHeader(”Pragma”, “no-cache”);