• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Gautham Reddy
Greenhorn
Posts: 5
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 251
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
James Ward
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shouldn't your TestServlet servlet be implementing CometProcessor ?
As per: http://tomcat.apache.org/tomcat-6.0-doc/aio.html
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic