【笔记】Celery调研

如何避免celey定时任务的重复执行(通过celery_one) 场景:在公司通过celery写了几个定时的任务,但是过了一段时间我发现这些定时任务的日志里面竟然出现的重复的结果,定时任务大概就是定期的去统计数据什么的,类似报表那样,可是今天我发现竟然有两条一模一样的报表,于是去查了一下celery的运行日志,发现同一时间内(1s内)竟然同时发送了两次的任务,也就是同时产生了两个worker。然后就出现了两条一毛一样的结果,还写到了我的报表里面。 查了一下官方c... 阅读详情

Celery是一个分布式任务调度系统。
但是坑比较深。

  1. 依赖第三方mq,复杂度增加,用Redis还是rabbit?这又是一个问题。
  2. CeleryBeat作为任务调度器,有单点故障,如果部署多个实例,又会产生重复消费,所以需要引入Redis或者zk来做选举来failover。
    参考https://www.v2ex.com/t/661409
  3. 生产消费高度耦合。
    @app.taskdef add(x, y): return x + y
    上面的逻辑感觉很尴尬,装饰器很奇怪,消费的逻辑在生产者的代码里,让人产生困惑,难以维护。
  4. 任务消息去重排序合并幂,怎么避免被worker并发处理等问题,还是要依赖消费端来实现,怎么实现成了问题。
  5. 批量处理消息,group方法感觉很难用。
  6. 其他各种限制,各种参数,感觉很古怪。
    综上,基于业务选择消息队列和分布式协调件,比如redis,再根据业务实现自定义的消息调度消费逻辑,基于关系型数据库比如MySQL实现消息幂等。
Celery 踩坑笔记 看教程里经常出现的那个魔法般的from task import add实际上只是同目录下对于模块的引用。因为 @app.task 修改后的对象和原函数对象一样,都可以直接调用,也都是调用本地方法。不同的是添加了 Celery 自己的方法,比如 delay,调用这些方法就是走 Celery 的流程了。 配置可以在 celeryconfig.py 中设置,用 app.config_from_object 阅读详情

相关推荐

Celery - 配置文件总结

目录 一、broker or backend 连接 二、定时任务 celery - 官方配置文档 Setting name Replace with CELERY_ACCEPT_CONTENT accept_content CELERY_ENABLE_UTC enable_utc CELERY_IMPORTS imports CELERY_INCLU...

LIN的博客 2711

celery路由和监控踩坑记录

celery路由以及监控记录

weixin_42573211的博客 584

celery-singleton:无缝地防止重复执行芹菜任务

芹菜单身 重复的任务阻塞了您的消息代理? 基于时间的速率限制会让您感到恶心吗? 别再看了! 这是celery任务的基类,可确保在任何给定时间只能将任务的一个实例排队或运行。 使用任务的名称和参数来确定唯一性。 目录 先决条件 celery-singleton使用任务的delay()或apply_async()参数的JSON表示来生成唯一锁,并将其存储在redis中。 默认情况下,它使用celery 的redis服务器。 如果您使用其他/无结果后端,或者想为celery-singleton使用其他Redis服务器,请参阅以了解如何自定义Redis。 要使用Redis以外的其他东西,请参阅后端部分 因此,要点是: 确保所有任务参数都可以JSON序列化 您的celery应用配置了Redis结果后端,或者您在配置中指定了另一个Redis /兼容后端 如果您已经在使用Redis后端和大多数默认的

如何保证消息不被重复消费?

在消费消息时,首先从消息的properties中获取messageId属性,并使用isMessageProcessed()方法查询该消息是否已经被处理过。这是因为RabbitMQ是一个消息的投递机制,只有在消费者确认了消息已经被处理后,才会从消息队列中删除该消息。在消费下一条消息时,先查询是否已经消费过该消息,如果已经消费过,则不再处理。在Java中,可以使用消息队列来实现消息的异步处理,其中常用的消息队列有 RabbitMQ、ActiveMQ、Kafka 等。1.消息队列提供的幂等性机制。

zy1992As的博客 5400

STM32L151C8T6低功耗实战:RTC闹钟唤醒停机模式的配置与优化

本文详细介绍了如何在STM32L151C8T6微控制器上配置与优化RTC闹钟唤醒停机模式,以实现极致的低功耗设计。文章从核心原理出发,结合STM32CubeMX配置实战,深入讲解了进入停机模式前的关键准备工作、唤醒后的系统恢复流程,并分享了将功耗降至个位数微安级的深度优化技巧与常见问题解决方案。

weixin_29166013的博客 307

【Python&RS】哨兵2号(Sentinel2)轨道条带说明+图幅统计(表格+矢量)

今天给大家带来哨兵2号的图幅编号介绍以及全国省、市所需图幅数的统计。网上教程极少,而且结果也不公开。因为每次下载的时候都不知道需要几幅,所以研究后给大家分享一下。

Remote Sensing迷途小书童 1695

celery 使用经验总结

         为什么要使用celery Celery是一个使用Python开发的分布式任务调度模块,因此对于大量使用Python构建的系统,可以说是无缝衔接,使用起来很方便。Celery专注于实时处理任务,同时也支持任务的定时调度。因此适合实时异步任务定时任务等调度场景。Celery需要依靠RabbitMQ等作为消息代理,同时也支持Redis甚至是Mysql,Mongo等,当然,官方...

ronon77的专栏 808

别再乱点U盘里的.exe了!手把手教你清除‘Usb Disk.exe’病毒并恢复隐藏文件

本文详细介绍了如何识别和清除U盘病毒(如Usb Disk.exe),并提供从终止病毒进程到恢复隐藏文件的完整步骤。通过禁用自动播放、清理注册表和使用命令行工具,帮助用户彻底清除病毒并预防未来感染,确保数据安全。

weixin_42530732的博客 621

celery apply_async定时任务重复执行问题

清晨起来,客户生产环境突然出现诡异的现象,定时早上7点执行一次的任务,在七点执行了七八次,非常诡异。而且经过排查,发现没有报错信息,最后是查看日志时,发现celery重发了很多同一时间的定时任务。

会一点前端、会一点Java、会一点Python 2042

最新测算源码PHP算命源码-风水八字-八字起名-塔罗牌占卜

未来,随着技术的发展和用户需求的变化,我们可以继续对系统进行升级和优化,以满足更多用户的需求和期望。数据库设计:创建一个名为bazi的数据库表,包含以下字段:id(自增ID)、name(姓名)、sex(性别)、birth_date(出生日期)、birth_time(出生时间)、bazi(八字结果)。数据库设计:创建一个包含塔罗牌信息的数据库表,如tarot_cards,包含字段:id(塔罗牌ID)、name(塔罗牌名称)、meaning(塔罗牌含义)等。根据操作系统的不同,PHP的安装方法会有所不同。

shanbeizi的博客 2424

手把手教你用Foobar2000播放DSD音频(含DOP设置与SPDIF输出教程)

本文详细指导如何在Foobar2000中播放DSD音频,重点解析了DOP协议的原理与设置方法。通过安装SACD插件、配置输出设备及启用DOP模式,实现DSD音频的原生比特流输出,并特别讲解了如何通过SPDIF接口传输DSD信号,帮助发烧友充分释放高清音频设备的潜力。

weixin_29290963的博客 1879

Celery笔记四之在Django中使用celery

在 Django 的 tasks 里我们会把 task 都写在可重复使用的 app 下,比如 blog,但是这些 app 不能依赖于项目本身,所以不能直接引入这些app实例@shared_task 装饰器可以让你在不需要任何具体的 app 实例的情况下创建 task以上是官方文档给出的一段介绍,u1s1,我不太理解这段话的含义,但是我们照做就行了,就是在 Django 的 task 中,我们使用 @shared_task 来修饰那些 task 即可。

weixin_43354181的博客 701

把 SAP GUI 做成可维护的应用:Module Pool 基础与 Table Control 深入实战

SAP Module Pool 与 Table Control 开发要点 摘要:Module Pool 作为 SAP GUI 交互的核心技术,由程序、屏幕(Dynpro)和流逻辑(Flow Logic)组成,通过 PBO/PAI 事件驱动数据流。Table Control 是其中处理多行数据的核心控件,其开发关键在于: 正确理解 PBO/PAI 数据流机制 掌握 CXTAB_CONTROL 结构的关键属性(LINES、TOP_LINE 等) 合理设置列控制属性(CXTAB_COLUMN) 采用 LOOP W

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 249

celery笔记四之在Django中使用celery

在 Django 的 tasks 里我们会把 task 都写在可重复使用的 app 下,比如 blog,但是这些 app 不能依赖于项目本身,所以不能直接引入这些app实例@shared_task 装饰器可以让你在不需要任何具体的 app 实例的情况下创建 task以上是官方文档给出的一段介绍,u1s1,我不太理解这段话的含义,但是我们照做就行了,就是在 Django 的 task 中,我们使用 @shared_task 来修饰那些 task 即可。

Gefangenes的博客 434

华为OD机试 - 猴子吃桃 - 二分查找(Java 新系统 100分)

每一题都有详细的答题思路、详细的代码注释、样例测试,发现新题目,随时更新,全天CSDN在线答疑。

学Java,找哪吒 3858

从0开始图形学(光栅化)

从0开始图形学

A112459的专栏 2402

pycharm 运行celery_Celery全面学习笔记

来源介绍Celery 是 Distributed Task Queue,分布式任务队列。分布式决定了可以有多个 worker 的存在,队列表示其是异步操作。Celery 核心模块Celery有一下5个核心角色Task就是任务,有异步任务和定时任务Broker中间人,接收生产者发来的消息即Task,将任务存入队列。任务的消费者是Worker。Celery本身不提供队列服务,推荐用Redis或Rabb...

weixin_33923901的博客 2382

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

Python学习笔记——Celery

目录 celery介绍 Task Queue Celery安装  Broker Application 1.创建应用 2.调用任务 3.存储结果 配置 1.直接通过app来配置 2.专有配置文件 项目中使用Celery 调用任务(Calling Task) Designing Work-flows Routing Periodic Tasks Django使用Ce...

唯恋殊雨的博客 7736

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

celery backend mysql_celery学习笔记

celery使用在django下,官方4.2文档 http://docs.celeryproject.org/en/latest/django/index.html, github文档:https://github.com/celery/celery/tree/master/examples/django/首先生成celery的appfrom __future__ import absolut...

weixin_28883533的博客 601

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

python笔记(celery框架初识)

一、Celery的定义 Celery(芹菜)是一个简单、灵活且可靠的,处理大量消息的分布式系统,并且提供维护这样一个系统的必需工具。 我比较喜欢的一点是:Celery支持使用任务队列的方式在分布的机器、进程、线程上执行任务调度。然后我接着去理解什么是任务队列。 任务队列 任务队列是一种在线程或机器间分发任务的机制。 消息队列 消息队列的输入是工作的一个单元,称为任务,独立的职程(...

小小龙的博客 2586

Celery 笔记(Flower Supervisor)

celery执行流程 使用场景 异步任务:将耗时操作任务交给Celery去异步执行,比如发短信、邮件、消息推送、音频处理等等 定时任务:类似于crontab,比如每日数据统计 一、python调用celery 1. 安装配置 pip install celery[redis] 消息中间件:RabbitMQ/Redis app = Celery(‘xxx’, backend=‘xxx’, b...

guohewei123的博客 1135

django+celery+beat笔记

异步任务

iam2cc的博客 1365

Celery笔记三之task和task的调用

如果是在 Django 系统中使用 celery,需要定义一个延时任务或者周期定时任务,可以使用 @shared_task 来修饰在 Django 系统中使用 celery 的方式会在接下来的几篇笔记中介绍道。多个装饰器task名称每个 task 都有一个唯一的名称用来标识这个 task,如果我们在定义的时候不指定,系统会为我们默认一个名称,这些名称会在 celery 的 worker 启动的时候被系统扫描然后输出一个列表展示。可以看到这个地方,系统就会使用我们定义的 name 了。

weixin_43354181的博客 3925

celery笔记一之celery介绍、启动和运行结果跟踪

celery 大致有两种应用场景,一种是异步任务,一种是定时任务。比如说在一个接口请求中,某个函数执行所需的时间过长,而前端页面并不是立刻需要在接口中获取处理结果,可以将这个函数作为异步任务,先返回给前端处理中的信息,在后台单独运行这个函数,这就是异步任务。另一个比如说某个函数需要每天晚上运行一遍,不可能人天天守着后台手动执行一遍这个函数,那么就可以用 celery 来实现这个定时的周期任务。task。

woaimx_1314的博客 3781

Django中使用celery

环境,win10。项目用的数据库需提前配置好,我用的mysql。redis数据库需提前配置好,并启动,我已在服务器中配置,并将连接信息存入win10环境变量,后面的代码里从环境变量中读取连接信息。 celery的安装和配置 安装 pip installDjango==3.2.2 pip installcelery==4.4.0 pip installcelery-with-redis==3.0 pip installdjango-celery-results==1.2.0 #基于Dja...

fj_changing的博客 1210
上一篇: 【代码】tarfile的使用
下一篇: 【笔记】程序性能优化28个策略原则
azach64
博客等级 码龄8年 25粉丝 68原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址