Skip to content

Commit

Permalink
Clean up topics more aggressively to avoid leakage.
Browse files Browse the repository at this point in the history
- Keep signals up to date with added groups
- Changed GC interval to 5 seconds
- Changed max dead topics to 1000 instead of 5000.

SignalR#1697
  • Loading branch information
davidfowl committed Mar 18, 2013
1 parent 592eaa9 commit 70b15bf
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ private void ProcessCommand(Command command)
if (EventKeyAdded != null)
{
_groups.Add(name);
_signals.Add(name);
EventKeyAdded(this, name);
}
}
Expand All @@ -272,6 +273,7 @@ private void ProcessCommand(Command command)
if (EventKeyRemoved != null)
{
_groups.Remove(name);
_signals.Add(name);
EventKeyRemoved(this, name);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.AspNet.SignalR.Core/Messaging/MessageBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class MessageBus : IMessageBus, IDisposable

private Timer _gcTimer;
private int _gcRunning;
private static readonly TimeSpan _gcInterval = TimeSpan.FromSeconds(15);
private static readonly TimeSpan _gcInterval = TimeSpan.FromSeconds(5);

private readonly TimeSpan _topicTtl;

Expand All @@ -48,7 +48,7 @@ public class MessageBus : IMessageBus, IDisposable
internal Action<string, Topic> AfterTopicMarkedSuccessfully;
internal Action<string, Topic, int> AfterTopicMarked;

private const int DefaultMaxTopicsWithNoSubscriptions = 5000;
private const int DefaultMaxTopicsWithNoSubscriptions = 1000;

private readonly Func<string, Topic> _createTopic;
private readonly Action<ISubscriber, string> _addEvent;
Expand Down
36 changes: 36 additions & 0 deletions src/Microsoft.AspNet.SignalR.Stress/Hubs/HubWithGroups.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.md in the project root for license information.

using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNet.SignalR.Hubs;

Expand All @@ -22,4 +23,39 @@ public Task Leave(string group)
return Groups.Remove(Context.ConnectionId, group);
}
}

public class OnConnectedOnDisconnectedHub : Hub
{
private static List<string> theList = new List<string>();
private static object syncLock = new object();

public string Echo(string str)
{
return str;
}

public override Task OnDisconnected()
{
lock (syncLock)
{
theList.Remove("TheList_" + Context.ConnectionId);
}

Groups.Remove(Context.ConnectionId, "Groups_" + Context.ConnectionId);

return base.OnDisconnected();
}

public override Task OnConnected()
{
lock (syncLock)
{
theList.Add("TheList_" + Context.ConnectionId);
}

Groups.Add(Context.ConnectionId, "Groups_" + Context.ConnectionId);

return base.OnConnected();
}
}
}
14 changes: 5 additions & 9 deletions src/Microsoft.AspNet.SignalR.Stress/Stress/StressRuns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,22 +181,18 @@ public static IDisposable ManyUniqueGroups(int concurrency)
private static void RunOne(MemoryHost host)
{
var connection = new Client.Hubs.HubConnection("http://foo");
var proxy = connection.CreateHubProxy("HubWithGroups");
var wh = new ManualResetEventSlim(false);

proxy.On<int>("Do", i => wh.Set());
var proxy = connection.CreateHubProxy("OnConnectedOnDisconnectedHub");

try
{
connection.Start(host).Wait();

proxy.Invoke("Join", "foo").Wait();
string guid = Guid.NewGuid().ToString();
string otherGuid = proxy.Invoke<string>("Echo", guid).Result;

proxy.Invoke("Send", "foo", 0).Wait();

if (!wh.Wait(TimeSpan.FromSeconds(10)))
if (!guid.Equals(otherGuid))
{
Debugger.Break();
throw new InvalidOperationException("Fail!");
}
}
finally
Expand Down

0 comments on commit 70b15bf

Please sign in to comment.