8.2. Coping with Limited Bandwidth
If our distributed application is bandwidth-limited in one of these ways, then our system needs to have a way to monitor our data feeds, and manage the bandwidth usage of the system. Monitoring data throughput is a way to detect changes in the runtime environment of the system, and managing bandwidth is a way to react to these changes. It's not sufficient to say "what you get is what you get"; we need to find out what bandwidth is available and optimize the way we use it.
8.2.1. Monitoring Bandwidth
You typically need to monitor the data flowing in and out of a local agent in terms of both raw and real data throughput. Raw data is fed into and out of the system at the socket or stream level. Below this level, the data is handled on the network, using the appropriate protocol. Raw data transmitted over the network may be compressed or otherwise encoded, and may require decoding before being usable as "real" data. A bandwidth-limited system needs to be capable of monitoring raw data throughput in order to respond to network variability (bandwidth fluctuations, loss of service, etc.). It must also monitor real data throughput in order to pick up on major fluctuations in its net bandwidth usage and local resources like CPU availability, while maintaining a certain performance level. How to measure performance depends on the application, but will typically be a function of responsiveness, relative rate of data delivery to the user, etc.
8.2.2. Managing Bandwidth
With bandwidth monitoring in place, a system can start managing its network resources in order to satisfy the application's requirements. A multimedia presentation with an audio track typically wants to ensure that the real input rate of audio samples into the local audio device is always greater than or equal to the playback rate, in order to avoid interruptions. An interactive chat client may want to balance input and output rates so that a user typing a response can see another chat user's response if they are sending a response at the same time.
In addition to managing bandwidth and local resources to support the type of data being processed, it is also possible to manage the nature of the data itself in order to match the bandwidth and local resource profile. When designing the distributed system, for example, the encoding format of the transmitted data should be chosen carefully to match both the expected bandwidth and local resource capabilities. Choosing data encoding schemes for limited bandwidth applications often involves a trade-off between these two resource types. If we strictly optimize for bandwidth, then we will use the encoding scheme that offers the best compression ratio (for low-bandwidth situations), or the most robustness in terms of lost data (for lossy network situations), or an effective combination when the network is both low in bandwidth and lossy. However, highly compressed data typically requires more CPU resources to encode and decode, especially if these operations have to occur in real time. If the application needs to run on hosts with limited CPU speed, you must also take the processing requirements into account when choosing an encoding scheme.
8.2.3. Levels of Monitoring and Management
Several network-level protocols that support monitoring and managing real-time data transmission have been proposed and are in use in various capacities. Perhaps the most widely accepted protocol suite is the Real-Time Protocol (RTP) and the Real-Time Control Protocol (RTCP), which is currently an IETF draft standard. RTP provides a protocol layered on top of a baseline network transport layer like TCP, with header information capable of providing data timing and ordering statistics. RTCP is meant to provide basic bandwidth management functions for RTP applications. Major vendors like Microsoft and Netscape have announced support for RTP and RTCP in various umbrella protocols, but an interface to RTP and RTCP has not yet been offered for the Java environment.
At the application level, distributed systems can monitor the arrival and departure times of data transmitted over InputStreams and OutputStreams, and use these measurements to estimate the raw throughput rate they are achieving. Real data throughput rates can also be estimated by putting timestamps on data before encoding or after decoding. These measurements can then be used to make runtime decisions about resource allocation.
Copyright © 2001 O'Reilly & Associates. All rights reserved.