Java Reference
In-Depth Information
should be minimized, whether by compression, or pruning of documents, or some other tech-
nique.
On the other hand, setting up a network call in the first place has measurable overhead.
When designing a network interface, the interface should be “coarse”—that is, it is better to
return lots of data in one call, so as to minimize the total number of network calls that the cli-
ent must make. That principle is at odds with the objective to reduce the amount of data be-
ing exchanged; some balance must be struck here.
This balance can be observed if we test the average response time for a RESTful web service
based on the stock history class. The service can be designed to return either just the basic
data (high, low, average, and standard deviation) for the period, or to return the basic data
plus all the individual daily data points.
If it is known ahead of time how the client will use the data, then it is easy to know exactly
which data to return. However, that isn't always possible. In this example, say that the client
requests a 5-year history for a stock, and the client application will initially just present a
summary of that data to the user. What happens if the user wants to drill into that data and
look at individual daily points? Should all the data be returned to the client in the first call, so
that no further network calls are needed to drill into the data? Should only the summary data
be returned, and if the user wants to drill into the data for year 3, the program must make an-
other call to get the daily data for that year? Should that second call get the entire 5-year his-
tory even though the user right now is only looking at the third year?
To figure out a strategy here, consider the time for returning all the data compared to the time
for making multiple network calls. Table 10-14 shows the average response time for retriev-
ing data under various scenarios:
1. The client requests 1 year of data.
2. The client requests a 1-year summary.
3. The client requests 5 years of data.
4. The client makes two requests: a summary request, and a drill-down request for a spe-
cific date.
5. The client makes 10 requests: a summary request plus 9 drill-down requests for a spe-
cific date.
Search WWH ::




Custom Search