Skip to content
This repository was archived by the owner on Sep 25, 2023. It is now read-only.

Pomelo 0.5新特性

demon0925 edited this page Jul 15, 2013 · 18 revisions

#Pomelo0.5新特性

在0.5版本中,主要增强了Pomelo高可用的特性,包括master服务器的高可用和其它服务器的可配置自动重启,另外还提供一个全局的globalChannel和服务器进程与cpu绑定的功能。

##master 高可用 Pomelo 虽然是分布式服务器,但是master确实全局唯一的。为了提高整体服务的可用性,我们在0.5版中引入了master高可用功能,提供可靠的master服务。

实现原理

master高可用采用多机热备技术,对于全局的master,可以启动多个备份节点。当主master宕机时,从master会自动接管主master的工作,这些全部是自动进行的。

使用说明

要开启Master高可用,只需要在app.js中加入以下配置: javascript app.configure('production|development', function(){ app.enable('masterHA'); app.set('masterHAConfig', { server : '127.0.0.1:2181', path : '/pomelo/master' }); });

app.enable('masterHA')表示开启master ha功能,这时服务器会加载zookeeper客户端,并尝试连接zookeeper默认端口“127.0.0.1:2181"。用户可以通过app.set('masterHAConfig'来加载自定义zookpeeper配置。server表示zookeeper服务器,path表示使用的zookeeper节点。该节点必须是zookeeper上已经存在并可以正常访问的节点。

##globalChannel

globalChannel是提供全局的channel服务,其默认实现是通过redis将相关信息存储,开发者可以根据自身需求开发其它实现;Pomelo原有的channelService只能在具体某个服务器中创建channel,这种channel只能存储该服务器的用户信息,而globalChannelService则可以创建全局的globalChannel,所有服务器的用户信息都可以通过globalChannel进行存储。

###使用说明

globalChannel默认不加载,需要使用只需要在app.js中进行配置即可,参考配置如下(开启redis-server)。

```javascript```
app.configure('production|development', function(){
	app.set('globalChannelConfig',
		{
			host: '127.0.0.1',
		        port: 6379
		});
});

需要使用只需要从application中获取,即app.get('globalChannelService');具体的接口可以参考Pomelo的API说明文档

##服务器自动重启

根据网友的需求,在Pomelo0.5版本中增加了服务器(非master)自动重启的功能,服务器的自动重启是以服务器与master服务器的连接状态为判断依据,即当服务器与master服务器断开后触发该服务器的重新启动。默认情况下服务器不会自动重启,如果需要开启自动重启功能需要在servers.json中进行配置auto-restart,具体配置如下:

json { "development":{ "connector":[ {"id":"connector-server-1", "host":"127.0.0.1", "port":4050, "clientPort": 3050, "frontend": true} ] "chat":[ {"id":"chat-server-1", "host":"127.0.0.1", "port":6050, "auto-restart": true} ] "gate":[ {"id": "gate-server-1", "host": "127.0.0.1", "clientPort": 3014, "frontend": true} ] } }


##服务器绑定CPU

为了更加充分的利用服务器的CPU,Pomelo在0.5版本中增加了服务器进程与指定CPU进行绑定,该功能限于linux系统的多核服务器,如果需要将服务器与具体CPU进行绑定,只需要在servers.json中进行配置,具体配置如下:

```json```
{
    "development":{
        "connector":[
             {"id":"connector-server-1", "host":"127.0.0.1", "port":4050, "clientPort": 3050, "frontend": true, "cpu": 2}
         ]
        "chat":[
             {"id":"chat-server-1", "host":"127.0.0.1", "port":6050, "cpu": 1}
        ] 
        "gate":[
	     {"id": "gate-server-1", "host": "127.0.0.1", "clientPort": 3014, "frontend": true, "cpu": 3}
	]
     }
}

Clone this wiki locally