File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes Why is Tomcat 5.5 handling requests one-at-a time? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Why is Tomcat 5.5 handling requests one-at-a time?" Watch "Why is Tomcat 5.5 handling requests one-at-a time?" New topic
Author

Why is Tomcat 5.5 handling requests one-at-a time?

Jerome Mrozak
Greenhorn

Joined: Feb 10, 2006
Posts: 13
In brief, my Tomcat installation appears to be serializing user requests, even though I am using thread pooling.

I examine the user requests (the GET calls) through Lambda Probe. There are multiple IPs asking for salesOrder.jsp. You can see that the first IP is (slowly -- perhaps a modem?) getting its data. There are other IPs asking for salesOrder.jsp but they have no data transfer going on. This continues until the first IP finishes. Then the other IPs get data transfer.

My system is Red Hat Enterprise Linux 2, running kernel 2.4.9. Tomcat is running on Sun Java 1.4.2, using Tomcat 5.5.7. The page is fronted by Apache 2, using a (misconfigured?) JK2 adapter.

When I examine the compiled JSP page, salesOrder_jsp.java, I see the page implements SingleThreadModel. But my pool says I have a lot of threads for TP-Processor, HTTP-8080-Processor. Lambda Probe says that sometimes these threads get used by my web site, and sometimes are just pooled (unused).

The problem I'm trying to solve is that my web site gets real slow sometimes and I restart Tomcat to fix that. But I'm wondering if I have a narrow place (only one thread at a time) being run, and if I can fix it.

Thanks for help,
Jerome.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12675
    
    5
Is this application doing database access? Could that be the bottleneck?
Is there any good reason for using SingleThreadModel?
Bill


Java Resources at www.wbrogden.com
Jerome Mrozak
Greenhorn

Joined: Feb 10, 2006
Posts: 13
Q: Is there a good reason for doing SingleThreadModel?
A: I don't know. But this is what you get by default when you let Tomcat compile its pages at runtime. I don't see a config setting for telling Tomcat to use, or not use, this interface.

Q: Am I doing database access?
A: I apologize in advance for the lengthy code section, but I feel it is hard to explain matters without it.
My users get to salesOrder.jsp by clicking on a link that directly requests the JSP. There is no MVC overhead at the current time. The page should begin, display the "just into salesOrder.jsp" message, wait for DB access and eventually emit HTML for the caller.
When things seem locked-up, what I am experiencing is no responses to client browsers and the log file has no messages like "just into...". It seems like the pages *ought* to be entered because they were directly called, but that the pages don't ever get to the log.info() call.

Top bit of salesOrder_java.jsp (slightly edited):

package org.apache.jsp;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import java.io.*;
import java.text.*;
import java.util.*;
import org.apache.log4j.*;
import com.halo.data.*;
[snip]
import com.halo.util.*;

public final class salesOrder_jsp extends org.apache.jasper.runtime.HttpJspBase
implements org.apache.jasper.runtime.JspSourceDependent,
SingleThreadModel {

private static String CONTEXTPATH = com.halo.data.PortalGlobalInformation.CONTEXTPATH;
private static SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy");
private static SimpleDateFormat tf = new SimpleDateFormat("HH:mm:ss");
private static DecimalFormat numberFormatTwoDigit = StringUtility.getCurrencyFormat();

private static java.util.Vector _jspx_dependants;

static {
_jspx_dependants = new java.util.Vector(4);
_jspx_dependants.add("/trafficCop.jsp");
_jspx_dependants.add("/navigateRights.jsp");
_jspx_dependants.add("/cacheControl.jsp");
_jspx_dependants.add("/star.css");
}

public java.util.List getDependants() { return _jspx_dependants; }

public void _jspService(HttpServletRequest request, HttpServletResponse response)
throws java.io.IOException, ServletException {
JspFactory _jspxFactory = null;
PageContext pageContext = null;
HttpSession session = null;
ServletContext application = null;
ServletConfig config = null;
JspWriter out = null;
Object page = this;
JspWriter _jspx_out = null;
PageContext _jspx_page_context = null;

try {
_jspxFactory = JspFactory.getDefaultFactory();
response.setContentType("text/html");
pageContext = _jspxFactory.getPageContext(this, request, response, "error.jsp", true, 8192, true);
_jspx_page_context = pageContext;
application = pageContext.getServletContext();
config = pageContext.getServletConfig();
session = pageContext.getSession();
out = pageContext.getOut();
_jspx_out = out;

out.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\r\n");
out.write(" \r\n");
{
if(!com.halo.util.HttpUtility.isSessionActive(session)) {
response.sendRedirect(com.halo.data.PortalGlobalInformation.CONTEXTPATH + "Login.jsp?timedout=true");
return;
}
}
out.write(" \r\n");
{
if(!com.halo.util.HttpUtility.canViewPage(request, getServletContext())) {
response.sendRedirect(com.halo.data.PortalGlobalInformation.CONTEXTPATH + "noRights.jsp");
return;
}
}
out.write(" \r\n");
response.setHeader("pragma", "no-cache");
response.setHeader("Cache-control", "no-cache, no-store, must-revalidate");
response.setHeader("Expires", "01 Apr 1995 01:10:10 GMT");
out.write(" \r\n");

Logger log = Logger.getLogger("salesOrder.jsp");
DB_User currentUser = (DB_User) session.getAttribute("currentUser");
log.info("for timing debug, user " + currentUser.getName() + ", just into salesOrder.jsp");
// *** The log.info() text never appears in the log.

[snip]
HttpUtility.java:
public static boolean isSessionActive(HttpSession session) {
return(session.getAttribute("currentUser") != null && session.getAttribute("currentSalesPsn") != null);
}

public static boolean canViewPage(HttpServletRequest request, ServletContext sc) {
HttpSession session = request.getSession();
DB_User currentSalesPsn = (DB_User) session.getAttribute("currentSalesPsn");
return (currentSalesPsn == null) ? false : HttpUtility.hasRight(sc, currentSalesPsn.getRoleId(),
DB_Rights.NAVIGATE_RIGHT, request.getServletPath());
}

public static boolean hasRight(ServletContext sc, String role_id, String right_code, String scope) {
boolean retval = false;
[snip]
// omitted code searches arrays stored in "sc" to see if user is allowed into this JSP.
return retval;
}
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12675
    
    5
Does the JSP page directive have isThreadSafe="false" ? If so that is what is forcing creation of a SingleThreadModel servlet and preventing multiple requests from being handled by the same instance "at one time."
The default is supposed to be "true" - SingleThreadModel is deprecated in the latest Servlet API. Much better to isolate code that must be synchronized.
Bill
[ July 13, 2006: Message edited by: William Brogden ]
Jerome Mrozak
Greenhorn

Joined: Feb 10, 2006
Posts: 13
This implies that Tomcat is creating and using only a single instance of salesOrder_jsp.java. There is speculation that JSP containers create multiple instances, so that SingleThreadModel wouldn't hurt.

I will examine the effects of changing the 'isThreadSafe' property.

Thank you very much.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Jerome Mrozak:
This implies that Tomcat is creating and using only a single instance of salesOrder_jsp.java. There is speculation that JSP containers create multiple instances, so that SingleThreadModel wouldn't hurt.

I will examine the effects of changing the 'isThreadSafe' property.

Thank you very much.


Tomcat does create a thread pool of servlets when SingleThreadModel is employed.
Are the com.halo packages yours or third party libraries?
I'm wondering if one of the methods being called by this JSP is synchronized; causing requests to queue up. If this is the case, you'll see similar behaviour even after switching from SingleThreadModel.

Also, A Javaranch tip:

If you are going to post more than a line or two of your code, wrap that
code in a set of UBB Code tags.
Doing so will help to preserve your code's indenting, making it easier to read.
If it is easier to read, more people will actaully read it and you will
stand a better chance of getting help with your question.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Jerome Mrozak
Greenhorn

Joined: Feb 10, 2006
Posts: 13
Thanks for replying. I will use the code tag in the future.

After doing a global search, I see that the only places I have the keyword 'synchronized' is when handling DB connection pool issues. The business of getting into my salesOrder.jsp page doesn't involve a DB connection, so I think that is not the issue here.

The com.halo.* stuff is company-specific stuff. The important parts of this I extracted in the code sample.
Jerome Mrozak
Greenhorn

Joined: Feb 10, 2006
Posts: 13
In determinng if I can set isThreadSafe=true, is a compiled Struts-enabled JSP file thread-safe? When I examine the generated salesOrder_jsp.java file I see a lot of pool references:



I don't see on the web any reference to this pool, or its methods, being thread-safe. I *suppose* it is, but can't guarantee it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why is Tomcat 5.5 handling requests one-at-a time?
 
Similar Threads
configuration / security problem
*** Which one do you think is BETTER ??? ***
Using Java as opposed to another language where performance counts
spawning a daemon thread on Tomcat startup
WebServer's process management