On this page:
Overview of Protocol Compression
Compression is an optional feature of the Ice protocol; whether it is used for a particular message is determined by several factors:
- Compression may not be supported on all platforms or in all language mappings.
- Compression can be used in a request or batch request only if the peer advertises the ability to accept compressed messages.
- For efficiency reasons, the Ice protocol engine does not compress messages smaller than 100 bytes.
A compliant implementation of the protocol is free to compress messages that are smaller than 100 bytes — the choice is up to the protocol implementation.
Compression is likely to improve performance only over lower-speed links, for which bandwidth is the overall limiting factor. Over high-speed LAN links, the CPU time spent on compressing and uncompressing messages is longer than the time it takes to just send the uncompressed data.
Encoding for Compressed Messages
If compression is used, the entire protocol message excluding the header is compressed using the bzip2 algorithm. The
messageSize member of the message header therefore reflects the size of the compressed message, including the uncompressed header, plus an additional four bytes.
compressionStatus field of the message header indicates whether a message is compressed and provides additional information, as shown in the table below.
Message is uncompressed. Client cannot accept compressed replies.
Request, Batch Request, Reply, Validate Connection, Close Connection
A client that does not support compression always uses this value. A client that supports compression sets the value to
Message is uncompressed. Client can accept compressed replies.
Request, Batch Request
A client uses this value if the endpoint via which the request is dispatched indicates that it supports compression, but the client has decided not to use compression for this particular request (presumably because the request is too small, so compression does not provide any saving).
Message is compressed.
Request, Batch Request, Reply
A client that supports compression sets this value only if the endpoint via which the request is dispatched indicates that it supports compression. A server uses this value for compressed replies.
The message body of a compressed request, batch request, or reply message is encoded by first writing the size of the uncompressed message (including its header) as a four-byte integer, followed by the compressed message body (excluding the header). It follows that the size of a compressed message is 14 bytes for the header, plus four bytes to record the size of the uncompressed message, plus the number of bytes occupied by the compressed message body. Writing the uncompressed message size prior to the body enables the receiver to allocate a buffer that is large enough to accomodate the uncompressed message body.
Compression Semantics for Clients
A client sends a compressed message if the following are true:
- The client-side run time supports compression
- The size of the uncompressed message is at least 100 bytes
- The proxy endpoint on which the message will be sent has the compression flag (
-zfor stringified endpoints) indicating that the server supports compression
If any of these criteria are false, the client sends an uncompressed message. In either case, the client uses the
compressionStatus field of the message header to inform the server whether the client supports compression.
Compression Semantics for Servers
A server will only receive a compressed message if the client's proxy endpoint has the compression flag (
-z for stringified endpoints). For simpler situations where a client is constructing proxies itself, such as obtaining them from a configuration file, you only need to ensure that the proxy's endpoints enable the compression flag. On the other hand, if the server is dynamically constructing proxies and returning them to the client for eventual invocations, then the server should also enable the compression flag in its object adapter endpoints as shown in the example configuration below:
Specifying the flag here causes every proxy created by the object adapter to advertise compression-capable endpoints.
A server examines the
compressionStatus field of an incoming message header not only to determine whether the message itself is compressed but also to discover whether the client supports compressed replies. A server sends a compressed reply if the following are true:
- The server-side run time supports compression
- The size of the uncompressed reply is at least 100 bytes
compressionStatusfield of the corresponding request message has a value of 1 or 2
If any of these criteria are false, the server sends an uncompressed reply.