Reverse Ajax Load Monitors
DWR comes packaged with different server load monitors which help balance server load between multiple users. The type of monitor chosen will depend on your application's need.
Throttling Server Load Monitor
The Throttling Server Load Monitor at its basic level works by controlling the maximum number of currently connected threads and the maximum hits per second to the server. To control load this load monitor will adjust the time a connection is allowed to stay connected, and the time that the reverse ajax api will wait before connecting to the server again. By adjusting the connected time and the disconnected time the Thottling Server Load Monitor can help give users a better overall experience during times of heavy load.
Since it is inefficient to check load everytime a client requests a new connection, this server monitor runs a separate load management thread that will run at most once every 5 seconds while there are incoming connections. When no more incoming connections are being received the load monitor will simply shutdown and sleep until a new connection is requested. Note that the thread will verify load at least once per hour even if no connections are being received.
When the server is throttling connections there are three possible modes that the server could be in.
- Low Usage
- Server will accept and maintain all connections with the default connected and disconnected times.
- High Usage
- In high usage mode the server has reached the maximum connected thread limit and will impose a connected time of 49 second and a disconnected time of 1 second. After high usage has been reached the server will adjust the connected time and disconnected time in a linear fashion to lower server load, which in turn will cause end user response times to feel more and more sluggish based on the number of clients connected and the amount of data being sent and received.
- Digg Usage
- When the server is under extremely heavy load the thottling load monitor will switch to digg mode which decreases the connected time to 0 and increases the imposed disconnected time to 2 seconds. When the connected time is 0 clients are not allowed to maintain connections. This mode is reached once the linear adjustment of high usage mode hits the threshold of connected time equal to 1 second.
- Include an init parameter to the DWRServlet.
<servlet> <servlet-name>dwr-invoker</servlet-name> <display-name>DWR Servlet</display-name> <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class> <init-param> <param-name>activeReverseAjaxEnabled</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>org.directwebremoting.extend.ServerLoadMonitor</param-name> <param-value>org.directwebremoting.impl.ThrottlingServerLoadMonitor</param-value> </init-param> </servlet>
At this point DWR will now use the ThrottlingServerLoadMonitor to balance reverse ajax connections.