-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from berdon/berdon/memory-leak-and-tests
Tests, caching multiplexers, fixing memory leak
- Loading branch information
Showing
38 changed files
with
1,556 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/Orleans.Redis.Common/CachedConnectionMultiplexerFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using StackExchange.Redis; | ||
|
||
namespace Orleans.Redis.Common | ||
{ | ||
/// <summary> | ||
/// Caches connections based on the configuration string and reuses them | ||
/// if able. | ||
/// </summary> | ||
public class CachedConnectionMultiplexerFactory : IConnectionMultiplexerFactory | ||
{ | ||
public static IConnectionMultiplexerFactory Default = new CachedConnectionMultiplexerFactory(); | ||
|
||
private readonly SemaphoreSlim _lock = new SemaphoreSlim(1, 1); | ||
private readonly Dictionary<string, IConnectionMultiplexer> _connectionMultiplexers = new Dictionary<string, IConnectionMultiplexer>(); | ||
internal Dictionary<string, IConnectionMultiplexer> TestHook_ConnectionMultiplexers => _connectionMultiplexers; | ||
|
||
private CachedConnectionMultiplexerFactory() { } | ||
|
||
public async Task<IConnectionMultiplexer> CreateAsync(string configuration) | ||
{ | ||
if (!_connectionMultiplexers.TryGetValue(configuration, out var connectionMultiplexer)) | ||
{ | ||
try | ||
{ | ||
await _lock.WaitAsync(); | ||
|
||
if (!_connectionMultiplexers.TryGetValue(configuration, out connectionMultiplexer)) | ||
{ | ||
connectionMultiplexer = await ConnectionMultiplexer.ConnectAsync(configuration); | ||
_connectionMultiplexers.Add(configuration, connectionMultiplexer); | ||
} | ||
} | ||
finally | ||
{ | ||
_lock.Release(); | ||
} | ||
} | ||
|
||
return connectionMultiplexer; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using StackExchange.Redis; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Orleans.Redis.Common | ||
{ | ||
/// <summary> | ||
/// You probably don't want this factory implementation. This does not pool | ||
/// or attempt to reuse connection multiplexers. | ||
/// </summary> | ||
internal class ConnectionMultiplexerFactory : IConnectionMultiplexerFactory | ||
{ | ||
public static ConnectionMultiplexerFactory Default = new ConnectionMultiplexerFactory(); | ||
|
||
private ConnectionMultiplexerFactory() { } | ||
|
||
public async Task<IConnectionMultiplexer> CreateAsync(string configuration) | ||
{ | ||
return await ConnectionMultiplexer.ConnectAsync(configuration); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using StackExchange.Redis; | ||
using System.Threading.Tasks; | ||
|
||
namespace Orleans.Redis.Common | ||
{ | ||
public interface IConnectionMultiplexerFactory | ||
{ | ||
Task<IConnectionMultiplexer> CreateAsync(string configuration); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: InternalsVisibleTo("StreamingTests")] | ||
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Serilog; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Orleans.Redis.Common | ||
{ | ||
public class SilentLogger | ||
{ | ||
public static readonly ILogger Logger = new LoggerConfiguration().CreateLogger(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: InternalsVisibleTo("StreamingTests")] | ||
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.