tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "许明" <hsum...@qq.com>
Subject why only 2 requests for async request can raise from a end-point?
Date Mon, 29 Jun 2015 09:08:00 GMT
Hi, 

I am trying to bench async servlet, tomcat7 and tomcat8, now it's seems I can only start 2
request from a end-point.


I make a simple tool, start 100 request same time, each request has own session, and write
a simple async servlet, which pasted in the bottom of this mail.


It's the result:


06-29 16:28:52 622 INFO  (Test.java:35)- test serve 1
06-29 16:28:52 622 INFO  (Test.java:35)- test serve 2
06-29 16:29:02 633 DEBUG (Test.java:54)- timout and  print
06-29 16:29:02 637 DEBUG (Test.java:54)- timout and  print
06-29 16:29:02 642 INFO  (Test.java:35)- test serve 3
06-29 16:29:02 677 INFO  (Test.java:35)- test serve 4
06-29 16:29:12 647 DEBUG (Test.java:54)- timout and  print
06-29 16:29:12 650 INFO  (Test.java:35)- test serve 5
06-29 16:29:12 682 INFO  (Test.java:35)- test serve 6
....


i have test this on tomcat7 and tomcat8 in windows and linux(ubuntu), and test it in browser
manually.


Best Regards


===================
my Test servlet:
===================


package com.botao.im;


import java.io.IOException;
import java.io.PrintWriter;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;


import javax.servlet.AsyncContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.apache.log4j.Logger;


/**
 * Servlet implementation class Test
 */
@WebServlet(asyncSupported = true, name = "test", urlPatterns = { "/test" })
public class Test extends HttpServlet {
	private static final long serialVersionUID = 1L;


	private static Logger logger = Logger.getLogger(Test.class);
	
	private static ScheduledExecutorService es =  Executors.newSingleThreadScheduledExecutor();
	
	private static int counter = 0;
	
	protected void doGet(HttpServletRequest request, final HttpServletResponse response) throws
ServletException, IOException {
	
			logger.info("test serve " + (++counter ));
			final AsyncContext context = request.startAsync();


			context.start(new Runnable() {
				
				@Override
				public void run() {
					context.setTimeout(1000000);					
					 es.schedule(new Runnable(){


						@Override
						public void run() {
							response.setContentType("text/plain");
							PrintWriter out;
							try {
								out = response.getWriter();
								out.print("hello");
								out.flush();
								context.complete();
								logger.debug("timout and  print");
							} catch (IOException e) {
							}
						
						}
						 
					 }, 10, TimeUnit.SECONDS);
				}
			});
			
	}




}
Mime
  • Unnamed multipart/alternative (inline, 8-Bit, 0 bytes)
View raw message