DWR Call batching

To reduce load on my current project I had a look into reducing the number of requests fired at the application server. Many pages in the application trigger multiple DWR calls resulting in Tomcat generating heavy load on the servers.

One of the sollutions I came up with is batching DWR calls, which reduces the number of calls by combining multiple calls into single requests.

Simply start and end a batch and DWR handles it all! For example:

[js]
function batchThreeCalls(){
DWREngine.beginBatch();
testbean.getOne(doOne);
testbean.getTwo(doTwo);
testbean.getThree(doThree);
DWREngine.endBatch();
}
[/js]

Results in a single call, and a single response which is routed to the correct callbacks by DWR:

request
[js]
callCount=3
warningHandler=null
httpSessionId=EA9C0891376DE06E977B26CD729E59C8
scriptSessionId=B206674DE4A43F7E497882E9E3723F3D
page=/JRubyController/dwrtest.html
c0-scriptName=testbean
c0-methodName=getOne
c0-id=158_1156968086615
c1-scriptName=testbean
c1-methodName=getTwo
c1-id=1425_1156968086615
c2-scriptName=testbean
c2-methodName=getThree
c2-id=3057_1156968086615
[/js]
response
[js]
//#DWR-START#
DWREngine._handleResponse(’158_1156968086615′, “1″);
//#DWR-END#
//#DWR-START#
DWREngine._handleResponse(’1425_1156968086615′, “2″);
//#DWR-END#
//#DWR-START#
DWREngine._handleResponse(’3057_1156968086615′, “3″);
//#DWR-END#
[/js]

More one batching can be found on the DWR site.

This entry was posted in ajax, java. Bookmark the permalink.

5 Responses to DWR Call batching

  1. railsguru says:

    The site is dog slow :(

    I’m wondering if you guys didn’t go (way) overboard with Ajaxy stuff? I tend to shy away from Ajax these days and only use it when it really really really makes a difference in user experience (and not simply because Rails makes it easy to (ab)use)

    -andy

  2. peter says:

    At this point AJAX stuff didn’t seem to have caused the problems. The outdated database statistics, misconfigured caches, proxies and filters which we fixed today seem to have improved the performance drastically!

  3. erikvanoosten says:

    Did the DWR Call Batching reduce load as well?
    I can image it is still better to leave this in, it will reduce the number of connections, but can you actually see a performance gain?

  4. peter says:

    Well, we haven’t put the batching stuff into online yet… so, hard to say just now. If I have numbers I’ll let you know!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>