Table of Contents Previous Next
Logo
The Ice Run Time in Detail : 32.15 Batched Invocations
Copyright © 2003-2007 ZeroC, Inc.

32.15 Batched Invocations

Oneway and datagram invocations are normally sent as a separate message, that is, the Ice run time sends the oneway or datagram invocation to the server immedi­ately, as soon as the client makes the call. If a client sends a number of oneway or datagram invocations in succession, the client-side run time traps into the OS kernel for each message, which is expensive. In addition, each message is sent with its own message header (see Chapter 37), that is, for n messages, the band­width for n message headers is consumed. In situations where a client sends a number of oneway or datagram invocations, the additional overhead can be considerable.
To avoid the overhead of sending many small messages, you can send oneway and datagram invocations in a batch: instead of being sent as a separate message, a batch invocation is placed into a client-side buffer by the Ice run time. Successive batch invocations are added to the buffer and accumulated on the client side until the client explicitly flushes them. The relevant APIs are part of the proxy inter­face:
namespace IceProxy {
    namespace Ice {
        class Object : /* ... */ {
        public:
            Ice::ObjectPrx ice_batchOneway() const;
            Ice::ObjectPrx ice_batchDatagram() const;
            // ...
        };
    }
}
The ice_batchOneway and ice_batchDatagram methods convert a proxy to a batch proxy. Once you obtain a batch proxy, messages sent via that proxy are buffered in the client-side run time instead of being sent immediately. Once the client has invoked one or more operations on batch proxies, it can explic­itly flush the batched invocations by calling Communicator::flushBatchRequests:
module Ice {
    local interface Communicator {
        void flushBatchRequests();
        // ...
    };
};
This causes the batched messages to be sent “in bulk”, preceded by a single message header. On the server side, batched messages are dispatched by a single thread, in the order in which they were written into the batch. This means that messages from a single batch cannot appear to be reordered in the server. More­over, either all messages in a batch are delivered or none of them. (This is true even for batched datagrams.)
For batched datagram invocations, you need to keep in mind that, if the data for the invocations in a batch substantially exceeds the PDU size of the network, it becomes increasingly likely for an individual UDP packet to get lost due to frag­mentation. In turn, loss of even a single packet causes the entire batch to be lost. For this reason, batched datagram invocations are most suitable for simple inter­faces with a number of operations that each set an attribute of the target object (or interfaces with similar semantics). (Batched oneway invocations do not suffer from this risk because they are sent over stream-oriented transports, so individual packets cannot be lost.)
Batched invocations are more efficient if you also enable compression for the transport: many isolated and small messages are unlikely to compress well, whereas batched messages are likely to provide better compression because the compression algorithm has more data to work with.1
Note that the Ice run time will automatically initiate a flush if you add a message to a batch, but that message would exceed Ice.MessageSizeMax or the maximum size for datagrams. You can disable automatic flushing by setting Ice.BatchAutoFlush to zero.
As for oneway invocations (see page 898), you should disable server-side active connection management (ACM). With server-side ACM enabled, it is possible for a server to close the connection at the wrong moment and not process a batch (with no indication being returned to the client that the batch was lost).

1
Regardless of whether you used batched messages or not, you should enable compression only on lower-speed links. For high-speed LAN connections, the CPU time spent doing the compression and decompression is typically longer than the time it takes to just transmit the uncompressed data.

Table of Contents Previous Next
Logo