Skip to content

Commit

Permalink
Fixed load balancer so it no longer hogs CPU resources when there are…
Browse files Browse the repository at this point in the history
… no workers available to process a message
  • Loading branch information
Mike737377 committed Nov 17, 2011
1 parent 7967d77 commit 4607fd6
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Rhino.ServiceBus/LoadBalancer/MsmqLoadBalancer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Rhino.ServiceBus.LoadBalancer
{
public class MsmqLoadBalancer : AbstractMsmqListener
{
private int continuousDeliveryFailures = 0;
private readonly Uri secondaryLoadBalancer;
private readonly IQueueStrategy queueStrategy;
private readonly ILog logger = LogManager.GetLogger(typeof(MsmqLoadBalancer));
Expand Down Expand Up @@ -322,9 +323,18 @@ private void HandleStandardMessage(OpenedQueue queue, Message message)
if (worker == null) // handle message later
{
queue.Send(message);

continuousDeliveryFailures++;

if (continuousDeliveryFailures >= 100)
{
System.Threading.Thread.Sleep(1000);
continuousDeliveryFailures = 0;
}
}
else
{
continuousDeliveryFailures = 0;
var workerEndpoint = endpointRouter.GetRoutedEndpoint(worker);
using (var workerQueue = MsmqUtil.GetQueuePath(workerEndpoint).Open(QueueAccessMode.Send))
{
Expand Down

0 comments on commit 4607fd6

Please sign in to comment.