Thursday, June 22, 2006

Asynchronous Servlet

WebLogic 9.1 has introduced Asynchronous servlet. WebLogic 9.1 AbstractAsyncServlet implementation can prevent hung threads by decoupling response from incoming request and timing out unresponsive requests.

How it is different from regular HTTP Servlet ?
Regular HTTP servlet accepts request and delivers response back with same WebLogic execute thread.
Execute thread can become stuck due to non responsive external process or internal deadlock.

Figure 1 Regular HTTP Servlet











*Click on image to see larger image.

AbstractAsyncServlet allows to decouple response from the request by executing response in different thread.
http://e-docs.bea.com/wls/docs92/webapp/progservlet.html#wp179418


Figure 2 AbstractAsyncServlet - Request/Response Decoupling














*Click on image to see larger image

If BackEnd processing object can not return response before configured time out interval it will execute doTimeout() and return response back with desired message.


Figure 3 AbstractAsyncServlet with timeout.















*Click on image to see larger image


How Request can be decoupled from Response ?

AbstractAsyncServlet itself doesn’t implement decoupling logic, However it provides hooks to and timer implementation to facilitate decoupling.

Decouling can be achieved using the WebLogic timer implementation. i.e TimerListener in doRequest() method.

TimerListener thread can invoke notify() on AbstractAsyncServlet to trigger delivery of the response.

AbstractAsyncServlet Benefit

It is very common to decouple web front request from long running backend process using JMS/MDB in cases where processing results are not required to send back immediatly in response.

AbstractAsyncServlet can decouple client request from long running backend process while allowing deliver results in response at the end of processing.
Key advantage of AbstractAsyncServlet is request time out in case of unresponsive back end processing.


AbstractAsyncServlet Limitation

WebLogic timer implementation allocates thread from default execute queue to process response. After time-out response thread continues execute for stale request and it is not released back to thread pool. This behavior can lead to thread exhaustion.

Above limitation can be addressed if it is possible to assign response thread to a dedicated custom WorkManager/ExecuteQueue potentially through WebLogic timer implementation.