views:

97

answers:

4

In general, is it better to have a web application make lots of calls to a web service getting smaller chunks of data back, or to have the web app make fewer calls and get larger chunks of data?

In particular, I'm building a Silverlight app that needs to get large amounts of data back from the server in response to a query created by a user. Each query could return anywhere from a few hundred records to a few thousand. Each record has around thirty fields of mostly decimal-type data. I've run into the situation before where the payload size of the response exceeded the maximum allowed by the service.

I'm wondering whether it's better (more efficient for the server/client/web service) to cut this payload vertically--getting all values for a single field with each call--or horizontally--getting batches of complete records with each call. Or does it matter?

+3  A: 

It definitely matters. You don't want the web service to be chatty - for small requests, you may well find the latency ends up being longer than the time taken to process the request. On the other hand, obviously you don't want to return data you don't need. There's a balance to be found, which usually involves the client being able to specify what they want from the server in a reasonably detailed fashion - or to be able to effectively send a "batch" of requests in one single web request.

Jon Skeet
Part of what I was worried about was that the frequency of web service calls could somehow bog down the server. But Countering that concern is the knowledge that the web service architecture is meant to handle lots of traffic. Since this website will never be a high-traffic site, I conclude that the only drawback to a chatty web service is the latency the user may experience. Is this correct?
Klay
@Klay: Well, I think "only drawback" is possibly overstating it - there may well be per-request overhead on the server and the client beyond just latency, but that may well be the biggest one.
Jon Skeet
A: 

I would say do something like paging (show X records at a time). This would result in "small" calls as the user would only request data as they need it. It really depends on your situation. Do they need to view through all the data at once or would only seeing small chunks of it at a time be okay?

Just remember: small chunks = less waiting for some data.

Bryan Denny
This app doesn't lend itself to paging, as I'm drawing thousands of points on a highly interactive map. I need to show all the points at once. And I can't use image-based map services for this, because they aren't interactive enough.
Klay
Maybe instead of paging your could limit the radius of points on the map? Think like how Google maps works. This is of course assuming you would be "zoomed in" on an area of the map.
Bryan Denny
Not to be unappreciative, but you're not addressing the question I asked. I know what paging is, and I've used it successfully elsewhere in the app. The issue is not how to minimize the amount of data being sent, but how best to send a large, atomic dataset.
Klay
+3  A: 

Getting a smaller dataset will mean the user will have to wait for less time; which is good.

But getting small datasets means he will have to wait more often.

One possibility would be to use a combination of both approaches, for example:

  • For the first request, only get a small dataset, to be able to display some informations faster
  • and, for the next requests, get bigger datasets, to make fewer HTTP requests
    • that way while those (a bit longer) requests take place, the user will already have something to read.
Pascal MARTIN
I like the notion of "perceived responsiveness" at work here.
Klay
+4  A: 

I have found, surprisingly, that hauling down two or even four times as much data as you need is almost always faster to doubling the number of calls in order to provide better filters.

I found that I can transfer 200K in the same time that I could issue one new request. Most fine-tuned requests wanted about 3K while course ones maybe wanted 50-100K.

If you exceed payload size, bump payload size or build a streaming CGI on the server. It's better that way.

Joshua