热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

设计模式寻求建议:pushmodelv.pull模型。-designpatternaskingforadvice:pushmodelv.s.pullmodel

Myapplicationhasseveralworkers(workingondifferentthingsasdifferentprocesses)andsomeres

My application has several workers (working on different things as different processes) and some resources (working unit). Different workers need to process on all working unites. For example, I have workers like W1, W2 and W3, working unit U1 and U2. Then W1 needs to process U1 and U2, the same as W2 and W3. The restriction is different workers can not work on the same work unit at the same time.

我的应用程序有几个工作人员(作为不同的过程处理不同的东西)和一些资源(工作单元)。不同的工人需要处理所有的工作单位。例如,我有W1、W2和W3、工作单元U1和U2。然后W1需要处理U1和U2,就像W2和W3一样。限制是不同的工人不能同时在同一工作单位工作。

I have two designs and want to ask for advice which one is better.

我有两种设计,想咨询一下哪个更好。

  1. Push model: using a central job scheduler to assign work units to different workers, to ensure different workers are not working on the same work unit;
  2. 推模型:使用中央作业调度器将工作单元分配给不同的工作者,以确保不同的工作者不在同一工作单元工作;
  3. Pull model: each worker will ask a central job scheduler for work units to process, and job scheduler will select an appropriate work unit which is not being processed by other worker for the asking worker.
  4. 拉模型:每个工作者将要求一个中央作业调度器处理工作单元,而作业调度器将选择一个适当的工作单元,这个工作单元没有被其他工作者处理。

I want to know the pros and cons of each design. And one of my major concerns is about -- finding a loosely coupled design (it is one of my major goal, but not the only goal). I am not sure whether push model or poll model has better extensibility (option 1 is more loosely coupled)?

我想知道每个设计的利弊。我最关心的一个问题是——找到一个松散耦合的设计(这是我的主要目标之一,但不是唯一的目标)。我不确定push模型或poll模型是否具有更好的可扩展性(选项1更松散耦合)?

thanks in advance, George

提前谢谢,乔治

2 个解决方案

#1


3  

The advantage of the "pull" model is that each worker knows locally how much it is loaded and thus can manage its load.

“拉动”模型的优点是,每个worker都知道本地加载了多少负载,因此可以管理其负载。

Also, the "pull" model might be more "decoupled" as the variable of "load" is kept local to the worker whereas in the "push" model one would need a communication protocol (and overhead) to communicate this state.

此外,“拉”模型可能更“解耦”,因为“负载”的变量对工作者是本地的,而在“推”模型中,一个人需要一个通信协议(和开销)来通信这个状态。


Think of the success of the "pull" model in the auto industry: it went from the traditional "push" model where inventories would be difficult to track and required lots of feedback to the now successful and ubiquitous "pull" model.

想想汽车行业“拉动”模式的成功:它来自传统的“推”模式,在这种模式下,存货很难追踪,需要大量反馈给现在成功且无处不在的“拉”模型。


When it comes to scaling, you can have an intermediate layer of "schedulers" that "poll" for jobs from the layer above. The base workers can now interact with the intermediate layer in a partitioned way.

当谈到扩展时,您可以有一个中间的“调度器”层,从上面的层“轮询”作业。基工作者现在可以以分区的方式与中间层交互。


Note that in either model a coordination communication protocol is required: it is the nature of the coordination protocol that differs. In the "push model", there is an additional control loop required to report/poll the "load factor" of each worker. As one scale the system, more bandwidth is required, more state on the scheduler side, more latency incurred etc.

注意,在任何一个模型中都需要一个协调通信协议:它是不同的协调协议的性质。在“push模型”中,需要一个额外的控制循环来报告/轮询每个worker的“负载因数”。当扩展系统时,需要更多的带宽、调度器端更多的状态、产生更多的延迟等等。

#2


2  

I would certainly use the Pull model as it is simpler to implement.

我肯定会使用拉模型,因为它更容易实现。

I can only imagine 2 implementations:

我只能想象两种实现:

  1. Pull model = 1 service with the tasks collection plus many worker clients.

    拉动模型= 1个服务,包含任务集合和许多工作客户端。

  2. Push model = 1 service with the tasks collection and a list of active subscribers plus many active subscribers (workers).

    Push model = 1服务,包含任务集合和活动订阅者列表以及许多活动订阅者(工作者)。

As the Pull model doesn't have to implement full duplex service calls neither a subscriber list, it is simpler.

由于拉模型不需要实现全双工服务调用,也不需要订阅者列表,因此更简单。


推荐阅读
  • 本文介绍了如何使用Express App提供静态文件,同时提到了一些不需要使用的文件,如package.json和/.ssh/known_hosts,并解释了为什么app.get('*')无法捕获所有请求以及为什么app.use(express.static(__dirname))可能会提供不需要的文件。 ... [详细]
  • 如何自行分析定位SAP BSP错误
    The“BSPtag”Imentionedintheblogtitlemeansforexamplethetagchtmlb:configCelleratorbelowwhichi ... [详细]
  • Spring源码解密之默认标签的解析方式分析
    本文分析了Spring源码解密中默认标签的解析方式。通过对命名空间的判断,区分默认命名空间和自定义命名空间,并采用不同的解析方式。其中,bean标签的解析最为复杂和重要。 ... [详细]
  • 本文讨论了在Spring 3.1中,数据源未能自动连接到@Configuration类的错误原因,并提供了解决方法。作者发现了错误的原因,并在代码中手动定义了PersistenceAnnotationBeanPostProcessor。作者删除了该定义后,问题得到解决。此外,作者还指出了默认的PersistenceAnnotationBeanPostProcessor的注册方式,并提供了自定义该bean定义的方法。 ... [详细]
  • http:my.oschina.netleejun2005blog136820刚看到群里又有同学在说HTTP协议下的Get请求参数长度是有大小限制的,最大不能超过XX ... [详细]
  • 本文介绍了通过ABAP开发往外网发邮件的需求,并提供了配置和代码整理的资料。其中包括了配置SAP邮件服务器的步骤和ABAP写发送邮件代码的过程。通过RZ10配置参数和icm/server_port_1的设定,可以实现向Sap User和外部邮件发送邮件的功能。希望对需要的开发人员有帮助。摘要长度:184字。 ... [详细]
  • flowable工作流 流程变量_信也科技工作流平台的技术实践
    1背景随着公司业务发展及内部业务流程诉求的增长,目前信息化系统不能够很好满足期望,主要体现如下:目前OA流程引擎无法满足企业特定业务流程需求,且移动端体 ... [详细]
  • 浏览器中的异常检测算法及其在深度学习中的应用
    本文介绍了在浏览器中进行异常检测的算法,包括统计学方法和机器学习方法,并探讨了异常检测在深度学习中的应用。异常检测在金融领域的信用卡欺诈、企业安全领域的非法入侵、IT运维中的设备维护时间点预测等方面具有广泛的应用。通过使用TensorFlow.js进行异常检测,可以实现对单变量和多变量异常的检测。统计学方法通过估计数据的分布概率来计算数据点的异常概率,而机器学习方法则通过训练数据来建立异常检测模型。 ... [详细]
  • IjustinheritedsomewebpageswhichusesMooTools.IneverusedMooTools.NowIneedtoaddsomef ... [详细]
  • Spring常用注解(绝对经典),全靠这份Java知识点PDF大全
    本文介绍了Spring常用注解和注入bean的注解,包括@Bean、@Autowired、@Inject等,同时提供了一个Java知识点PDF大全的资源链接。其中详细介绍了ColorFactoryBean的使用,以及@Autowired和@Inject的区别和用法。此外,还提到了@Required属性的配置和使用。 ... [详细]
  • 本文介绍了OpenStack的逻辑概念以及其构成简介,包括了软件开源项目、基础设施资源管理平台、三大核心组件等内容。同时还介绍了Horizon(UI模块)等相关信息。 ... [详细]
  • 本文记录了在vue cli 3.x中移除console的一些采坑经验,通过使用uglifyjs-webpack-plugin插件,在vue.config.js中进行相关配置,包括设置minimizer、UglifyJsPlugin和compress等参数,最终成功移除了console。同时,还包括了一些可能出现的报错情况和解决方法。 ... [详细]
  • 本文介绍了一个适用于PHP应用快速接入TRX和TRC20数字资产的开发包,该开发包支持使用自有Tron区块链节点的应用场景,也支持基于Tron官方公共API服务的轻量级部署场景。提供的功能包括生成地址、验证地址、查询余额、交易转账、查询最新区块和查询交易信息等。详细信息可参考tron-php的Github地址:https://github.com/Fenguoz/tron-php。 ... [详细]
  • VueCLI多页分目录打包的步骤记录
    本文介绍了使用VueCLI进行多页分目录打包的步骤,包括页面目录结构、安装依赖、获取Vue CLI需要的多页对象等内容。同时还提供了自定义不同模块页面标题的方法。 ... [详细]
  • 从零基础到精通的前台学习路线
    随着互联网的发展,前台开发工程师成为市场上非常抢手的人才。本文介绍了从零基础到精通前台开发的学习路线,包括学习HTML、CSS、JavaScript等基础知识和常用工具的使用。通过循序渐进的学习,可以掌握前台开发的基本技能,并有能力找到一份月薪8000以上的工作。 ... [详细]
author-avatar
手机用户2502880331
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有