All Projects → knitmesh → Servos Framework

knitmesh / Servos Framework

Adopt decentralized development and unified management Develop on a service basis Each service can be started individually or multiple services can be started at the same time Configuration file management specifies which services take effect and deployment is flexible

Programming Languages

python
139335 projects - #7 most used programming language
python27
39 projects

Servos Framework: The process level Concurrent Toolkit

Python 2.7 License Codacy Badge

框架说明

服务的组织

采用分散开发统一管理。以服务为单位进行开发。每个服务可以单独启动,也可以多个服务同时启动,通过配置文件进行管理指定哪些服务生效,部署方式灵活。

特点

  • 框架代码结构简单易用,易于修改。新手、老鸟皆可把控。

  • 采用gevent实现并发操作,与scrapy的twisted相比,代码更容易理解。

  • 完全模块化的设计,强大的可扩展性。

  • 支持多线程/Gevent两种并发模式

  • 支持分布式

扩展性

  • plugin扩展。框架已经预设了一些调用点,方便对各个环节进行修改。可以针对这些调用点编写相应的处理,当框架启动时会自动进行采集,当程序运行到调用点位置时,自动调用对应的插件函数。
  • middleware 中间件扩展。与web framework类似,这里是对服务接口调用进行扩展。
  • injection 注入式扩展。可向框架注入 functions, global_objects 等。

新增服务流程

  • 增加服务包。
  • 从基类继承,并使用 entry 装饰器标记。
  • 编码服务逻辑。
  • 配置文件中增加要启动的服务。

用户手册

依赖

  • Python 2.7
  • pip

安装

  • 安装服务框架。新构建的服务依赖 servos-framework 框架,先 pip install servos-framework
  • 安装服务依赖。运行命令 servos install,该命令会自动安装各服务在自己目录下 requirements.txt 定义的依赖包,具体参数可以运行 servos help 命令查看。
  • 启动服务。运行 servos runserver --settings cache_settings.ini
  • 调试服务。使用 manage.py 作为启动文件,在IDE的 Parameters 配置处输入将要使用的命令行, 如: runserver --settings cache_settings.ini

部署安装

  • 执行./setenv.sh会自动创建virtualenv虚拟环境。
  • 执行source .virtualenvs/services/bin/activate切换到虚拟环境。
  • 启动服务。
    1. cache服务:运行 servos runserver --settings cache_settings.ini
    2. websocket服务:运行 servos runserver --settings wss_settings.ini

Docker

构建base镜像

# 初始化外部依赖
python2 docker/prepare.py -v VERSION --pip-server 192.168.103.137:8000 --yum-repo http://192.168.103.137:8001
docker build . -f docker/base/Dockerfile -t service_base:VERSION

构建功能镜像(以cache为例)

cd docker/cache/
docker build . -t service-cache:VERSION

运行服务(以cache为例)

docker run --rm --network host \
    -v /etc/portal/cache_settings.ini:/etc/portal/cache_settings.ini \
    --name service-wss \
    t2cloud-service-wss:VERSION
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].