Skip to content

Commit

Permalink
fixed #174
Browse files Browse the repository at this point in the history
  • Loading branch information
imperugo committed May 27, 2019
1 parent 2c09b81 commit 896668d
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Title>StackExchange.Redis.Extensions.AspNetCore is a library that has a set of extensions method fpr ASP.NET Core.</Title>
<Summary>StackExchange.Redis.Extensions.AspNetCore is a library that has a set of extensions method fpr ASP.NET Core with the scope to simply the library configuration into the dependency injection</Summary>
<Description>StackExchange.Redis.Extensions.AspNetCore is a library that has a set of extensions method fpr ASP.NET Core</Description>
<VersionPrefix>5.0.2</VersionPrefix>
<VersionPrefix>5.0.3</VersionPrefix>
<!--<VersionSuffix>pre</VersionSuffix>-->
<Authors>Ugo Lattanzi</Authors>
<Copyright>Ugo Lattanzi</Copyright>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Description>StackExchange.Redis.Extensions is a library that extends StackExchange.Redis allowing you a set of functionality needed by common applications.

This implementation is based on Microsoft's BinarySerializer</Description>
<VersionPrefix>5.0.2</VersionPrefix>
<VersionPrefix>5.0.3</VersionPrefix>
<!--<VersionSuffix>pre</VersionSuffix>-->
<Authors>Ugo Lattanzi</Authors>
<Copyright>Ugo Lattanzi</Copyright>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

using StackExchange.Redis.Extensions.Core.Configuration;
using StackExchange.Redis.Extensions.Core.Configuration;
using StackExchange.Redis.Extensions.Core.Implementations;

namespace StackExchange.Redis.Extensions.Core.Abstractions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,19 @@ public void Dispose()
}

public IConnectionMultiplexer GetConnection()
{
Lazy<ConnectionMultiplexer> response;

var loadedLazys = connections.Where(lazy => lazy.IsValueCreated);

if (loadedLazys.Count() == connections.Count)
{
var minValue = connections.Min(lazy => lazy.Value.GetCounters().TotalOutstanding);
response = connections.First(lazy => lazy.Value.GetCounters().TotalOutstanding == minValue);
}
else
{
response = connections.First(lazy => !lazy.IsValueCreated);
}

return response.Value;
}
{
Lazy<ConnectionMultiplexer> response;
var loadedLazys = connections.Where(lazy => lazy.IsValueCreated);

if (loadedLazys.Count() == connections.Count) {
response = connections.OrderBy(x=>x.Value.GetCounters().TotalOutstanding).First();
}
else {
response = connections.First(lazy => !lazy.IsValueCreated);
}

return response.Value;
}

private void Initialize()
{
Expand All @@ -59,4 +55,4 @@ private void Initialize()
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ To store complex data It requires one of the following implementations:
- StackExchange.Redis.Extensions.Protobuf
- StackExchange.Redis.Extensions.Utf8Json
- StackExchange.Redis.Extensions.Binary</Description>
<VersionPrefix>5.0.2</VersionPrefix>
<VersionPrefix>5.0.3</VersionPrefix>
<!--<VersionSuffix>pre</VersionSuffix>-->
<IncludeSource>false</IncludeSource>
<IncludeSymbols>true</IncludeSymbols>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Description>StackExchange.Redis.Extensions is a library that extends StackExchange.Redis allowing you a set of functionality needed by common applications.

This implementation is based on Jil serializer.</Description>
<VersionPrefix>5.0.2</VersionPrefix>
<VersionPrefix>5.0.3</VersionPrefix>
<!--<VersionSuffix>pre</VersionSuffix>-->
<Authors>Ugo Lattanzi</Authors>
<Copyright>Ugo Lattanzi</Copyright>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("4.0.5.0")]
[assembly: AssemblyFileVersion("4.0.5.0")]
[assembly: AssemblyVersion("5.0.3.0")]
[assembly: AssemblyFileVersion("5.0.3.0")]
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<metadata>
<id>StackExchange.Redis.Extensions.LegacyConfiguration</id>
<title>StackExchange.Redis.Extensions.LegacyConfiguration</title>
<version>5.0.2</version>
<version>5.0.3</version>
<authors>Ugo Lattanzi</authors>
<owners>Ugo Lattanzi</owners>
<licenseUrl>https://github.com/imperugo/StackExchange.Redis.Extensions/blob/master/LICENSE</licenseUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Description>StackExchange.Redis.Extensions is a library that extends StackExchange.Redis allowing you a set of functionality needed by common applications.

This implementation is based on MsgPack serializer.</Description>
<VersionPrefix>5.0.2</VersionPrefix>
<VersionPrefix>5.0.3</VersionPrefix>
<!--<VersionSuffix>pre</VersionSuffix>-->
<Authors>Ugo Lattanzi</Authors>
<Copyright>Ugo Lattanzi</Copyright>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Description>StackExchange.Redis.Extensions is a library that extends StackExchange.Redis allowing you a set of functionality needed by common applications.

This implementation is based on Newtonsoft Json.Net serializer.</Description>
<VersionPrefix>5.0.2</VersionPrefix>
<VersionPrefix>5.0.3</VersionPrefix>
<!--<VersionSuffix>pre</VersionSuffix>-->
<Authors>Ugo Lattanzi</Authors>
<Copyright>Ugo Lattanzi</Copyright>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Description>StackExchange.Redis.Extensions is a library that extends StackExchange.Redis allowing you a set of functionality needed by common applications.

This implementation is based on Protobuf serializer.</Description>
<VersionPrefix>5.0.2</VersionPrefix>
<VersionPrefix>5.0.3</VersionPrefix>
<!--<VersionSuffix>pre</VersionSuffix>-->
<Authors>Ugo Lattanzi</Authors>
<Copyright>Ugo Lattanzi</Copyright>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Description>StackExchange.Redis.Extensions is a library that extends StackExchange.Redis allowing you a set of functionality needed by common applications.

This implementation is based on UTF8Json serializer.</Description>
<VersionPrefix>5.0.2</VersionPrefix>
<VersionPrefix>5.0.3</VersionPrefix>
<!--<VersionSuffix>pre</VersionSuffix>-->
<Authors>Ugo Lattanzi</Authors>
<Copyright>Ugo Lattanzi</Copyright>
Expand Down
55 changes: 50 additions & 5 deletions tests/StackExchange.Redis.Extensions.Tests/StressTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Linq;
using System.Threading.Tasks;
using StackExchange.Redis.Extensions.Core;
using StackExchange.Redis.Extensions.Core.Configuration;
using StackExchange.Redis.Extensions.Core.Implementations;
using StackExchange.Redis.Extensions.Newtonsoft;
using StackExchange.Redis.Extensions.Tests.Extensions;
using Xunit;
Expand All @@ -21,7 +23,7 @@ public StressTest(ITestOutputHelper output)
mux = ConnectionMultiplexer.Connect(new ConfigurationOptions
{
DefaultVersion = new Version(3, 0, 500),
EndPoints = { { "redishost", 6379 } },
EndPoints = { { "localhost", 6379 } },
AllowAdmin = true,
ConnectTimeout = 5000
});
Expand All @@ -30,10 +32,13 @@ public StressTest(ITestOutputHelper output)

public void Dispose()
{
sut.Database.FlushDatabase();
sut.Database.Multiplexer.GetSubscriber().UnsubscribeAll();
sut.Database.Multiplexer.Dispose();
sut.Dispose();
if(sut != null)
{
sut.Database.FlushDatabase();
sut.Database.Multiplexer.GetSubscriber().UnsubscribeAll();
sut.Database.Multiplexer.Dispose();
sut.Dispose();
}
}

private async Task PopulateDbAsync(string prefix, int numberOfItems)
Expand Down Expand Up @@ -86,5 +91,45 @@ public async Task StressTest_On_SearchKeysMethod()
Assert.Equal(schemas1.Count(), totalItemsToAdd);
}

//[Fact(Skip = "Is a performance test, must be run manually")]
[Fact]
public async Task Open_Tons_of_concurrent_connections()
{
var sut = new RedisCacheConnectionPoolManager(new RedisConfiguration()
{
AbortOnConnectFail = false,
Hosts = new RedisHost[]
{
new RedisHost() { Host = "localhost", Port = 6379 }
},
AllowAdmin = true,
ConnectTimeout = 5000,
Database = 8,
PoolSize = 10,
ServerEnumerationStrategy = new ServerEnumerationStrategy()
{
Mode = ServerEnumerationStrategy.ModeOptions.All,
TargetRole = ServerEnumerationStrategy.TargetRoleOptions.Any,
UnreachableServerAction = ServerEnumerationStrategy.UnreachableServerActionOptions.Throw
}
});

await sut.GetConnection().GetDatabase().StringSetAsync("key","value");

var conn = sut.GetConnection();

Parallel.For(0,1000, x =>
{
try
{
sut.GetConnection().GetDatabase().StringGet("key");
}
catch (Exception exc)
{
output.WriteLine($"Index: {x} - Exception {exc.ToString()}");
throw;
}
});
}
}
}

0 comments on commit 896668d

Please sign in to comment.