Batch calls Problem in Ajax Hi,
ASP.NET AJAX has a feature in the CTP release (and previous releases) which allows batching multiple requests into one request. It works transparently, you won't notice anything, nor would you need to write any special code. Once you turn on the Batch feature, all web service calls made within a duration gets batched into one call. Thus it saves roundtrip time and total response time.
The actual response time might be reduced, but the perceived delay is higher. If three web service calls are batched, the first call does not finish first. All three calls finish at the same time. If you are doing some UI updates upon completion of each WS call, it does not happen one by one. All of the calls complete in one shot and then the UI gets updated in one shot. As a result, you do not see incremental updates on the UI, instead a long delay before the UI updates. If any of the calls, say the third call downloads a lot of data, the user sees nothing happening until all three calls complete. So, the duration of the first call becomes nearly the duration of the sum of all three calls. Although the actual total duration is reduced, the perceived duration is higher. Batch calls are handy when each call is transmitting a small amount of data. Thus three small calls get executed in one roundtrip.
Let's work on a scenario where three calls are made one by one. Here's how the calls actually get executed.
The second call takes a little bit time to reach the server because the first call is eating up the bandwidth. For the same reason, it takes longer to download. Browsers open two simultaneous connections to the server. So at a time, only two calls are made. Once the second/first call completes, the third call is made.
When these three calls are batched into one:
Here the total download time is reduced (if IIS compression is enabled), and there's only one network latency overhead. All three calls get executed on the server in one shot, and the combined response is downloaded in one call. But to the user, the perceived speed is slower because all the UI update happens after the entire batch call completes. The total duration the batch call will take to complete will always be higher than that for two calls. Moreover, if you do a lot of UI updates one after another, Internet Explorer freezes for a while, giving the user a bad impression. Sometimes, expensive updates on the UI makes the browser screen go blank and white. But Firefox and Opera does not have this problem.
Batch calls have some advantages too. The total download time is less than that for downloading individual call responses because if you use gzip compression in IIS, the total result is compressed instead of individually compressing each result. So, generally, a batch call is better for small calls. But if a call is going to send a large amount of data or is going to return, say, 20KB of response, then it's better not to use batch. Another problem with batch call is, say two calls are very small but the third call is quite big, and if these three calls get batched, the smaller calls are going to suffer from the long delay due to the third larger call.
thnx... |