Low-Level Communication Optimizations
There are number of optimizations you can make to the low-level communication infrastructure. These optimizations can be difficult to implement, and it is usually easier to buy these types of optimizations than to build them.
Compression
Where the distributed application is transferring large amounts of data over a network, the communications layer can be optimized to support compression of the data transfers. In order to minimize compression overhead for small data transfers, the compression mechanism should have a filter size below which compression is not used for data packets.
The JDK documentation includes an extended example of installing a compression layer in the RMI communications layer (the main documentation index page leads to RMI documentation under the “Enterprise Features” heading). The following code illustrates a simple example of adding compression into a communications layer. The bold type shows the extra code required:
void writeTransfer(byte[] transferbuffer, int offset, int len)
{
if (len <= 0)
return;
int newlen = compress(transferbuffer, offset, len);
communicationSocket.write(len);
communicationSocket.write(newlen);
communicationSocket.write(transferbuffer, offset, newlen);
communicationSocket.flush( );
}
byte[] readTransfer( )
throws IOException
{
int len = communicationSocket.read( );
if (len <= 0)
throw new IOException("blah blah");
int newlen = communicationSocket.read( );
if (newlen <= 0)
throw new IOException("blah ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access