Skip to content

Commit

Permalink
Merge pull request #142 from akkadotnet/dev
Browse files Browse the repository at this point in the history
v1.4.17 Release
  • Loading branch information
Aaronontheweb authored Mar 17, 2021
2 parents 1219f69 + 7c8e175 commit bd9ec73
Show file tree
Hide file tree
Showing 28 changed files with 867 additions and 280 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,5 @@ FakesAssemblies/
tools/
build/
.nuget/
.dotnet/
.dotnet/
.idea/
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ akka.persistence.journal.redis {
# qualified type name of the Redis persistence journal actor
class = "Akka.Persistence.Redis.Journal.RedisJournal, Akka.Persistence.Redis"
# connection string, as described here: https://github.com/StackExchange/StackExchange.Redis/blob/master/Docs/Configuration.md#basic-configuration-strings
# connection string, as described here: https://stackexchange.github.io/StackExchange.Redis/Configuration#basic-configuration-strings
configuration-string = ""
# Redis journals key prefixes. Leave it for default or change it to appropriate value. WARNING: don't change it on production instances.
Expand All @@ -43,7 +43,7 @@ akka.persistence.journal.redis {
```

### Configuration
- `configuration-string` - connection string, as described here: https://github.com/StackExchange/StackExchange.Redis/blob/master/docs/Configuration.md#basic-configuration-strings
- `configuration-string` - connection string, as described here: https://stackexchange.github.io/StackExchange.Redis/Configuration#basic-configuration-strings
- `key-prefix` - Redis journals key prefixes. Leave it for default or change it to customized value. WARNING: don't change this value after you've started persisting data in production.

## Snapshot Store
Expand All @@ -59,7 +59,7 @@ akka.persistence.snapshot-store.redis {
# qualified type name of the Redis persistence journal actor
class = "Akka.Persistence.Redis.Journal.RedisJournal, Akka.Persistence.Redis"
# connection string, as described here: https://github.com/StackExchange/StackExchange.Redis/blob/master/Docs/Configuration.md#basic-configuration-strings
# connection string, as described here: https://stackexchange.github.io/StackExchange.Redis/Configuration#basic-configuration-strings
configuration-string = ""
# Redis journals key prefixes. Leave it for default or change it to appropriate value. WARNING: don't change it on production instances.
Expand All @@ -68,7 +68,7 @@ akka.persistence.snapshot-store.redis {
```

### Configuration
- `configuration-string` - connection string, as described here: https://github.com/StackExchange/StackExchange.Redis/blob/master/docs/Configuration.md#basic-configuration-strings
- `configuration-string` - connection string, as described here: https://stackexchange.github.io/StackExchange.Redis/Configuration#basic-configuration-strings
- `key-prefix` - Redis journals key prefixes. Leave it for default or change it to appropriate value. WARNING: don't change it on production instances.

## Security and Access Control
Expand Down
42 changes: 3 additions & 39 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,4 @@
#### 1.4.16 February 6th 2021 ####
This is a major update to the Akka.Persistence.Redis plugin.
#### 1.4.17 March 17 2021 ####

**Enabled Redis Cluster Support**
Akka.Persistence.Redis will now automatically detect whether or not you are running in clustered mode via your Redis connection string and will distribute journal entries and snapshots accordingly.

All journal entries and all snapshots for a single entity will all reside inside the same Redis host cost - [using Redis' consistent hash distribution tagging](https://redis.io/topics/cluster-tutorial) scheme.

**Significant Performance Improvements**
Akka.Persistence.Redis' write throughput was improved significantly in Akka.Persistence.Redis v1.4.16:

| Test | Akka.Persistence.Redis v1.4.4 (msg/s) | current PR (msg/s) |
|-----------------|---------------------------------------|--------------------|
| Persist | 782 | 772 |
| PersistAll | 15019 | 20275 |
| PersistAsync | 9496 | 13131 |
| PersistAllAsync | 32765 | 44776 |
| PersistGroup10 | 611 | 6523 |
| PersistGroup100 | 8878 | 12533 |
| PersistGroup200 | 9598 | 12214 |
| PersistGroup25 | 9209 | 10819 |
| PersistGroup400 | 9209 | 11824 |
| PersistGroup50 | 9506 | 9704 |
| Recovering | 17374 | 20119 |
| Recovering8 | 36915 | 37290 |
| RecoveringFour | 22432 | 20884 |
| RecoveringTwo | 22209 | 21222 |

These numbers were generated running a single Redis instance inside a Docker container on Docker for Windows - real-world values generated in cloud environments will likely be much higher.

**Removed Akka.Persistence.Query Support**
In order to achieve support for clustering and improved write performance, we made the descision to drop Akka.Persistence.Query support from Akka.Persistence.Redis at this time - if you wish to learn more about our decision-making process or if you are affected by this change, please comment on this thread here: https://github.com/akkadotnet/Akka.Persistence.Redis/issues/126

**Other Changes**

- Bump [Akka.NET to version 1.4.16](https://github.com/akkadotnet/akka.net/releases/tag/1.4.16)
- Modernized Akka.NET Serialization calls
- [Added benchmarks](https://github.com/akkadotnet/Akka.Persistence.Redis/pull/118)
- Upgraded to [StackExchange.Redis 2.2.11](https://github.com/StackExchange/StackExchange.Redis/blob/main/docs/ReleaseNotes.md)
- Improved documentation
* Upgraded to [Akka.NET 1.4.17](https://github.com/akkadotnet/akka.net/releases/tag/1.4.17)
* [Added Akka.Persistence.Query support for EventsByPersistenceId back](https://github.com/akkadotnet/Akka.Persistence.Redis/pull/133)
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="$(FluentAssertionsVersion)" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 1 addition & 2 deletions src/Akka.Persistence.Redis.Cluster.Tests/DbUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
// </copyright>
// -----------------------------------------------------------------------

using System.Linq;
using StackExchange.Redis;

namespace Akka.Persistence.Redis.Cluster.Test
namespace Akka.Persistence.Redis.Cluster.Tests
{
public static class DbUtils
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Akka.Configuration;
using Akka.Persistence.Query;
using Akka.Persistence.Redis.Query;
using Akka.Persistence.TCK.Query;
using Xunit;
using Xunit.Abstractions; //-----------------------------------------------------------------------
// <copyright file="RedisCurrentEventsByPersistenceIdSpec.cs" company="Akka.NET Project">
// Copyright (C) 2017 Akka.NET Contrib <https://github.com/AkkaNetContrib/Akka.Persistence.Redis>
// </copyright>
//-----------------------------------------------------------------------

namespace Akka.Persistence.Redis.Cluster.Tests.Query
{
[Collection("RedisClusterSpec")]
public class RedisCurrentEventsByPersistenceIdSpec : CurrentEventsByPersistenceIdSpec
{
public static Config Config(RedisClusterFixture fixture)
{
DbUtils.Initialize(fixture);

return ConfigurationFactory.ParseString($@"
akka.loglevel = INFO
akka.persistence.journal.plugin = ""akka.persistence.journal.redis""
akka.persistence.journal.redis {{
class = ""Akka.Persistence.Redis.Journal.RedisJournal, Akka.Persistence.Redis""
plugin-dispatcher = ""akka.actor.default-dispatcher""
configuration-string = ""{fixture.ConnectionString}""
}}
akka.test.single-expect-default = 3s")
.WithFallback(RedisPersistence.DefaultConfig());
}

public RedisCurrentEventsByPersistenceIdSpec(ITestOutputHelper output, RedisClusterFixture fixture)
: base(Config(fixture), nameof(RedisCurrentEventsByPersistenceIdSpec), output)
{
ReadJournal = Sys.ReadJournalFor<RedisReadJournal>(RedisReadJournal.Identifier);
}

protected override void Dispose(bool disposing)
{
DbUtils.Clean();
base.Dispose(disposing);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//-----------------------------------------------------------------------
// <copyright file="RedisEventsByPersistenceIdSpec.cs" company="Akka.NET Project">
// Copyright (C) 2017 Akka.NET Contrib <https://github.com/AkkaNetContrib/Akka.Persistence.Redis>
// </copyright>
//-----------------------------------------------------------------------

using Akka.Configuration;
using Akka.Persistence.Query;
using Akka.Persistence.Redis.Query;
using Akka.Persistence.TCK.Query;
using Xunit;
using Xunit.Abstractions;

namespace Akka.Persistence.Redis.Cluster.Tests.Query
{
[Collection("RedisClusterSpec")]
public class RedisEventsByPersistenceIdSpec : EventsByPersistenceIdSpec
{
public static Config Config(RedisClusterFixture fixture)
{
DbUtils.Initialize(fixture);

return ConfigurationFactory.ParseString($@"
akka.loglevel = INFO
akka.persistence.journal.plugin = ""akka.persistence.journal.redis""
akka.persistence.journal.redis {{
class = ""Akka.Persistence.Redis.Journal.RedisJournal, Akka.Persistence.Redis""
plugin-dispatcher = ""akka.actor.default-dispatcher""
configuration-string = ""{fixture.ConnectionString}""
}}
akka.test.single-expect-default = 3s")
.WithFallback(RedisPersistence.DefaultConfig());
}

public RedisEventsByPersistenceIdSpec(ITestOutputHelper output, RedisClusterFixture fixture)
: base(Config(fixture), nameof(RedisEventsByPersistenceIdSpec), output)
{
ReadJournal = Sys.ReadJournalFor<RedisReadJournal>(RedisReadJournal.Identifier);
}

protected override void Dispose(bool disposing)
{
DbUtils.Clean();
base.Dispose(disposing);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
using Docker.DotNet.Models;
using Xunit;

namespace Akka.Persistence.Redis.Cluster.Test
namespace Akka.Persistence.Redis.Cluster.Tests
{
[CollectionDefinition("RedisClusterSpec")]
public sealed class RedisSpecsFixture : ICollectionFixture<RedisClusterFixture>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
// </copyright>
// -----------------------------------------------------------------------

using System;
using Akka.Configuration;
using Akka.Persistence.TestKit.Performance;
using Xunit;
using Xunit.Abstractions;

namespace Akka.Persistence.Redis.Cluster.Test
namespace Akka.Persistence.Redis.Cluster.Tests
{
[Collection("RedisClusterSpec")]
public class RedisJournalPerfSpec : JournalPerfSpec
Expand Down
53 changes: 52 additions & 1 deletion src/Akka.Persistence.Redis.Cluster.Tests/RedisJournalSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,24 @@
// </copyright>
// -----------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using Akka.Configuration;
using Akka.Persistence.TCK.Journal;
using FluentAssertions;
using StackExchange.Redis;
using Xunit;
using Xunit.Abstractions;

namespace Akka.Persistence.Redis.Cluster.Test
namespace Akka.Persistence.Redis.Cluster.Tests
{
[Collection("RedisClusterSpec")]
public class RedisJournalSpec : JournalSpec
{
private readonly RedisClusterFixture _fixture;

public static Config Config(RedisClusterFixture fixture)
{
DbUtils.Initialize(fixture);
Expand All @@ -33,6 +41,8 @@ class = ""Akka.Persistence.Redis.Journal.RedisJournal, Akka.Persistence.Redis""
public RedisJournalSpec(ITestOutputHelper output, RedisClusterFixture fixture)
: base(Config(fixture), nameof(RedisJournalSpec), output)
{
_fixture = fixture;

RedisPersistence.Get(Sys);
Initialize();
}
Expand All @@ -44,5 +54,46 @@ protected override void Dispose(bool disposing)
base.Dispose(disposing);
DbUtils.Clean();
}

[Fact]
public void Randomly_distributed_RedisKey_with_HashTag_should_be_distributed_relatively_equally_between_cluster_master()
{
var totalEntries = 10000;

var redis = ConnectionMultiplexer.Connect(_fixture.ConnectionString);
var db = redis.GetDatabase();
var journalHelper = new JournalHelper(Sys, "foo");
var dict = new Dictionary<EndPoint, int>();

for (var i = 0; i < totalEntries; ++i)
{
var id = $"{Guid.NewGuid():N}-{i}";
var ep = db.IdentifyEndpoint(journalHelper.GetJournalKey(id, true));
if (!dict.TryGetValue(ep, out _))
{
dict[ep] = 1;
}
else
{
dict[ep]++;
}
}

var values = dict.Values.AsEnumerable().ToArray();

// Evaluate standard deviation
var standardDeviation = StandardDeviation(values);
Output.WriteLine($"Server assignment distribution: [{string.Join(",", values)}]. Standard deviation: [{standardDeviation}]");

// Should be less than 1 percent of total keys
StandardDeviation(values).Should().BeLessThan(totalEntries * 0.01);
}

private double StandardDeviation(int[] values)
{
var mean = values.Average();
var sum = values.Sum(d => Math.Pow(d - mean, 2));
return Math.Sqrt((sum) / (values.Count() - 1));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using FluentAssertions;
using Xunit;

namespace Akka.Persistence.Redis.Cluster.Test
namespace Akka.Persistence.Redis.Cluster.Tests
{
public class RedisSettingsSpec : Akka.TestKit.Xunit2.TestKit
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using Xunit;
using Xunit.Abstractions;

namespace Akka.Persistence.Redis.Cluster.Test
namespace Akka.Persistence.Redis.Cluster.Tests
{
[Collection("RedisClusterSpec")]
public class RedisSnapshotStoreSpec : SnapshotStoreSpec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using Xunit;
using Xunit.Abstractions;

namespace Akka.Persistence.Redis.Cluster.Test.Serialization
namespace Akka.Persistence.Redis.Cluster.Tests.Serialization
{
[Collection("RedisClusterSpec")]
public class RedisJournalSerializationSpec : JournalSerializationSpec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using Xunit;
using Xunit.Abstractions;

namespace Akka.Persistence.Redis.Cluster.Test.Serialization
namespace Akka.Persistence.Redis.Cluster.Tests.Serialization
{
[Collection("RedisClusterSpec")]
public class RedisSnapshotStoreSerializationSpec : SnapshotStoreSerializationSpec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="$(FluentAssertionsVersion)" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit bd9ec73

Please sign in to comment.