circus 做为批处理的守护进程

circus 是集成了zeromq,使用python编写的一个进程以及socket 管理工具,使用circus 的进程管理,我们可以用来进行批任务的
处理,同时又能保证任务的准确

项目使用docker+ docker-compose 运行

案例

  • 简单原理说明
    就是一个简单的worker 分了三个,通过circus 的进程watch,确保worker 的唯一,同时可以进行任务的状态监控

项目结构

  • 目录结构
 
├── Dockerfile
├── README.md
├── circus.ini
├── docker-compose.yaml
├── entrypoint.sh
└── webapp
    ├── info.py
    ├── info2.py
    └── info3.py
  • 代码说明
    worker: 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 配置 (circus.ini)
[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
 
  • dockerfile
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" ]
  • entrypoint 文件
#!/bin/sh
circusd /app/circus.ini
  • docker-compose 文件
version: "3"
services: 
  web:
    build: ./
    hostname: web
    ports: 
    - "9999:9999"
    - "8080:8080"
    - "5555:5555"

运行&&效果

  • 启动
docker-compose up -d 
  • 效果

 


统计监控

 

说明

以上只是一个简单的演示,实际上我们基于circus 的watch 特性,可以确保worker 任务的准确以及一致,使用circus
对于我们确保任务可靠是一种很不错的方案

参考资料

https://github.com/rongfengliang/circus-batch-worker-docker-compose
https://github.com/circus-tent/circus
https://circus.readthedocs.io/en/latest/for-ops/configuration/

posted on   荣锋亮  阅读(1004)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2017-06-10 一款直接时空处理分析的开源数据库---geomesa
2017-06-10 nginx php 配置
2017-06-10 Apache Accumulo
2017-06-10 Kubernetes Helm
2017-06-10 Helm Charts

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示