2

This question has been obsessing me for a few weeks but I was too much in rush to tackle it with sensible hindsight. I finally delivered a quick and dirty solution to the agog customer to relieve his fragile nerves (& also mine, as a matter of consequence). I am now finally taking time to examine this with a free mind.

Basically, I am facing the challenge of processing Synchronous Data (Time-Ordered Series) as fast as possible (<5ms). After trying to play around with many Rube-Goldberg-style designs, such as ordered thread pools and hybrid solutions involving parallel worker queues and other wonky far-fetched ideas, a thorough hands-on bench-work proved that sticking to a plain' old single threaded chain process was by far the best choice for data integrity and performance.

However, at some point in the bottom of the app, this gets to a certain limit. I need to broadcast data in a parallel fashion to different processors. And this is where my headache starts again. When I make the Data Hub (see below) send data to processors in an Asynchronous way (via a thread & a binary ring buffer), it is received in a scrambled order by the receiving party, and data order is corrupted.

So I am looking for a way to send data in a a parallel fashion to all processors, and keep order straight. My other concern is asynchronicity : If the Data Hub's SendEvent delegate is subscribed to by processes' Receive Method in a plain classical way (via +=) , how is this going to behave ?
First off, I don't want the subscriptions to be called "one by one". I am sure there is a way to parallelize this. Secondly, and above all, I do certainly not want processor A to lock the whole chain until it finishes its work.

SO here it is folks. To make a long story short I want to find a sensible way to keep sending data to processors without waiting for it to be processed, but in the same time I need each Data processor to receive the data in an ordered fashion. This might sound incompatible, but I am sure there is a smart & pretty simple way to do this (But I went so deep into this I got really confused, that's why I am asking for your help, good people)

enter image description here

4

3 回答 3

1

If you are talking about a single machine in which you need to distribute the ordered series to all processors on the same machine, I would have Data Hub, continuing with your single-thread idea, enqueue serially to N private queues (relatively fast, so I wouldn't worry about blocking, and you get the benefit of knowing the item got enqueued to all the queues).

Each of these private queues would only allow dequeue from one and only processor. The likely slower "Data Hub --> Processors" will be called in parallel, yet not hold up the whole chain as you put it because...

You can then configure a 1-processor/queue/thread (simple to manage) or 1 queue/N-queues/similar stateless processors (this would take additional downstream work to do reordering).

In a more distributed system (e.g. multi-machine) you typically have something like Data Hub sending a message to a messaging "Topic", and then let the messaging infrastructure send to all the consumers.

于 2012-07-16T21:23:05.517 回答
0

It sounds like you are looking for a Service Bus. In your diagram, that would be the DATA HUB. Microsoft provides a service called MSMQ that can be used for something like this, and I like to use a library called NServiceBus to simplify things.

于 2012-07-16T15:34:54.460 回答
0

Not sure if it is the best fit, but zeromq might work for you here. You can have queues that are all in-memory (fast), you can fan-out and then condense messages to multiple configurations (and I think it take care of order etc).

I have no experience using zeromq on a project, however, it does have some compelling features and seems well supported (with many client languages, C# included).

The manual page has a good introductory video showing what the tool can achieve.

于 2012-07-23T21:30:48.243 回答