﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Scooletz commented on When race conditions &amp; unbounded result sets are actually the solution – the resolution</title><description>Having the numbers: 10^5 requests to perform, 1s - time of a single request, the solution simply begs for using some kind of a dispatcher moving the applications from "I am a single instance of Windows serwice" rather to "I use some bus (MassTransit, NServiceBus) to dispatch all of asynchronous work".
</description><link>http://ayende.com/4819/when-race-conditions-unbounded-result-sets-are-actually-the-solution-the-resolution#comment4</link><guid>http://ayende.com/4819/when-race-conditions-unbounded-result-sets-are-actually-the-solution-the-resolution#comment4</guid><pubDate>Sat, 23 Apr 2011 05:06:05 GMT</pubDate></item><item><title>Brian commented on When race conditions &amp; unbounded result sets are actually the solution – the resolution</title><description>Maybe I'm underthinking this.  Why not just use the TPL?
  
  
int numConcurentRequests = 25;
  
Subscription[] subscriptions = session.Query
&lt;subscription().Where(s =&gt; s.NextCharge &lt; DateTime.Now).ToArray();
  
numConcurentRequests = numConcurentRequests &gt; subscriptions.Count() ? subscriptions.Count() : numConcurentRequests;
  
Task[] tasks = new Task[numConcurentRequests];
  
for (int i = 0; i &lt; subscriptions.Count(); i++)
  
{
  
    if (i % numConcurentRequests == 0 &amp;&amp; i &gt;= numConcurentRequests)
  
        Task.WaitAll(tasks);
  
    tasks[i % numConcurentRequests] = Task.Factory.StartNew(
  
                    () =&gt;
  
                    {
  
                        subscriptions[i].ChargeAccount();
  
                    }
  
                    );
  
}    
&gt;</description><link>http://ayende.com/4819/when-race-conditions-unbounded-result-sets-are-actually-the-solution-the-resolution#comment3</link><guid>http://ayende.com/4819/when-race-conditions-unbounded-result-sets-are-actually-the-solution-the-resolution#comment3</guid><pubDate>Fri, 22 Apr 2011 15:34:42 GMT</pubDate></item><item><title>Frank Quednau commented on When race conditions &amp; unbounded result sets are actually the solution – the resolution</title><description>Not really a tech thing, but I'd consider prioritizing billing operations. For example going for larger outstanding bills first and every x weeks going for small amounts (because, if the business runs well, they may never be charged). 
  
  
Also it could be considered whether it is feasible to split the bill. That way, if you don't get the full amount you take what is available, and call the transaction xyz pt.1
  
  
Additionally it may be worth to throw more money at the intelligence you deploy with regards to when the accounts are filled. Outwitting others in that respect should reduce the need to actually race for the money. 
</description><link>http://ayende.com/4819/when-race-conditions-unbounded-result-sets-are-actually-the-solution-the-resolution#comment2</link><guid>http://ayende.com/4819/when-race-conditions-unbounded-result-sets-are-actually-the-solution-the-resolution#comment2</guid><pubDate>Fri, 22 Apr 2011 13:49:20 GMT</pubDate></item><item><title>ammarmar commented on When race conditions &amp; unbounded result sets are actually the solution – the resolution</title><description>Queues are nice. We use MSMQ for similar application (just not dealing with money :). I like the way you can always pause processing and restart it later (fine granularity).
  
  
With introducing of error queues you also get an opportunity to push failed requests to it and get back to them later.
  
  
Sometimes, when the error is e.g. network-related, fixing it is as simple as movine the message from error queue back to the regular one.
</description><link>http://ayende.com/4819/when-race-conditions-unbounded-result-sets-are-actually-the-solution-the-resolution#comment1</link><guid>http://ayende.com/4819/when-race-conditions-unbounded-result-sets-are-actually-the-solution-the-resolution#comment1</guid><pubDate>Fri, 22 Apr 2011 11:17:19 GMT</pubDate></item></channel></rss>