解决多人网络游戏同步问题的一个算法--The CMB Algorithm

本文介绍了CMB算法,一种用于分布式高性能计算中同步多个进程的有效算法。CMB算法通过维护每个参与进程的时间戳队列来计算全局虚拟时间(GVT),确保所有进程观察到相同的事件顺序。文章还讨论了如何避免死锁情况以及使用空消息来维持系统运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

转载于:https://www.cnblogs.com/vilyLei/articles/1549600.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值