2

In my project I need to create a proxy server which will be able to shape traffic. The main issue is to have different queues with different priorities which will provide access to further servers.

My idea is to use Jetty with its asynchronous feature - Continuation. In Continuation there is option of suspending the request and releasing thread. Then my request can be queued.

My main concerns are around resources. What happens with requests in Jetty which are 'suspended'? Do they still have any threads attached? In my case quite many requests might be queued and method 'thread per request' from Tomcat is not good solution for me...

1 Answer 1

0

You might want to start with the org.eclipse.jetty.servlets.ProxyServlet, then look how to extend it, similar to the BalancerServlet and and go from there. It already has many async/continuation features you can start with.

Look at the public void service(ServletRequest req, ServletResponse res) method for how the Continuations are used.

4
  • Thank you very much for your answer. I've searched a little bit more and it turned out that the newest versions of Jetty relies on Servlet 3.0 implementation. It means that they use method startAsync which suspends execution of request, releases RequestThread and starts another WorkingThread. It can be seen in link. It doesn't solve my problem because I need to store requests for a while (and release threads). Generally I see that one option is event-driven approach like Netty framework.
    – tRun
    Jan 3, 2013 at 22:43
  • Continuations are supported for Servlet 3.0 async as well. Know that the HTTP Request is merely suspended and the thread processing it is returned to thread pool once the startAsync() is called, there can be [0..n] working threads to process it. (note that if 0 threads process it, the client will see a timeout) Jan 3, 2013 at 23:22
  • And here is the issue. HTTP request is suspended - this means that is given another thread which consumes resources. E.g. I would like to suspend/store 100 HTTP requests. Then it will consume 100 threads which are literally doing nothing - just waiting. I need to store those requests and not to consume so many resources.
    – tRun
    Jan 4, 2013 at 12:59
  • With Async there is not a 1::1 relationship of threads to requests. The model is far more complicated than that. Example: A servlet handling an incoming request that simply does startAsync() then returns from the doGet() will have a request with no thread belonging to it. Example 2: a servlet can do startAsync() then hand off the processing to a java.util.concurrent.ExecutorService with a fixed thread count and thousands of pending handlers in its queue. Don't get caught up in assumptions and premature optimizations now. Use it. learn it first, then plan. Jan 4, 2013 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.