tomcat Posts

[Weird Issue] Slow Database Query Which only Happen in Windows Server 2008 64Bit

Several days ago, i was asked by my friend to fix one of his weird issue. A same java webapp deployed on two different Operating System, Windows Server 2003 32bit and Windows Server 2008 64bit, gives two different performance. The webapp runs well on Windows Server 2003, while at the same time have a very poor performance on Windows Server 2008. Same identical infrastructure, the only differences is the Windows Server version.

Later i will show you how to fix this issue, but first let me show what the infrastructure looks like. Basically, it’s a three tier infrastructure, a load balancer, multiple webserver and database server. At first, i thought that the bottleneck is on network infrastructure, but the network guy says that there is nothing wrong on network’s monitoring.

After several days monitoring, i found out that the main culprit is Windows Server 2008. Somehow there are some issues on network outbound causing a very slow database queries.

So this is to fix it, first via netsh interface

netsh interface tcp set global rss=disabled
netsh interface tcp set global autotuning=disabled
netsh interface tcp set global chimney=disabled

netsh1

netsh2

Next is disabling QoS Packet Scheduler,
qos

And last is adding a TcpNoDelay variable in windows server’s regedit, which located at HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters
tcpnodelay

After i run those command and restart my machine, my application on Windows Server 2008 run smoothly.

Google+

Weird HTTP Error, HTTP Request Parameter Not Detected When Using JavaScript canvas.toDataURL and Base64 Ajax Post

I have a simple Java web application that use Ajax image upload using canvas.toDataURL and base64 encoder. Usually it run well, but I have a very weird error that happen intermittently. Somehow my application cannot detect any http request parameters that send by my Ajax requests. After I spend a while researching, it seems that this error only happen when uploading multiple big images.

At first I thought that it was my Java or JavaScript issue, but then I realized that this is an issue on my Application Server, which is Apache Tomcat. Its default value for maximum POST size is 2MB (2097152), and after I resize it, the error went away.

I add “maxPostSize” property on server.xml, to increase maximum POST size that Apache Tomcat can handle. In this example, i increase it into 20MB.

    <Connector connectionTimeout="20000" 
        port="8080" protocol="HTTP/1.1" 
        redirectPort="8443" maxPostSize="20971520"/>

;-)

Google+

How To Change Apache Tomcat’s Server Name

On this tutorial, i’ll show you how to change Apache Tomcat’s server name. This is the screenshot from a regular Apache Tomcat,

And with a simple configuration on server.xml,

 <Connector port="8080" protocol="HTTP/1.1"
         connectionTimeout="20000"
	 server="Why So Serious"
         redirectPort="8443" />

It will change my Tomcat’s server name into,

Not hard actually ;-)

Google+

A java.lang.IllegalArgumentException when Using SpringMVC @PathVariable

Another exception happened to me today while im deploying my application to Tomcat 7, somehow the error (again) never happen on my IDE. The error is related to Spring MVC’s @PathVariable. Below is the complete stacktrace for the error.

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: Name for argument type 1 not available, and parameter name information not found in class file either.
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894)
	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
	com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:119)
	com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:55)
	org.springframework.security.web.FilterChainProxy$VirtualFilterChain .doFilter(FilterChainProxy.java:330)
	org.springframework.security.web.access.intercept.FilterSecurityInterceptor .invoke(FilterSecurityInterceptor.java:118)
	org.springframework.security.web.access.intercept.FilterSecurityInterceptor .doFilter(FilterSecurityInterceptor.java:84)

And this is the suspected method which raise exception,

    @RequestMapping(value ="/baculsoft/news/view/{id}", method = RequestMethod.GET)
    public String newsView(ModelMap modelMap, 
                        @PathVariable String id) {
        modelMap.put("news", newsService.get(id);
        return "news/view";
    }

The workaround is actually simple, below is how to deal with it,

    @RequestMapping(value ="/baculsoft/news/view/{id}", method = RequestMethod.GET)
    public String newsView(ModelMap modelMap, 
                        @PathVariable("id") String id) {
        modelMap.put("news", newsService.get(id);
        return "news/view";
    }

Actually very simple workaround, but since i have hundreds of methods using @PathVariable, it’s not so simple anymore. And the weird thing is, the .war exported from Eclipse IDE run perfectly, only .war created from Netbeans that raise exception. I dont know why, but somehow Netbeans’ ant create a different war compared to Eclipse’s war file.

After sometimes googling, i found out that it happens due to javac’s debug parameter on Netbeans’ ant, changing “debug” default value into “on” on Netbeans’ build-impl.xml makes my war file run perfectly on Tomcat 7. Well i hope it hepled others, cheers (B)

Google+

How to Set %JAVA_HOME% Variable on Apache Tomcat’s Catalina Script

Usually im using Apache Tomcat’s catalina script to launch and start Apache Tomcat, but sometimes the script wont run because of not having JAVA_HOME variables on your OS environment variables or you cant add new environment variables due to lack of privileges.

So instead of adding JAVA_HOME variable into my OS, i set the JAVA_HOME on my catalina scripts. This is how i do it, i add this script on the top of catalina.bat file.

set JAVA_HOME=C:\Program Files (x86)\Java\jdk1.7.0_07

Note, there is no space before and after “=” sign.

Easy isnt it ;)

Google+