解决LMAX Disruptor模式中的消费者(eventProcessor)问题(Solution to slow consumer(eventProcessor) issue in LMAX Disruptor pattern)
在使用破坏者时,可能存在滞后的消费者,并且由于消费者的速度缓慢,整个应用程序都会受到影响。
请记住,每个生产者(发布者)和消费者(EventProcessor)都在一个线程上运行,这可以解决缓慢的消费者问题?
我们可以在单个消费者上使用多个线程吗? 如果没有,什么是更好的选择?
While using the disruptor, there may be a consumer(s) that is lagging behind, and because of that slow consumer, the whole application is affected.
Keeping in mind that every producer(Publisher) and consumer(EventProcessor) is running on a single thread each, what can be the solution to the slow consumer problem?
Can we use multiple threads on a single consumer? If not, what is a better alternative?
原文:https://stackoverflow.com/questions/11606102
最满意答案
使用Dictionary类 :
static Dictionary<string, VideoProcessor> processors = new Dictionary<string, VideoProcessor(); static void HandleVideoConnectionEvent(int port, string deviceId) { processors.Add(deviceId, new VideoProcessor(port, deviceId)); }
然后,您可以通过deviceId查找VideoConnection类。 如:
static VideoProcessor GetVideoProcessor(string deviceId) { return processors[deviceId]; }
当然,您需要进行完整性检查,例如确保字典中不存在deviceId(字典必须具有唯一键或唯一的deviceIds,并确保何时尝试从字典中获取它) ,deviceId实际存在)
Use a Dictionary class:
static Dictionary<string, VideoProcessor> processors = new Dictionary<string, VideoProcessor(); static void HandleVideoConnectionEvent(int port, string deviceId) { processors.Add(deviceId, new VideoProcessor(port, deviceId)); }
Then you can lookup a VideoConnection class by the deviceId. Such as:
static VideoProcessor GetVideoProcessor(string deviceId) { return processors[deviceId]; }
Of course, you will need to do sanity checks, like making sure that the deviceId doesn't already exist in the dictionary (a dictionary has to have unique keys, or unique deviceIds, and making sure when you try to get it from the dictionary, that the deviceId actually exists)
相关问答
更多-
我认为你不能访问x:Name,但是你应该能够定义你自己的列类型,它具有你可以设置的Name属性。 因此,不要添加GridViewColumns,而是在xaml中添加NamedColumn对象。 定义从GridViewColumn派生的类型: public class NamedColumn : GridViewColumn { public string ColumnName {get; set;} } 并在你的xaml中使用它:
钩对象实例化(Hook to object instantiation)[2022-02-03]
没有简单的方法可以在外部挂钩对象实例化,也许还有一些调试API,这是有充分理由的。 它使您的代码更难以维护和理解为其他人。 属性将不起作用,因为在需要之前实际上不创建属性的实例 - 通过反射,并且将属性分配给类型而不是实例。 但您可能会将代码放在基类中,并从中派生所有其他类,尽管将半初始化实例传递给其他方法也不是一个好习惯。 如果该类继承自ContextBoundObject ,则可以为其分配ProxyAttribute的自定义实现并覆盖其上的所有操作。 如果您无法创建公共基类(当您的类型继承自不同类型时) ...不,你不能将委托“分配”给事件处理程序。 处理程序通过将事件添加到内部用于表示事件的基础委托的调用列表来附加到事件。 这是设计的! 不,您不能通过更改先前用于附加事件处理程序的引用所指向的对象来更改处理程序; 部分原因是委托是不可变的 ,部分原因是你只是将引用改为指向别的东西,而不是真正改变你想要完成的事件处理程序。 要更改委托,您必须先删除以前的委托: backgroundworker.DoWork -= dweh; 然后通过将其添加为事件的处理程序来分配新的: backgroundworker.DoW ...我认为没有必要使用该编译代码。 您在动态定义的函数中所做的一切都可以通过普通的Python完成。 from django.utils import timezone from types import MethodType def _add_get_in_last_delta(self, time_series_object_name, time_series_field_name): # ...就在这里; 但它不是真正公开的API。 示例:( 在运行时创建事件处理程序 ) @handler("foo") def on_foo(self): return "Hello World!" def test_addHandler(): m = Manager() m.start() m.addHandler(on_foo) 这取自tests.core.test_dynamic_handlers 注意:每个BaseComponent / Component子类也是Ma ...如果要获取所有选项卡信息,则需要定义回调。 尝试这个: chrome.windows.getAll({populate:true},function(wins){ wins.forEach(function(win){ win.tabs.forEach(function(tab){ console.log(tab.url); }); }); }); 如果要获取选项卡信息,请记住在清单中添加“tabs”权限。 You need to define a callback i ...我的事件处理程序是否仍然附加到新的myPerson或我是否需要再次添加它? 事件处理程序特定于类的每个实例。 当你执行myPerson = New Person你实例化一个全新的Person类实例,它有自己的引用,变量和事件。 请记住,仅仅因为你引用相同的变量,它并不意味着它是同一个类实例。 类实例可以由多个变量引用。 例如,这里: Dim Person1 As New Person Dim Person2 As Person = Person1 Dim Person3 As Person = Person ...我不能简单地新建一个EventHandler当然可以,尽管你需要使用Delegate.CreateDelegate()和反射来完成它。 假设MyEventHandler是一个实例方法,你可以这样做: var eventInfo = …; EventHandler badHandler = MyEventHandler; var goodHandler = Delegate.CreateDelegate( eventInfo.EventHandle ... 使用Dictionary类 : static Dictionaryprocessors = new Dictionary 您应该重写OnMouseXXX方法: class Etape : Panel { private Point MouseDownLocation; protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); if (e.Button == MouseButtons.Left) { MouseDownLocation ...相关文章
更多- 构建Disruptor实例-生产消费模型完成整个入门示例
- 数据生产者向disruptor容器RingBuffer中推送数据
- Disruptor实现EventFactory接口创建实例对象
- Storm-源码分析- Disruptor在storm中的使用
- 数据消费者:实现EventHandler监听接口处理数据
- [MySQL Slow log]平滑清除在线慢查询日志slow log的流程
- ACTIVEMQ Topic消息 生产者 发布消息后 消费者收不到消息
- Hadoop常见问题及解决办法
- 不选择使用Lucene的6大原因(转载) - Hubble.net 将尽可能解决这些问题
- 强人,牛人进来帮忙解决一下
最新问答
更多- 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
- 如何通过引用返回对象?(How is returning an object by reference possible?)
- 矩阵如何存储在内存中?(How are matrices stored in memory?)
- 每个请求的Java新会话?(Java New Session For Each Request?)
- css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
- 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
- xcode语法颜色编码解释?(xcode syntax color coding explained?)
- 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
- 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
- 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
- 西安哪有PLC可控制编程的培训
- 在Entity Framework中选择基类(Select base class in Entity Framework)
- 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
- 电脑二级VF有什么用
- Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
- 金华英语角.
- 手机软件如何制作
- 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
- 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
- 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
- Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
- 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
- python的访问器方法有哪些
- DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
- 在Ruby中对组合进行排序(Sorting a combination in Ruby)
- 网站开发的流程?
- 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
- 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
- 透明度错误IE11(Transparency bug IE11)
- linux的基本操作命令。。。