aspose file tools*
The moose likes Tomcat and the fly likes Tomcat NIO configuration in server.xml does not improve concurrent behaviour Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Tomcat NIO configuration in server.xml does not improve concurrent behaviour" Watch "Tomcat NIO configuration in server.xml does not improve concurrent behaviour" New topic
Author

Tomcat NIO configuration in server.xml does not improve concurrent behaviour

Gautham Reddy
Greenhorn

Joined: Jul 17, 2007
Posts: 5
Hi,

I am trying to check the performance and concurrent behaviour of tomcat with nio configurations and comparing with the default setting of tomcat

I have configured tomcat for nio capabilities in server.xml as follows by adding nioprotocol.

<Connector port="8080"
protocol="org.apache.coyote.http11.Http11NioProtocol" maxThreads="150"
connectionTimeout="20000" redirectPort="8443" />


in server.xml where as the default protocol was

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

Here is the code

server.xml
-----------------------------------------------------------------------------------------------------------------------------------
<?xml version='1.0' encoding='utf-8'?>

<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<Listener className="org.apache.catalina.core.JasperListener" />
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />

<GlobalNamingResources>
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>

<Service name="Catalina">

<!--
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
-->

<Connector port="8080"
protocol="org.apache.coyote.http11.Http11NioProtocol" maxThreads="150"
connectionTimeout="20000" redirectPort="8443" />


<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>

<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">

</Host>
</Engine>
</Service>
</Server>

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Here is the simple servlet TestServlet.java
--------------------------------------------------------------------------------------------




import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Servlet implementation class TestServlet
*/
public class TestServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#HttpServlet()
*/
public TestServlet() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
System.out.println("<============ IN WebTest TestServlet doGet()=============>"+request.getHeader("URN"));
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
System.out.println("<============ IN WebTest TestServlet doPost()=============>"+request.getHeader("URN"));

response.setHeader("header", "header");
}

}

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Now the httpclient class HttpRequets10000.java to connect to the TestServlet

--------------------------------------------------------------------------------------------



import java.io.IOException;


import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;




public class HttpRequets10000 {

/**
* @param args
* @throws IOException
* @throws ClientProtocolException
*/
public static void main(String[] args) throws IOException {



try {
long beginTime = System.currentTimeMillis();
for (int i = 0; i < 5000; i++) {

MultiThreadedHttpConnectionManager connectionManager =
new MultiThreadedHttpConnectionManager();
HttpClient client = new HttpClient(connectionManager);

// and then from inside some thread executing a method
PostMethod get = new PostMethod("http://localhost:8080/WebTest/TestServlet");
get.setRequestHeader("URN", "urn"+i);
try {
client.executeMethod(get);
// print response to stdout
System.out.println(get.getResponseBodyAsStream());
} finally {
// be sure the connection is released back to the connection
// manager
get.releaseConnection();
}
}
long endTime = System.currentTimeMillis();
System.out.println("time taken ="+(endTime-beginTime));

} catch (Exception e) {
System.err.println("<============ error ============>"+e.getMessage());
e.printStackTrace();
// TODO: handle exception
}



}

}

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


I am getting "java.net.BindException: Address already in use: connect" exception in HttpRequets1000.java after around 3900 httprequests with or without tomcat nio configurations in server.xml.

I dont see the real benefit of using nio in tomcat with these results. Am i missing something here to get the desired nio behaviour in Tomcat?


Thanks
Kees Jan Koster
JavaMonitor Support
Rancher

Joined: Mar 31, 2009
Posts: 251
    
    5
Dear Gautham,

So because your hand-cratfted load test code craps out and you conclude that this must be because Tomcat cannot handle the load? I am not sure I follow your logic.

For starters, if you want to load Tomcat, use one of the many, many load testing tools available on-line (Grinder, Siege, jmeter, etc). That way, you can be sure that you have a solid test harness.


Java-monitor, JVM monitoring made easy <- right here on Java Ranch
James Ward
Ranch Hand

Joined: Apr 27, 2003
Posts: 263
Shouldn't your TestServlet servlet be implementing CometProcessor ?
As per: http://tomcat.apache.org/tomcat-6.0-doc/aio.html
toby bao
Greenhorn

Joined: Dec 03, 2013
Posts: 1
you can see this :
http://www.baselogic.com/blog/system-administration/solved-java-net-bindexception-address-use-connect-issue-windows/
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12682
    
    5
Seems to me if you want to test NIO, your test case should do a large volume of IO. Otherwise, all the other stuff going on in a servlet environment will totally dominate the response time.

Bill

Java Resources at www.wbrogden.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tomcat NIO configuration in server.xml does not improve concurrent behaviour
 
Similar Threads
server.xml:has to do anything with database access pools
Tomcat port error
Changing the default port number for Apache Tomcat 6.0.26
How to change default port of Apache Tomcat?
Unicode convert problem with Jboss in Linux