DWR Call batching
Published by peter August 30th, 2006 in ajax, java.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:
JavaScript:
-
function batchThreeCalls(){
-
DWREngine.beginBatch();
-
testbean.getOne(doOne);
-
testbean.getTwo(doTwo);
-
testbean.getThree(doThree);
-
DWREngine.endBatch();
-
}
Results in a single call, and a single response which is routed to the correct callbacks by DWR:
request
JavaScript:
-
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
response
JavaScript:
-
//#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#
More one batching can be found on the DWR site.




















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
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!
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?
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!
bet0r!
-andy