gateway worker 分离部署

什么是Gateway Worker分离部署GatewayWorker有三种进程,Gateway进程负责网络IO,BusinessWorker进程负责业务处理,Register进程负责协调Gateway与BusinessWorker之间建立TCP长连接通讯 。我们可以把Gateway BusinessWorker Register分开部署在不同的服务器上,当业务进程BusinessWorker出现瓶颈时,单独增加BusinessWorker服务器提升系统负载能力 。同理,如果Gateway进程出现瓶颈,则增加Gateway服务器 。而Register服务一个集群只需要部署一台服务器,Register服务只有在进程启动的时候协调Gateway与BusinessWorker建立TCP连接,集群运行起来后通讯量极低,不会成为系统瓶颈 。
部署示例以Applications/Todpole为例,假如需要部署三台服务器提供高可用服务 。瓶颈在BusinessWorker进程,则可使用1台作为gateway服务器,另外两台做BusinessWorker服务器 。(如果瓶颈在gateway进程(一般是带宽瓶颈),则可以2台gateway机器,1台BusinessWorker机器,部署方法类似) 。Register服务可以部署在任意一台服务器上 。
gateway worker 分离部署扩容步骤1、由于一个集群只需要一台服务器运行Register服务,这里选择192.168.0.1,端口是1236(端口为start_register.php中监听的端口),其它服务器中start_register.php中的代码可以注释掉 。
2、将进程切分,将Gateway进程部署在一台机器上(假设内网ip为192.168.0.1),这台服务器也运行着集群的Register服务,而BusinessWorker部署在另外两台机器上(内网ip为192.168.0.2/3) 。
3、由于192.168.0.1这台机器只部署Gateway进程和Register进程,所以将该服务器上初始化BusinessWorker实例的地方注释或者删掉,避免运行BusinessWorker进程,例如
这里打开文件Applications/Todpole/start_businessworker.php,注释掉bussinessWorker初始化
...// bussinessWorker//$worker = new BusinessWorker();//$worker->name = 'TodpoleBusinessWorker';//$worker->count = 4;...4、配置Gateway服务器(192.168.0.1)上start_gateway.php中的lanIp=192.168.0.1与本机ip一致,配置registerAddress为192.168.0.1:1236,start_gateway.php文件最终类似下面配置
文件Applications/Todpole/start_gateway.php
<?phpuse WorkermanWorker;use GatewayWorkerGateway;// gateway$gateway = new Gateway("Websocket://0.0.0.0:8282");$gateway->name = 'TodpoleGateway';$gateway->count = 4;// ==== 注意这里配置的是本机内网ip ====$gateway->lanIp = '192.168.0.1';// ==== 注意这里配置的是192.168.0.1:1236 ====$gateway->registerAddress = '192.168.0.1:1236';$gateway->startPort = 2000;$gateway->pingInterval = 10;$gateway->pingData = https://www.isolves.com/it/cxkf/bk/2022-11-14/'{"type":"ping"}';...5、由于192.168.0.2/3 两台服务器只部署BusinessWorker进程,所以将这两台服务器上的Gateway进程初始化文件注释掉或者删掉 。
这里打开Applications/Todpole/start_gateway.php,注释掉gateway初始化部分
<?phpuse WorkermanWorker;use GatewayWorkerGateway;// gateway//$gateway = new Gateway("Websocket://0.0.0.0:8282");//$gateway->name = 'TodpoleGateway';//$gateway->count = 4;//$gateway->lanIp = '192.168.0.1';//$gateway->registerAddress = '192.168.0.1:1236';//$gateway->startPort = 2000;//$gateway->pingInterval = 10;//$gateway->pingData = https://www.isolves.com/it/cxkf/bk/2022-11-14/'{"type":"ping"}';6、打开192.168.0.2/3两台服务器的start_businessworker.php,配置registerAddress为 192.168.0.1:1236
7、逐台启动


    推荐阅读