S
S
satmurat2015-05-16 13:19:32
Java
satmurat, 2015-05-16 13:19:32

How to properly configure Jetty 9 embedded?

This is how I run Jetty embedded.

QueuedThreadPool threadPool = new QueuedThreadPool(50, 10);
        Server server = new Server(threadPool);
        ServerConnector connector = new ServerConnector(server);
        connector.setIdleTimeout(30000);
        connector.setPort(8000);

        ServletContextHandler context0 = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
        context0.setContextPath("/cameraImages");
        context0.addServlet(new ServletHolder(new MyServlet(this.images)), "/*");

        server.setHandler(context0);
        server.addConnector(connector);

        try {
            server.start();
            server.join();
        } catch (Exception e) {
            e.printStackTrace();
        }

The problem is that over time (somewhere in 5-6 hours) there will be a memory overflow when requests come from two nodeJS clients every 7 seconds. Memory analyzed, but did not really understand. The fact is that there were entries in the Response headers and apparently were not deleted. And when I tested it with Apache JMeter, there were no such problems, everything worked stably. What could be the problem? Maybe nodeJS has some specifics?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
satmurat, 2015-05-21
@satmurat

I can:

public class MyServlet extends HttpServlet {
    private final ConcurrentMap<Integer, String> images;
    private final static String RESPONSE_TYPE = "text/plain";
    private final static String ID_KEY = "id";
    private final static String JPEG_KEY = "jpeg";
    private final static Logger log = Logger.getLogger(MyServlet.class);
    public MyServlet(ConcurrentMap<Integer, String> images) {
        this.images = images;
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType(RESPONSE_TYPE);
        String img = null;
        ImagesToJSON itj = new ImagesToJSON();
        img = itj.toString(images);
        if (img == null) {
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
            return;
        }
       response.getWriter().println(img);
    }
}

The culprit turned out to be nodeJS. It sends "keep alive" in the request header, and after receiving the response, the connection is not closed. Each time nodeJS created a new client and held the connection.
I used jetty version 9.3.0.M1, that is, milestone, not release. The issue was fixed after updating the libraries to release 9.3.3.v20150827. It's not about "keep alive". Here's your carelessness.

N
Nikolai, 2015-05-21
@j_wayne

Can you attach MyServlet?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question