心跳服务器
我们目前游戏服务器的初步架构是一个连接服务器处理来自多个客户端的连接数据,这个服务器将所有数据汇总后通过一个 socket 发送到后方的逻辑服务器。这个设计曾经写过一篇 blog 提到过。
今天,我在两个服务器之间加入了一个控制心跳的服务器。其原始作用很简单,就是按心跳(目前的设定是 10Hz)从连接服务器上拿到数据,再转发给逻辑服务器。并把逻辑服务器发出的数据转出。
为什么这样做?首先,逻辑服务器不再依赖系统时间。它周期性的从心跳服务器获得数据,获得一次,就认为时间流逝了 0.1 秒。这样,时间就改由心跳服务器控制了。
其次,在心跳服务器上加了一小段代码。可以把从连接服务器上获取的所有需要转发到逻辑服务器上的数据都记录在硬盘的一个文件上。那么,逻辑服务器就随时可以重新请求心跳服务器重复发送上一次的数据流。
显然,这大大方便了调试。因为,逻辑服务器的内部状态改变仅仅只依赖于从心跳服务器获得的输入。它自己的时钟也是由心跳服务器输出的数据的节奏控制,而不被自己的时钟影响。所以逻辑服务器上的伪 timer 也只受输入数据的影响。
这样,即使我们实际让服务器工作几个小时甚至几十小时,在心跳服务器回放数据流时,逻辑服务器可以以无等待的过程全速运行,也可以得到完全相同的结果。当然,如果我们暂停下来单步跟踪,同样不会有丝毫影响。
当逻辑服务器由于某个 bug crash 掉时,就可以反复的重现这个 bug ,直到找到问题了。
心跳服务器的代码非常简洁,区区几百行。其任务也非常简单,所以保证其 7*24 小时稳定运行以及高效率运作是非常容易的事情。至于 client 到达逻辑服务器的路程上又多了一台机器引起的效率问题,我觉得大可不必在意。反正在实际运营情况下,玩家的机器连到服务器的机房,已经路过很多机器了,不在乎加这么一台 :)
Comments
Posted by: shawhen | (38) June 22, 2015 01:53 PM
Posted by: 林绍川 | (37) January 31, 2012 02:32 PM
Posted by: Anonymous | (36) August 19, 2010 11:26 AM
Posted by: Mandi Zu | (35) March 24, 2007 10:26 PM
Posted by: Cloud | (34) December 13, 2006 08:31 PM
Posted by: Divin | (33) December 13, 2006 05:49 PM
Posted by: Cloud | (32) October 1, 2006 11:06 PM
Posted by: Anonymous | (31) October 1, 2006 10:17 PM
Posted by: Cloud | (30) September 30, 2006 10:57 AM
Posted by: Wesley | (29) September 30, 2006 06:17 AM
Posted by: sunway | (28) September 22, 2006 09:07 AM
Posted by: Atry | (27) September 21, 2006 11:49 PM
Posted by: Cloud | (26) September 21, 2006 11:05 PM
Posted by: Atry | (25) September 21, 2006 02:56 AM
Posted by: KxjIron | (24) September 19, 2006 09:51 PM
Posted by: Cloud | (23) September 19, 2006 02:20 PM
Posted by: sunway | (22) September 19, 2006 01:29 PM
Posted by: Cloud | (21) September 19, 2006 12:20 PM
Posted by: sunway | (20) September 19, 2006 11:51 AM
Posted by: Cloud | (19) September 19, 2006 11:42 AM
Posted by: xiaoxiao | (18) September 19, 2006 10:34 AM
Posted by: Anonymous | (17) September 19, 2006 09:31 AM
Posted by: Atry | (16) September 19, 2006 12:53 AM
Posted by: Cloud | (15) September 18, 2006 10:20 PM
Posted by: Cloud | (14) September 18, 2006 09:30 PM
Posted by: Anonymous | (13) September 18, 2006 06:58 PM
Posted by: analyst | (12) September 18, 2006 06:11 PM
Posted by: KxjIron | (11) September 18, 2006 05:39 PM
Posted by: Cloud | (10) September 18, 2006 05:18 PM
Posted by: ZERO | (9) September 18, 2006 01:06 PM
Posted by: sunway | (8) September 18, 2006 12:55 PM
Posted by: Cloud | (7) September 17, 2006 07:14 PM
Posted by: ZERO | (6) September 17, 2006 05:40 PM
Posted by: Cloud | (5) September 17, 2006 04:06 PM
Posted by: DD | (4) September 17, 2006 02:10 PM
Posted by: Cloud | (3) September 17, 2006 11:43 AM
Posted by: DD | (2) September 17, 2006 10:00 AM
Posted by: KxjIron | (1) September 17, 2006 09:50 AM