pengwk / blog

用 Issue 的方式写博客
0 stars 0 forks source link

Celery 原理 #1

Open pengwk opened 5 years ago

pengwk commented 5 years ago

问题:

https://github.com/celery/celery https://www.fullstackpython.com/celery.html

pengwk commented 5 years ago

入队的数据结构

http://docs.celeryproject.org/en/latest/internals/protocol.html#version-2

pengwk commented 5 years ago

https://liuliqiang.info/post/celery-source-analysis-worker-execute-engine

pengwk commented 5 years ago

https://gtcsq.readthedocs.io/en/latest/openstack/kombu.html

pengwk commented 5 years ago

运行的地方:https://sourcegraph.com/github.com/celery/celery@76d10453ab9267c45b12d7c60b5ee0e4113b4369/-/blob/celery/app/trace.py?utm_source=share#L383

pengwk commented 5 years ago

https://www.youtube.com/watch?v=ceJ-vy7fvus https://www.youtube.com/watch?v=kDoHrFLkahA https://www.youtube.com/watch?v=XjzyOyLbvN8 https://www.youtube.com/watch?v=Bo6UtRhedjE https://www.youtube.com/watch?v=E708csv4XgY

pengwk commented 5 years ago

用例及其对应的数据结构和算法

pengwk commented 5 years ago

相关概念

相互关联的概念

关联的组件开源项目

pengwk commented 5 years ago

主要功能

pengwk commented 5 years ago

文章

pengwk commented 5 years ago

怎么启动,怎么关闭,怎么监控?

pengwk commented 5 years ago

用到了哪些设计模式?

pengwk commented 5 years ago

heartbeat

pengwk commented 5 years ago

没有中心化的东西怎么相互确保还活着? worker 具体指什么?一个进程?如果是,究竟是一个怎样的进程?

pengwk commented 5 years ago

worker

https://docs.celeryproject.org/en/latest/userguide/workers.html

image

https://linux.die.net/man/2/getrusage

System usage statistics. The fields available may be different on your platform.

From getrusage(2):

stime 系统调用时间

Time spent in operating system code on behalf of this process.

utime 花在用户指令上的时间

Time spent executing user instructions.

maxrss 这个进程最大的驻留内存

The maximum resident size used by this process (in kilobytes).

idrss 用于保存数据的不共享内存大小

Amount of non-shared memory used for data (in kilobytes times ticks of execution)

isrss 不共享用于堆栈的内存大小

Amount of non-shared memory used for stack space (in kilobytes times ticks of execution)

ixrss 与其他内存共享的内存数量。

Amount of memory shared with other processes (in kilobytes times ticks of execution).

inblock 这个进程读磁盘文件的次数

Number of times the file system had to read from the disk on behalf of this process.

oublock 这个进程写磁盘的次数

Number of times the file system has to write to disk on behalf of this process.

majflt I/O 时出现的页错误次数

Number of page faults that were serviced by doing I/O.

minflt 没有 I/O 时的页错误数

Number of page faults that were serviced without doing I/O.

msgrcv 收到的 IPC 消息数

Number of IPC messages received.

msgsnd 发送的 IPC 消息数

Number of IPC messages sent.

nvcsw 自愿发起 context switch 次数

Number of times this process voluntarily invoked a context switch.

nivcsw 非自愿发起 context switch 次数

Number of times an involuntary context switch took place.

nsignals 收到的信号数

Number of signals received.

nswap 进程完全交换到磁盘的次数

The number of times this process was swapped entirely out of memory.

pengwk commented 5 years ago

broadcast

https://github.com/celery/celery/blob/8e016e667ae16958043b096e5cb89ac0f7dd7989/celery/app/control.py#L443

pengwk commented 5 years ago

一个远程控制指令是怎么被执行的?

pengwk commented 5 years ago

image

为什么类变量和实例变量这样用?

pengwk commented 5 years ago

drain 排空耗尽

pengwk commented 5 years ago

Redis

command

key

http://xargin.com/redis-protocal/ https://redis.io/topics/protocol

pengwk commented 5 years ago

ack

[pid 17740] sendto(29, "*1\r\n$5\r\nMULTI\r\n*3\r\n$4\r\nZREM\r\n$13\r\nunacked_index\r\n$36\r\ne6bad363-8d7c-4a02-8a8e-2a4cc58dfdf7\r\n*3\r\n$4\r\nHDEL\r\n$7\r\nunacked\r\n$36\r\ne6bad363-8d7c-4a02-8a8e-2a4cc58dfdf7\r\n*1\r\n$4\r\nEXEC\r\n", 176, 0, NULL, 0) = 176
pengwk commented 5 years ago

使用了那些设计模式?

pengwk commented 5 years ago

DAG directed acyclic map 有向无环图

https://zh.wikipedia.org/wiki/%E6%9C%89%E5%90%91%E6%97%A0%E7%8E%AF%E5%9B%BE

pengwk commented 5 years ago

default queue (named “celery” for historical reasons).

pengwk commented 5 years ago

The non-AMQP backends like Redis or SQS don’t support exchanges, so they require the exchange to have the same name as the queue. Using this design ensures it will work for them as well.

pengwk commented 5 years ago
pengwk commented 5 years ago

Celery 的生态

管理

监控

与 Web 框架结合

Django

Flask

tornado

扩展增强

RedBeat

RedBeat is a Celery Beat Scheduler that stores the scheduled tasks and runtime metadata in Redis.

Celery Once

https://github.com/cameronmaske/celery-once

Celery for node

[node-celery: Celery client for Node.js]https://github.com/mher/node-celery

node-celery-ts: TypeScript Celery client for Node

Celery for go

gocelery: Celery Distributed Task Queue in Go

竞品

pengwk commented 5 years ago

http://docs.celeryproject.org/en/latest/internals/guide.html#module-overview