by Fred Cooper
Today’s mobile notebooks have battery lives of 8 hours or more, and can be connected to the Internet through a cellular GPRS connection one moment and through an 802.11 wireless access point the next. Software architects can no longer assume that the environment in which their applications run is static. The world of mobility is here and that means power, processor speeds, network availability, security, and bandwidth are all subject to change without notice. Software must be designed to best take advantage of what resources are available, when they are available. The mobile notebook is becoming the target platform for application development. This paper focuses on adapting an application’s network usage to make the best use of available bandwidth. I’ll demonstrate simple techniques to measure the available network throughput to determine if it is adequate for your application’s changing needs. Moreover, to ensure needed data is available to the user as quickly as possible, I will share techniques to organize data transmissions with mobile network policies.
This paper discusses how to adjust an application’s network usage to take advantage of the network bandwidth available. It does not cover detecting network connections, active network adapters, or adapter type or speed all of which were covered in my previous paper “Implementing Network Detection for Mobility”.
At the heart of adapting software to its mobile environment is mobile policy management. Mobile policy management defines which data is most important, least important, which can be cached locally, which should be transmitted, when, and on which types and speeds of networks. In short, mobile policy management determines how an application reacts to its mobile environment.
This can be as simple as using an algorithm that decides to use a local database when a network connection is less than 100Kbps and a network database when the connection is 100 Kbps or greater. Such an algorithm would work well for certain types of applications without a lot of data to exchange and no security concerns. However, applications with more demanding networking needs require sophisticated policy management algorithms.
Architecting for mobility does not lend itself well to one solution that can meet needs of all applications. There are many factors that must be considered when architecting a mobile application. For example, the more data your application needs to transfer in a short period of time, the greater the need to intelligently manage those transmissions to adjust to the available bandwidth.
In most products, it makes sense to localize the mobile policy management into a single object or component. Due to time constraints, developers often intermix the policy code (the code that decides what data to send, how much, in what order, and when) with the network transport code which is simply responsible for sending and receiving the data. Separating the policy code from the network transport code will make it easier to increase the sophistication of the mobile policy management over time. In the initial version of an application, for example, all the mobile policies may be hard-coded into the business logic; in a subsequent release some policies may be configurable by the user. Localizing policy management in your code also makes it easier to take advantage of any system-wide mobile policy management services that may, in the future, be produced by various software vendors.
In an application where a large amount of data needs to be shipped in a small period of time, data prioritization is essential. If the network connection is slow, it is important to get the data that is needed immediately by the user across the network first. You want to avoid your application’s own data from artificially becoming a barrier to the application’s ability to respond to the user. For example, in a simple email application, the first priority of data is to send the subject lines of the new messages to the email application, followed by the full text of the message the user is currently poised to read first. You don’t want the application to be in a position where it has to wait for the full text of email messages, or even worse, file attachments of messages the user isn’t currently viewing to be received before it can display the text of the message the user is actively attempting to view. By sending less relevant data first, followed by key data required by the application to respond to the user, an application can create a blockage of data that directly impacts the perceived performance of the application.
There are two ways to avoid this blockage: first is to properly prioritize your data. The priority of the data is a policy decision, and should be made by the policy manager. Key points to consider when setting data priority:
The second technique to avoid a data blockage is to design the transport layer to be packetized and support multiple tasks. To be more specific, the transport layer while transferring data across the network for one record must be flexible enough to put a current record on hold, transfer data from a higher priority record, and then resume transferring data from the original record once the higher priority data is transferred. And this must be completed without resending any data that was previously transferred. This type of architecture allows the policy manager to better respond to the user’s needs. For example, if the user views a record that is not available locally, the transfer of the record is immediately started; however, before the transfer is complete, the user switches the view to a different record that is also not available locally. Then the transfer of the first record should be put on hold, while the transfer of the actively viewed record is processed. Once the actively viewed record is transferred, the transfer of the original record may be completed.
To make the best use of the available network bandwidth, we must avoid consuming network bandwidth with unnecessary data. There are four things I would like to focus on in regard to minimizing data: (1) offline data stores; (2) differencing; (3) restarts; and (4) compression.
Not all networks are created equal. Some have shared bandwidth, while others have dedicated bandwidth. Some permit a high level of security while others do not. Some cost $4 a megabyte while others have unlimited usage. The mobile policy manager detects the type of network that is being used for the network connection and decides how, if at all, the application will make use of that network.
Below are network attributes that affect mobile policy:
With the right information available to your mobile policy manager, it can take that information and determine what the application will do in certain situations. Once again, there is no single solution to mobile policy management, so exactly what your application does is dependent on the data that needs to be transmitted. If, for example, a large amount of data needs to be transmitted in a short period of time, the policy manager must have a solution for low bandwidth connections. That solution should specify what data won’t be transmitted in low bandwidth situations. An online database application can reduce the number of database records that are synched to only the accounts assigned to a specific user or accessed in the last 15 days on low bandwidth connections. It could exchange only text based data on low bandwidth connections and full blob data on higher bandwidth connections.
Combinations of the network attributes may factor together to make up part of your mobile network policy. For example, if the connection is wireless and a VPN is not available, don’t exchange network data—use the offline data store instead.
Power is the final resource the mobile policy manager needs to help manage. When running on battery power, an application needs to be aware of how much power remains and what can be done to conserve it. An application can conserve power by accessing the hard disk or CD ROM less frequently, doing less computations, thus allowing the CPU to switch to a low power mode, and transmitting less data over a wireless connection, thus allowing the wireless network adapter to switch to a low power mode. The mobile policy manager in the application should make intelligent decisions to reduce power consumption when possible. It also needs to know how to respond when power is running low to ensure that local data stores are saved and network connections are terminated.
There are various methods for estimating the available network bandwidth of a connection. For mobility, it is important to remain focused on the level of accuracy your mobile policy manager requires to adjust the data usage of your application. To measure the available bandwidth of a network, it is necessary to inject probing traffic into the network and therefore degrade the network’s performance. So the first step in detecting available network bandwidth for mobility, is determining when it is actually necessary. For example, dial-up network connections are typically limited by the speed of the modem—when the modem connects, its connection speed is reported by the interface. Hence, when the policy manager detects a modem connection it doesn’t need to measure the network bandwidth.
On wired and wireless LAN networks, the bottleneck is less likely to be the network adapter, and more likely to be the available bandwidth of the network. In this case, we send probe packets across the network to determine if the available bandwidth is adequate. Once again, focus on the level of accuracy your mobile policy manager requires. For most mobile application purposes, it is not necessary to determine the maximum available bandwidth of a network, but rather if the network can meet a minimum need. The point being, that to determine the maximum available bandwidth the probe packets will have to exceed the available bandwidth of a router or switch on the path, which impacts everyone on the network. If your mobile policy manager would respond the same way if the available bandwidth were 1 Mbps or 1 Gbps, it is not necessary to consume all 1 Gbps of available bandwidth of a network to prove it is adequate. Also keep in mind the usage model of your application. If you are designing client software that will appear on hundreds of desktops in a corporate environment, IT departments would be unwilling to deploy software for which each client periodically consumed all their available network bandwidth. So if you expect multiple copies of your application to be running in the same network environment, you’ll want to be conscious of how your application impacts overall network performance.
To that end, let’s review a few approaches to determine if the available bandwidth is adequate for the application’s needs.
First, the basics: If I send a stream of UDP packets from one end point to the other, by simply recording the time when the first packet is received and the time when the last packet is received, I can compute throughput by dividing the bytes received by the number of seconds it took to receive them. Notice that this approach does not reveal the total available bandwidth of the network. To know if we’ve exceeded the available bandwidth, we look at the end-to-end delivery times. When the probe stream exceeds the available bandwidth, the network will start to queue the packets. A queued packet takes longer to reach the end point than a non-queued packet. If we send UDP packets at a rate that exceeds the available bandwidth, not only will it result in packet queuing, but the queue will grow with each successive packet. Therefore the overall end-to-end delivery time for each successive packet will increase as well. If we are not exceeding the available bandwidth, the end-to-end delivery time for each packet will be roughly the same for each packet. So to determine if we’ve exceeded the available bandwidth, all we need to add is some time information to the packets. The information we really need to know is when the packet was sent from the source computer and when did it arrived on the remote system in relation to the other packets in the stream. The clock starts when the first packet of the probe stream is received on the remote system. Contained in that first packet is information that tells the remote system how much time should be between packets. The remote system compares this intended arrival time of the second packet to the actual arrival time of the second packet. The difference between the two is recorded. If stream is below the available bandwidth, the difference between the intended separation of the packets and the actual received separation will remain relatively flat. However, if the probe stream exceeds the bandwidth of the network, the packets will be queued, and as more packets are queued, the difference between their intended arrival time and their actual arrival time grows. So if we have exceeded the available network bandwidth, the difference will, on average, continue to grow.
The above approach works well if you are trying to measure available network bandwidth for UDP packets; however TCP/IP is an entirely different beast. As a reliable transport protocol, TCP typically has its own buffers on both sending and receiving systems, a return channel of ACK packets, and the ability to share bandwidth with other TCP connections. For example, a network that is saturated with a single TCP connection, you would probably expect that the available bandwidth on this network is zero. However, because TCP shares the transport, ½ of the bandwidth may be available to a new TCP connection.
Since TCP has a return channel of ACK packets, its throughput is typically dependent of the Round-Trip Time (RTT) as well as the start up time of TCP. Different implementations of TCP implementations may also dramatically affect the transfer capacity of the network.
With TCP we are unable to control the exact content of packets, the rate at which packets are sent, and if they get resent. The typical method for determining available bandwidth of a single TCP connection is to set a timer before transferring or receiving data, stop the timer when the transfer is complete and compute the throughput by dividing the number of bytes transferred by the number of seconds required to transfer them. To avoid wasting perfectly good network bandwidth, send data you wanted to transfer anyway. Once the transfer is complete, the mobile policy manager will have a better understanding of the available network bandwidth, and can determine to what extent it will continue to use the network connection.
Available with this paper is a sample application, UDPNetSample which demonstrates the UDP method of measuring network bandwidth. To detect network bandwidth, the sample application must be running on both ends of the network connection. Choose a sample application on either end of the network connection and enter the IP address of the other system running the sample application, then press the Connect button. This allows the application to test that the remote address is accessible. Once connected, in the edit box at the bottom of the dialog, enter the speed in mega bits per second that you would like to test.
This sample application links to a library, INetBWUdp, which has a simple API for requesting network bandwidth. It is in this library, INetBWUdp, where the network bandwidth detection is accomplished. The simple API is defined in the INetBWApi.h file, where each function and its parameters are described. Here is a summary of some of the functions in this API:
The source code to this library is also included, where the main class CSocketMgr handles all the packets exchanged as well as the actual test measurements.
The key functions in CSocketMgr are:
UDPTestBandwidth: This function, given a suggested bandwidth, determines the size, number and frequency of packets to send to the remote system, constructs the packets, and sends them at the determined rate.
HandleTestPacket: This function is called on the remote system each time a test packet sent by UDPTestBandwidth is received. This function simply records several key statistical elements as the packets are received, such as: total number of packets received, total number of bytes received, time of first packet received, did this packet take longer to transmit than previous packets?
TestComplete: This function is called when the last packet of the test is received, or the test has timed out, to complete the test. This function evaluates the data accumulated during the test, computes the results, and sends them back to the source system.
Good mobilized applications make the best of the available network resources. For your application to best respond to the ever changing mobile world, incorporate a mobile policy manager that can decide how your software will respond to various mobile conditions. This policy manager assures that the data is transferred in the right priority order and pares it down for lower bandwidth connections. It decides when to use certain network connections and when to use a local data store. It can decide when it needs to determine the available network bandwidth and when an adapter interface speed is adequate. The algorithms described in this paper will assist you in developing code to determine the available network bandwidth and incorporating mobile policy management into your own applications.
Implementing Network Detection for Mobility
Download the code samples mentioned in this paper
Windows* WM_POWERBROADCAST Messages in a Mobile Environment
WinSock Applications for Mobile Environment