无扩展和并行处理 [英] Reactive Extensions and parallel processing

查看:139
本文介绍了无扩展和并行处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算使用接收矿在某些时候一个项目中,我一直在研究入什么我可以接收事。

I am planning on using Rx within a project of mine at some point, and I have been researching into what I can do with Rx.

我的项目使用TPL处理状态机并行(利用所有可用的处理器核心)。然而,为了提高性能,我想,以取代目前的IList<>拉与接收推送机制机制

My project uses TPL for processing state machine transitions in parallel (utilising all available processor cores). However, to improve performance, I want to replace the current IList<> pull mechanism with an Rx push mechanism.

由于我不知道很多关于这项技术我想确定接收是否会与推令牌平行状态转换兼容。我会要求所有的平行状态转换订阅接收主体和检索下一个标记。每个状态过渡将需要从主体同理。从我从我自己的研究明白的是,一旦令牌被向外推送给观察者(状态转换在这种情况下),该令牌消失了。如果是这样的情况下,其他方面的转型(在相同状态下)将永远不会收到此标记,并最终会处于错误状态。

As I do not know very much about this technology I want to ascertain whether Rx will be compatible with pushing tokens to the parallel state transitions. I will require that all parallel state transitions subscribe to the Rx subject and retrieve the next token. Each state transition will require the same token from the subject. From what I understand from my own research is that once a token gets pushed out to an observer (a state transition in this case) that token is gone for good. If that is the case the other transitions (for the same state) will never receive this token and will end up in an error state.

可能有人开导我,给我的顾虑是否正确?我没有code显示,因为我只是探索我的选择。

Could somebody enlighten me as to whether my concerns are correct? I have no code to show as I am merely exploring my options.

感谢你。

推荐答案

它可以帮助思考的接收主体为类似.NET的事件,也就是注册的事件处理程序的线程安全的列表。在主题的情况下,这些可被视为等同于一个单独的观察OnNext代表。当事件触发,每次调用处理程序与同一事件的说法。同样的,订阅一个主题各观测得到OnNext使用相同的参数对象调用。这种说法可能包含一个值类型或所需的状态转换令牌的引用类型。 presumably你观察的OnNext处理程序将存储此令牌(比如在并发队列),为相应的并行任务的消耗。

It may help to think about the Rx Subject as similar to .NET event, that is, a thread-safe list of registered event handlers. In the case of Subject these may be considered equivalent to an individual Observer OnNext delegates. Once the event fires, each handler is invoked with the same event argument. Similarly, each Observer subscribed to a Subject gets OnNext invoked with the same argument object. This argument may contain a value type or a reference type of the token needed for state transition. Presumably your Observer's OnNext handlers would store this token (say in concurrent queue) for the corresponding parallel task consumption.

所以没有什么是走了,除非你根本不理会OnNext来电或放弃,他们传递给你的对象。

So nothing is gone for good unless you simply ignore OnNext calls or discard the object that they pass to you.

您可能已经共享的国家腐败问题,如果你的任务之一更改标记。或者你可以有同步的问题,如果一个任务处理的几个状态转换的令牌,而另一项任务都没有出列,甚至第一个时间。但是这不会是,代替一些其他技术推令牌特定于使用接收主题。

You may have shared state corruption issues, if one of your tasks changes the token. Or you may have synchronization issues, if one task processed several state transition tokens while another task had not had the time to dequeue even the first one. But this would not be specific to using Rx Subject, instead of some other technology to push the tokens.

这篇关于无扩展和并行处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆