Hello Everyone,

 

I am having an issue where tomcat 6.0.35 comet is not sending a response
when the host is under significant load. It is also sending the end
event which, as far as I understand, means the CometEvent is not being
closed. 

 

I am suspicious that this may be because the legacy code I am debugging
is using comet timeouts to handle rescheduling. When a request comes in
and there is no data immediately available our code sets
cometEvent.setTimeout(30000) and then attaches some attributes to the
event. 

 

I can log the response, it is there waiting to be sent, and the read
event which is triggering the response completes successfully. 

 

The problem only occurs when running on our prod and staging CentOS 5.4
but not on local CentOS 6.3 or Windows machines.

 

Any ideas on why the response and end event would be getting held up
under load?

 

Code below

 

Thank you,

Heath

 

public class MyCometProcessor extends HttpServlet implements
CometProcessor {

 

    @Override

    public void event(CometEvent cometEvent) throws IOException,
ServletException {

        HttpServletRequest request = cometEvent.getHttpServletRequest();

 

        try {

            if (cometEvent.getEventType() == CometEvent.EventType.BEGIN)
{

                                // do nothing

            }

            else if (cometEvent.getEventType() ==
CometEvent.EventType.READ) {

                new CometReadHandler(cometEvent).process();

            }

            else if (cometEvent.getEventType() ==
CometEvent.EventType.ERROR) {

                if (cometEvent.getEventSubType() ==
CometEvent.EventSubType.TIMEOUT) {

                    new CometTimeoutHandler(cometEvent).process();

                }

                cometEvent.close();

            }

            else if (cometEvent.getEventType() ==
CometEvent.EventType.END) {

                cometEvent.close();

            }

        } catch (Exception e) {

            try {

                cometEvent.close();

            } catch (Exception ignore) {}

            throw new ServletException(e);

        }

    }

}

 

 

public class CometReadHandler {

    private final CometEvent cometEvent;

 

    public CometReadHandler(CometEvent cometEvent) {

        if (cometEvent.getEventType() != CometEvent.EventType.READ) {

            throw new IllegalArgumentException(...);

        }

        this.cometEvent = cometEvent;

    }

 

    public void process() throws Exception {

        InputStream inStream;

        Element messageResponse;

        try {

            inStream =
cometEvent.getHttpServletRequest().getInputStream();

            messageResponse = generateMessage(inStream);

        } catch (Throwable thrown) {

                // log

            return;

        }

 

        if (messageResponse == null) {

            cometEvent.setTimeout(30000);

            cometEvent.getHttpServletRequest().setAttribute("key",
dataObject);

        } else {

            try {

                new MessageSender(cometEvent).send(messageResponse);

            } finally {

                try {

                    cometEvent.close();

                } catch (Exception ignore) {

                }

            }

        }

    }

}

 

 

public class CometTimeoutHandler {

    private final CometEvent cometEvent;

 

    public CometTimeoutHandler(CometEvent cometEvent) {

        if (cometEvent.getEventType() != CometEvent.EventType.END &&
cometEvent.getEventSubType() != CometEvent.EventSubType.TIMEOUT) {

            throw new IllegalArgumentException("");

        }

        this.cometEvent = cometEvent;

    }

    

    public void process() throws Exception {

                // generate message and send, message is generated and
logged and I see it in the logs

    }

}

 

public class MessageSender {

    private final CometEvent cometEvent;

 

    public MessageSender(CometEvent cometEvent) {

        this.cometEvent = cometEvent;

    }

 

    public void send(Element xmlResponse) throws IOException,
ServletException {

        cometEvent.getHttpServletResponse().setContentType("text/xml");

        PrintWriter writer =
cometEvent.getHttpServletResponse().getWriter();

       MessagingUtil.outputElement(xmlResponse, writer);

        writer.flush();

    }

}


______________________________________________________________________
This message, including any attachments, is confidential and contains 
information intended only for the person(s) named above. Any other 
distribution, copying or disclosure is strictly prohibited. If you are not the 
intended recipient or have received this message in error, please notify us 
immediately by reply email and permanently delete the original transmission 
from all of your systems and hard drives, including any attachments, without 
making a copy.

Reply via email to