Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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

 
Gautham Reddy
Greenhorn
Posts: 5
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 251
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
toby bao
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Morning came much too soon and it brought along a friend named Margarita Hangover, and a tiny ad.
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic