Skip to content

Instantly share code, notes, and snippets.

@segphault
Created May 2, 2013 20:53
Show Gist options
  • Save segphault/5505383 to your computer and use it in GitHub Desktop.
Save segphault/5505383 to your computer and use it in GitHub Desktop.
A patch for commenting out the performance counters in SignalR so that it will compile under Mono
diff --git a/src/Microsoft.AspNet.SignalR.Core/Messaging/MessageBroker.cs b/src/Microsoft.AspNet.SignalR.Core/Messaging/MessageBroker.cs
index 76c2416..eb36a38 100644
--- a/src/Microsoft.AspNet.SignalR.Core/Messaging/MessageBroker.cs
+++ b/src/Microsoft.AspNet.SignalR.Core/Messaging/MessageBroker.cs
@@ -19,7 +19,7 @@ public class MessageBroker : IDisposable
{
private readonly Queue<ISubscription> _queue = new Queue<ISubscription>();
- private readonly IPerformanceCounterManager _counters;
+ //private readonly IPerformanceCounterManager _counters = null;
// The maximum number of workers (threads) allowed to process all incoming messages
private readonly int _maxWorkers;
@@ -28,10 +28,10 @@ public class MessageBroker : IDisposable
private readonly int _maxIdleWorkers;
// The number of allocated workers (currently running)
- private int _allocatedWorkers;
+ private int _allocatedWorkers = 0;
// The number of workers that are *actually* doing work
- private int _busyWorkers;
+ private int _busyWorkers = 0;
// Determines if the broker was disposed and should stop doing all work.
private bool _disposed;
@@ -43,7 +43,7 @@ public MessageBroker(IPerformanceCounterManager performanceCounterManager)
public MessageBroker(IPerformanceCounterManager performanceCounterManager, int maxWorkers, int maxIdleWorkers)
{
- _counters = performanceCounterManager;
+ // _counters = performanceCounterManager;
_maxWorkers = maxWorkers;
_maxIdleWorkers = maxIdleWorkers;
}
@@ -101,7 +101,9 @@ private void AddWorker()
{
if (_allocatedWorkers == _busyWorkers)
{
+ /*
_counters.MessageBusAllocatedWorkers.RawValue = Interlocked.Increment(ref _allocatedWorkers);
+ */
Trace.TraceEvent(TraceEventType.Verbose, 0, "Creating a worker, allocated={0}, busy={1}", _allocatedWorkers, _busyWorkers);
@@ -147,7 +149,9 @@ private void ProcessWorkSync(Task pumpTask)
finally
{
// After the pump runs decrement the number of workers in flight
+ /*
_counters.MessageBusAllocatedWorkers.RawValue = Interlocked.Decrement(ref _allocatedWorkers);
+ */
}
}
@@ -156,7 +160,9 @@ private void ProcessWorkAsync(Task pumpTask)
pumpTask.ContinueWith(task =>
{
// After the pump runs decrement the number of workers in flight
+ /*
_counters.MessageBusAllocatedWorkers.RawValue = Interlocked.Decrement(ref _allocatedWorkers);
+ */
if (task.IsFaulted)
{
@@ -213,7 +219,9 @@ private void PumpImpl(TaskCompletionSource<object> taskCompletionSource, ISubscr
}
}
+ /*
_counters.MessageBusBusyWorkers.RawValue = Interlocked.Increment(ref _busyWorkers);
+ */
Task workTask = subscription.Work();
@@ -239,7 +247,9 @@ private void PumpImpl(TaskCompletionSource<object> taskCompletionSource, ISubscr
subscription = null;
}
+ /*
_counters.MessageBusBusyWorkers.RawValue = Interlocked.Decrement(ref _busyWorkers);
+ */
Debug.Assert(_busyWorkers >= 0, "The number of busy workers has somehow gone negative");
}
@@ -262,7 +272,9 @@ private void PumpImplAsync(Task workTask, ISubscription subscription, TaskComple
{
bool moreWork = subscription.UnsetQueued();
+ /*
_counters.MessageBusBusyWorkers.RawValue = Interlocked.Decrement(ref _busyWorkers);
+ */
Debug.Assert(_busyWorkers >= 0, "The number of busy workers has somehow gone negative");
diff --git a/src/Microsoft.AspNet.SignalR.Core/Transports/TransportHeartBeat.cs b/src/Microsoft.AspNet.SignalR.Core/Transports/TransportHeartBeat.cs
index a475265..2c40938 100644
--- a/src/Microsoft.AspNet.SignalR.Core/Transports/TransportHeartBeat.cs
+++ b/src/Microsoft.AspNet.SignalR.Core/Transports/TransportHeartBeat.cs
@@ -24,8 +24,8 @@ public class TransportHeartbeat : ITransportHeartbeat, IDisposable
private readonly IServerCommandHandler _serverCommandHandler;
private readonly TraceSource _trace;
private readonly string _serverId;
- private readonly IPerformanceCounterManager _counters;
- private readonly object _counterLock = new object();
+ //private readonly IPerformanceCounterManager _counters;
+ //private readonly object _counterLock = new object();
private int _running;
private ulong _heartbeatCount;
@@ -39,7 +39,7 @@ public TransportHeartbeat(IDependencyResolver resolver)
_configurationManager = resolver.Resolve<IConfigurationManager>();
_serverCommandHandler = resolver.Resolve<IServerCommandHandler>();
_serverId = resolver.Resolve<IServerIdManager>().ServerId;
- _counters = resolver.Resolve<IPerformanceCounterManager>();
+ //_counters = resolver.Resolve<IPerformanceCounterManager>();
var traceManager = resolver.Resolve<ITraceManager>();
_trace = traceManager["SignalR.Transports.TransportHeartBeat"];
@@ -112,10 +112,12 @@ public bool AddConnection(ITrackingConnection connection)
Trace.TraceInformation("Connection {0} is New.", connection.ConnectionId);
}
+ /*
lock (_counterLock)
{
_counters.ConnectionsCurrent.RawValue = _connections.Count;
}
+ */
// Set the initial connection time
newMetadata.Initial = DateTime.UtcNow;
@@ -129,10 +131,12 @@ private void RemoveConnection(string connectionId)
ConnectionMetadata metadata;
if (_connections.TryRemove(connectionId, out metadata))
{
+ /*
lock (_counterLock)
{
_counters.ConnectionsCurrent.RawValue = _connections.Count;
}
+ */
Trace.TraceInformation("Removing connection {0}", connectionId);
}
}
@@ -190,10 +194,12 @@ private void Beat(object state)
return;
}
+ /*
lock (_counterLock)
{
_counters.ConnectionsCurrent.RawValue = _connections.Count;
}
+ */
try
{
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment