Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple Producers, Multiple Consumers and Store Problem
    primarykey
    data
    text
    <p>I have a scenario where Multiple Producers are running on different machines in a Network. These are Singleton WCF Services which are queuing the Products (Output) in the Central Store which is also a Singleton WCF Service.</p> <p>There are consumers who dequeue the product from the Central Store by calling the Central Store via a JSON Request. The products are delivered by resolving certain priority constraints. The Producers produce the products at very high rate around 10000 in a minute the aim is to serve them at the same speed to the consumers and not keep them waiting.</p> <p>Everything works fine as long as I have 3-4 Producers and upto 10 consumers. But as I increase the Producers and Consumers everything Freezes.</p> <p>I was using <a href="http://www.interact-sw.co.uk/iangblog/2004/04/26/yetmoretimedlocking" rel="nofollow noreferrer">TimedLock</a> which is a wrapper to Monitor.TryEnter. I have tried all Types of Synchronization Techniques like ReaderWriterLockSlim and other posts on the Web but the result is same. I was avoiding ReaderWriterLockSlim as I've large number of writes than reads.</p> <p>As I don't have control over the Consumer and Producer threads which are spawned by WCF as Singleton Store is accessed by them. I was not able to implement the Produer/Consumer samples available on Web. Following is the Sample Code of the Data Store.</p> <pre><code>public class Store:IEnumerable&lt;Product&gt; { private List&lt;Product&gt; _Products; private object _MonitorLock; public Store() { _Products = new List&lt;Product&gt;(); _MonitorLock = new object(); } public void Add(Product Product) { lock (_MonitorLock) { _Products.Add(Product); } } public void Remove(Product Product) { lock (_MonitorLock) { _Products.Remove(Product); } } public int Count { get { lock (_MonitorLock) { return _Products.Count; } } } public IEnumerator&lt;Product&gt; GetEnumerator() { List&lt;Product&gt; ProductsCopy; lock (_MonitorLock) { ProductsCopy = new List&lt;Product&gt;(_Products); } foreach (Product oEntry in ProductsCopy) yield return oEntry; } public Product GetHighestPriorityProduct() { Product oProduct; lock (_MonitorLock) { //Some Logic to Resolve the Priority _Products.Remove(oProduct); } return oProduct; } #region IEnumerable Members System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); } #endregion } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload