HTTP Proxy: Handle requests concurrently

60 views
Skip to first unread message

petra

unread,
Sep 17, 2011, 12:05:55 PM9/17/11
to membrane...@googlegroups.com
Hi,

I'm using the Membrane Router API to use the Membrane Monitor as HTTP Proxy. I have written a custom interceptor to analyze and monitor SOAP traffic and all is working well. However, I'm currently performance testing the solution and when sending concurrent requests the response time is really bad. It seems that only one single interceptor instance is created and handles all received requests sequentially. Is there any way to let the proxy handle requests concurrently?

Best regards,
Petra

Shaan Jayaratna

unread,
Sep 19, 2011, 5:04:39 AM9/19/11
to membrane-monitor
Hi,

an interceptor is a singleton and therefore has only one instance. If
you need a per exchange lifecycle you can simulate this by using a
Map. The following example shows an interceptor that uses a thread-
safe map to save session data:

public class SessionDataInterceptor extends AbstractInterceptor {

private static Log log =
LogFactory.getLog(SessionDataInterceptor.class
.getName());

private Map<Exchange, Integer> sessions = new
ConcurrentHashMap<Exchange, Integer>();

@Override
public Outcome handleRequest(Exchange exc) throws Exception {
sessions.put(exc, new Random().nextInt());
return Outcome.CONTINUE;
}

@Override
public Outcome handleResponse(Exchange exc) throws Exception {
int session = sessions.get(exc);
log.info("session: " + session);
sessions.remove(session);
return Outcome.CONTINUE;
}

}

Alternatively you can store per exchange data in the exchange itself
using the following methods:

exc.setProperty(key, value)
exc.getProperty(key)

Please tell me if that solves your problem. If not can you describe
your scenario in more detail?

Kind Regards
Shaan

petra

unread,
Sep 19, 2011, 7:52:57 AM9/19/11
to membrane...@googlegroups.com
Hi,

the problem is not that I need to store per exchange data, but that the performance is really bad for concurrent requests. My interceptor analyzes the SOAP message and decides if it should update the endpoint or simply forward it. Because the logic for this decision is rather complex, it takes some time to complete. It works fine as long as there are only a few requests, however, if I try to load test the solution (for example with soapUI oder Apache JMeter) and send concurrent requests, the performance is really bad.

Is there no way to handle requests concurrently instead of one after another?

Best regards
Petra

Thomas Bayer

unread,
Sep 19, 2011, 8:46:46 AM9/19/11
to membrane-monitor
Hi Petra,

Membrane handles requests concurrently. It is optimized for this task.
The best result do you get using Membrane version 2.0.4 or 3.0.1 .
But older versions should also perform good. Interceptors are
singletons and are instanciated only once. That instance can handle
lots of concurrent threads but the interceptor must be implemented
thread-safe and it should be careful with synchronization. If your
logic is not thread-safe or must be synchronized you can use an
object pool in the interceptor that manages objects encapsulating not
threadsafe logic or logic that needs a lot of time to initialize.

Let me know if that doesn't fix your problem.If you don't mind you can
post your interceptor or the handle methods. We can also talk on the
phone. You can reach me at +49 228 55525760.

--
Thomas

petra

unread,
Sep 19, 2011, 1:31:40 PM9/19/11
to membrane...@googlegroups.com
Hi,

thanks for your response and the offered support. I was not aware that the interceptor had to be thread-safe. I will update my implementation to meet this requirement.

Best regards
Petra
Reply all
Reply to author
Forward
0 new messages