Supervisor分布式

安装php5-xmlrpc扩展

sudo apt-get install php5-xmlrpc

安装supervisor_twiddler

sudo pip install -U supervisor_twiddler
supervisor_twiddler这个包是supervisor的RPC的扩展,它允许supervisor的配置和状态在运行时可以被操纵

pip是python的包管理工具,如果没有装pip,可用sudo apt-get install python-pip进行安装

配置supervisor

往supervisor.conf中加入下列

[rpcinterface:twiddler]
supervisor.rpcinterface_factory = supervisor_twiddler.rpcinterface:make_twiddler_rpcinterface

改变supervisor.sock的权限,将默认的

[unix_http_server]
file=/var/run/supervisor.sock   ; (the path to the socket file)
chmod=0700                       ; sockef file mode (default 0700)

改为

[unix_http_server]
file=/var/run/supervisor.sock   ; (the path to the socket file)
chmod=0766                       ; sockef file mode (default 0700)

配置config.php

  • define('REPO_PATH', '{repo_path}'); 代码路径,例如 : /var/www/campaign-portal
  • define('SUPERVISOR_SOCK', '{supervisor_sock}'); supervisor的sock地址,在supervisor.conf中supervisorctl块可以找到
  • define('SUPERVISOR_CONF', '{supervisor_conf}'); 生成work的配置文件地址,例如 : /etc/supervisor/conf.d/campaignportal.conf,同时需要更改这个文件的权限为777,使用命令sudo chmod 777 {supervisor_conf}
  • define('GROUP_NAME', '{group_name}');
    在{supervisor_conf}的文件末尾加上
    [group:{group_name}]
    programs:{program_name}

添加worker

进入目录{repo_path}/src/protected/
输入命令php yiic resque addProgram --queue="email" --count=6
其中–queue表示监听的队列名, –count表示添加的worker的个数

删除worker

进入目录{repo_path}/src/protected/
输入命令`php yiic resque removeProgram –reserve=3 –queue=“email”
其中–reserve表示保留的worker的个数, –queue可以指定队列名,若指定则表示保留监听队列{queue_name}的worker个数,若不指定–queue则默认表示所有队列

测试发送邮件

分别用单台机器1个worker发送100条邮件,单台机器10个worker发送100条邮件,两台机器各10个worker发送100条邮件
(当用两台机器发送时,需将redis的地址配置成同一台机器即可)
测试结果:
单机器1worker耗时: 25s
单机器10worker耗时: 7s
两机器各10worker耗时: 4s

你可能感兴趣的:(分布式,Supervisor)