circus 是集成了zeromq,使用python編寫的一個進程以及socket 管理工具,使用circus 的進程管理,咱們能夠用來進行批任務的
處理,同時又能保證任務的準確python
項目使用docker+ docker-compose 運行git
├── Dockerfile
├── README.md
├── circus.ini
├── docker-compose.yaml
├── entrypoint.sh
└── webapp
├── info.py
├── info2.py
└── info3.py
info.py:
#!/usr/bin/env python
def main(args):
print(1,"this is a demo")
if __name__ == '__main__':
main("demo")
info2.py:
#!/usr/bin/env python
def main(args):
print(2,"this is a demo")
if __name__ == '__main__':
main("demo")
info3.py:
#!/usr/bin/env python
def main(args):
print(3,"this is a demo")
if __name__ == '__main__':
main("demo")
[circus]
statsd = True
httpd = True
httpd_host = 0.0.0.0
check_delay = 5
endpoint = tcp://0.0.0.0:5555
pubsub_endpoint = tcp://0.0.0.0:5556
[watcher:webapp]
cmd = python /app/webapp/info.py
numprocesses = 1
shell = True
[watcher:webapp2]
cmd = python /app/webapp/info2.py
numprocesses = 1
shell = True
[watcher:webapp3]
cmd = python /app/webapp/info3.py
numprocesses = 1
shell = True
FROM dalongrong/circus:2.7-slim-stretch
WORKDIR /app
COPY circus.ini /app/
COPY webapp/ /app/webapp/
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT [ "/entrypoint.sh" ]
#!/bin/sh
circusd /app/circus.ini
version: "3"
services:
web:
build: ./
hostname: web
ports:
- "9999:9999"
- "8080:8080"
- "5555:5555"
docker-compose up -d
統計監控github
以上只是一個簡單的演示,實際上咱們基於circus 的watch 特性,能夠確保worker 任務的準確以及一致,使用circus
對於咱們確保任務可靠是一種很不錯的方案web
https://github.com/rongfengliang/circus-batch-worker-docker-compose
https://github.com/circus-tent/circus
https://circus.readthedocs.io/en/latest/for-ops/configuration/docker