The CMB Algorithm

The distributed computing/high performance computing community came up with many algorithms that improve upon the two common solutions mentioned above. The best one that we can use for networked games is the CMB algorithm.

CMB stands for three names: Chandy, Misral and Bryant. Just google to know more about them. Or, ask Dr. Plank.

CMB is a distributed k-reduction algorithm. It is distributed by nature. So there is no single master process. Note, here distributed refers more to all processes being independent. You can use CMB to synchronize 20 processes on the same machine too.

On each process, you keep an event queue sorted by timestamp. Note, here the timestamp are time to execute. You keep a queue for each participating process. So, if you have three processes, then on each process, there are three queues (one of those is the queue for the host process).

Based on the timestamps in the queues, each process can calculate a Global Virtual Time (GVT), by look at the first element in each queue. The lowest one is the current GVT.

GVT basically describes that all processes have gone into the "future" of GVT. No one will generate any events that "live in the past". We can then be pretty sure that all processes see the same order up to the instant of GVT. So all events up till the GVT event can be executed right away. All events on the queue with a timestamp higher than GVT remains in the queue for future release.

As events get released, it is possible for a queue to become empty. In that case, there is no way to know what time that corresponding process is up to. So everybody wait. The system remains in deadlock situation until a new message arrives from that event.

To avoid the problem of deadlock, null messages are used. One way is to generate null messages on regular intervals. The length of the interval is basically the longest period of deadlock that you can tolerate. Another way is to generate a null message after every real executable event. This causes the number of messages to double, but basically enforce of deadlock time of zero.