The Message Flow Manager

This class is an intermediary between the messaging layer (send/receive) and the application code. It provides the following features:

Discussion

This class works by aggregating small messages into larger groups. Doing so increases latency for small messages in an idle system. However orders of magnitude performance benefits can be gained by the resulting reduction in process/process and process/kernel context switching, memory allocation, and network bandwidth. In a busy system this efficiency benefit can ultimately reduce average latency for small messages as compared to overwhelming the system with short messages.

This class support simple concatenation of short messages into a single larger packet.

However, many typical messages have a variable sized internal structure consisting of a header, some variable amount of data, and possibly a trailer.

This class allows application code to build messages with this structure through multiple, independent calls.

#include <clMsgFlowMgr.hxx>

APIs

   1 namespace SAFplus
   2   {
   3 
   4   class Message
   5     {
   6     public:
   7     // destination data, only one valid be a union...
   8     SAFplus::Handle handle;
   9     Group* grp;
  10     ClIocAddress addr;
  11 
  12     //? Prefer a more sophisticated scatter/gather technique here, and ability to prepend/append to basic buffer
  13     char msg[MAX_MSG_SIZE];
  14     };
  15 
  16   class MessageFlowManager
  17     {
  18     public: 
  19 
  20     //? Derived class overrides this to implement the actual send.  The class might use also use this function to "complete" the message if the header needs to be updated WRT number of records or if there is a suffix that needs to be added.
  21     virtual void send(Message* msg);
  22     //? Derived class overrides this to implement the message header (if needed) 
  23     virtual void open(Message* msg);   
  24 
  25     //? Derived class overrides this to report how much data is waiting on the receive queue.  Typically, returning 0 here will trigger all pending send data to be flushed.  0xffffffff means there is no receive queue (this MessageFlowManager instance is not dealing with a server's receive/send data pattern).
  26     virtual unsigned int recvQueueSize() { return 0xffffffff; }
  27 
  28     //? Send any pending data right now.
  29     void flush(void);
  30 
  31     // Message Flow Management APIs
  32     unsigned int maxLatency;  //? Do not wait any longer than this before sending the data
  33     unsigned int maxSize;     //? If a message exceeds this size, send it right away
  34     
  35 
  36 
  37     // Message construction APIs
  38    
  39     //? Get a message buffer with at least maxSize available space
  40     Message* get(int maxSize);
  41     //? Queues the message for sending -- may not send right away.  A subsequent call to get() may return this same "msg" for message aggregation.
  42     void send(Message* msg);  
  43     };
  44 
  45 
  46 
  47   }

SAFplus: MessageFlowManager (last edited 2014-08-28 20:25:22 by AndrewStone)