Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Blazor startup compat #5085

Draft
wants to merge 6 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/Akka.sln
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SerializationBenchmarks", "
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DDataStressTest", "examples\Cluster\DData\DDataStressTest\DDataStressTest.csproj", "{44B3DDD6-6103-4E8F-8AC2-0F4BA3CF6B50}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Platforms", "Platforms", "{0E0F71BB-A13C-46C3-AE19-602A3DD5AF35}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Akka.Blazor.Tests", "contrib\platforms\Akka.Blazor.Tests\Akka.Blazor.Tests.csproj", "{6F7ACAF6-AE2E-4B58-84EA-ADB06309CE69}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Samples.Akka.Blazor", "examples\AspNetCore\Samples.Akka.Blazor\Samples.Akka.Blazor.csproj", "{2797D6E2-C00E-4747-8CB4-5D04856E3ED9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1137,6 +1143,30 @@ Global
{44B3DDD6-6103-4E8F-8AC2-0F4BA3CF6B50}.Release|x64.Build.0 = Release|Any CPU
{44B3DDD6-6103-4E8F-8AC2-0F4BA3CF6B50}.Release|x86.ActiveCfg = Release|Any CPU
{44B3DDD6-6103-4E8F-8AC2-0F4BA3CF6B50}.Release|x86.Build.0 = Release|Any CPU
{6F7ACAF6-AE2E-4B58-84EA-ADB06309CE69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6F7ACAF6-AE2E-4B58-84EA-ADB06309CE69}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6F7ACAF6-AE2E-4B58-84EA-ADB06309CE69}.Debug|x64.ActiveCfg = Debug|Any CPU
{6F7ACAF6-AE2E-4B58-84EA-ADB06309CE69}.Debug|x64.Build.0 = Debug|Any CPU
{6F7ACAF6-AE2E-4B58-84EA-ADB06309CE69}.Debug|x86.ActiveCfg = Debug|Any CPU
{6F7ACAF6-AE2E-4B58-84EA-ADB06309CE69}.Debug|x86.Build.0 = Debug|Any CPU
{6F7ACAF6-AE2E-4B58-84EA-ADB06309CE69}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6F7ACAF6-AE2E-4B58-84EA-ADB06309CE69}.Release|Any CPU.Build.0 = Release|Any CPU
{6F7ACAF6-AE2E-4B58-84EA-ADB06309CE69}.Release|x64.ActiveCfg = Release|Any CPU
{6F7ACAF6-AE2E-4B58-84EA-ADB06309CE69}.Release|x64.Build.0 = Release|Any CPU
{6F7ACAF6-AE2E-4B58-84EA-ADB06309CE69}.Release|x86.ActiveCfg = Release|Any CPU
{6F7ACAF6-AE2E-4B58-84EA-ADB06309CE69}.Release|x86.Build.0 = Release|Any CPU
{2797D6E2-C00E-4747-8CB4-5D04856E3ED9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2797D6E2-C00E-4747-8CB4-5D04856E3ED9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2797D6E2-C00E-4747-8CB4-5D04856E3ED9}.Debug|x64.ActiveCfg = Debug|Any CPU
{2797D6E2-C00E-4747-8CB4-5D04856E3ED9}.Debug|x64.Build.0 = Debug|Any CPU
{2797D6E2-C00E-4747-8CB4-5D04856E3ED9}.Debug|x86.ActiveCfg = Debug|Any CPU
{2797D6E2-C00E-4747-8CB4-5D04856E3ED9}.Debug|x86.Build.0 = Debug|Any CPU
{2797D6E2-C00E-4747-8CB4-5D04856E3ED9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2797D6E2-C00E-4747-8CB4-5D04856E3ED9}.Release|Any CPU.Build.0 = Release|Any CPU
{2797D6E2-C00E-4747-8CB4-5D04856E3ED9}.Release|x64.ActiveCfg = Release|Any CPU
{2797D6E2-C00E-4747-8CB4-5D04856E3ED9}.Release|x64.Build.0 = Release|Any CPU
{2797D6E2-C00E-4747-8CB4-5D04856E3ED9}.Release|x86.ActiveCfg = Release|Any CPU
{2797D6E2-C00E-4747-8CB4-5D04856E3ED9}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1245,6 +1275,9 @@ Global
{D62F4AD6-318F-4ECC-B875-83FA9933A81B} = {162F5991-EA57-4221-9B70-F9B6FEC18036}
{2E4B9584-42CC-4D17-B719-9F462B16C94D} = {73108242-625A-4D7B-AA09-63375DBAE464}
{44B3DDD6-6103-4E8F-8AC2-0F4BA3CF6B50} = {C50E1A9E-820C-4E75-AE39-6F96A99AC4A7}
{0E0F71BB-A13C-46C3-AE19-602A3DD5AF35} = {588C1513-FAB6-42C3-B6FC-3485F13620CF}
{6F7ACAF6-AE2E-4B58-84EA-ADB06309CE69} = {0E0F71BB-A13C-46C3-AE19-602A3DD5AF35}
{2797D6E2-C00E-4747-8CB4-5D04856E3ED9} = {162F5991-EA57-4221-9B70-F9B6FEC18036}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {03AD8E21-7507-4E68-A4E9-F4A7E7273164}
Expand Down
74 changes: 72 additions & 2 deletions src/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<Copyright>Copyright © 2013-2021 Akka.NET Team</Copyright>
<Authors>Akka.NET Team</Authors>
<VersionPrefix>1.4.19</VersionPrefix>
<VersionPrefix>1.4.21</VersionPrefix>
<PackageIconUrl>https://getakka.net/images/akkalogo.png</PackageIconUrl>
<PackageProjectUrl>https://github.com/akkadotnet/akka.net</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/akkadotnet/akka.net/blob/master/LICENSE</PackageLicenseUrl>
Expand All @@ -29,7 +29,77 @@
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<PropertyGroup>
<PackageReleaseNotes>Placeholder for nightlies**</PackageReleaseNotes>
<PackageReleaseNotes>Maintenance Release for Akka.NET 1.4**
Akka.NET v1.4.21 is a significant release that includes major performance improvements, bug fixes, and a major update to the [Akka.DependencyInjection NuGet package](https://getakka.net/articles/actors/dependency-injection.html).
Performance Improvements**
Akka.NET v1.4.21 includes some major performance fixes and improvements:
[`Ask` is now ~10% faster](https://github.com/akkadotnet/akka.net/pull/5051)
[`MurmurHash` is 33% faster and allocates 0 memory](https://github.com/akkadotnet/akka.net/pull/5028) - used _heavily_ in DData, Cluster Sharding, and Consistent Hash Routers
`ActorPath.Parse` went from 1672 ns/op to 527 ns/op - a 68% improvement in throughput and a 50% reduction in memory. See [#5039](https://github.com/akkadotnet/akka.net/pull/5039) and [#5068](https://github.com/akkadotnet/akka.net/pull/5068).
[Akka.Remote: remove `ActorPath.ToString` call from `ResolveActorRefWithLocalAddress`](https://github.com/akkadotnet/akka.net/pull/5034)
Important**: [Revert `ThreadPool.SetMinThreads(0,0)`](https://github.com/akkadotnet/akka.net/pull/5059) - based on the input from users on "[Akka.NET v1.4.19: ChannelExecutor performance data](https://github.com/akkadotnet/akka.net/discussions/4983)"
Our observed performance numbers for Akka.Remote show a significant increase in performance for v1.4.21 over v1.4.20:
Before*
```
PS&gt; dotnet run -c Release --framework netcoreapp3.1
OSVersion: Microsoft Windows NT 6.2.9200.0
ProcessorCount: 16
ClockSpeed: 0 MHZ
Actor Count: 32
Messages sent/received per client: 200000 (2e5)
Is Server GC: True
Thread count: 109
Num clients, Total [msg], Msgs/sec, Total [ms]
1, 200000, 113379, 1764.56
5, 1000000, 186429, 5364.05
10, 2000000, 185340, 10791.11
15, 3000000, 183218, 16374.06
20, 4000000, 179824, 22244.63
25, 5000000, 182716, 27365.89
30, 6000000, 182039, 32960.61
```
After*
```
PS&gt; dotnet run -c Release --framework netcoreapp3.1
OSVersion: Microsoft Windows NT 6.2.9200.0
ProcessorCount: 16
ClockSpeed: 0 MHZ
Actor Count: 32
Messages sent/received per client: 200000 (2e5)
Is Server GC: True
Thread count: 111
Num clients, Total [msg], Msgs/sec, Total [ms]
1, 200000, 109770, 1822.14
5, 1000000, 192902, 5184.79
10, 2000000, 191663, 10435.53
15, 3000000, 191339, 15679.11
20, 4000000, 192725, 20755.78
25, 5000000, 189754, 26350.14
30, 6000000, 189772, 31617.20
```
&gt; N.B. these after numbers don't benefit from the performance benefits we observed in v1.4.20 when we invoked `ThreadPool.SetMinThreads(0,0)`, which makes them even more impressive.
Akka.DependencyInjection Updates**
We had one major issue we implemented in v1.4.21 for Akka.DependencyInjection: [Abstraction of `ServiceProvider`, Improving Akka.DependencyInjection ](https://github.com/akkadotnet/akka.net/pull/4814)
What this change did was:
Deprecate the `Akka.DependencyInjection.ServiceProvider` class in favor of the `Akka.DependencyInjection.DependencyResolver` class - to avoid namespace collision with Microsoft.Extensions.DependencyInjection.ServiceProvider;
Deprecates the `Akka.DependencyInjection.ServiceProviderSetup` class in favor of the `Akka.DependencyInjection.DependencyResolverSetup` class for consistency reasons;
`Akka.DependencyInjection.DependencyResolver` now takes an input of type [`IDependencyResolver`](https://getakka.net/api/Akka.DependencyInjection.IDependencyResolver.html), which allows users to abstract away the `IServiceProvider` and mock / replace it during unit testing; and
Added some non-generic `Props` methods for dynamically spawning actors via DI.
All of these changes are backwards-compatible with v1.4.20 and earlier - and the deprecation warnings will appear in your code when you upgrade. If you run into any [issues upgrading to Akka.DependencyInjection v1.4.21 please reply on this thread](https://github.com/akkadotnet/akka.net/discussions/5070)!
Other Changes and Fixes**
[Akka.Streams: A couple of fixes affecting the `FileSubscriber`](https://github.com/akkadotnet/akka.net/pull/5035)
[Akka.DistributedData: memory leak when recovering events from LMDB data store](https://github.com/akkadotnet/akka.net/issues/5022)
[Akka.DistributedData: port `VectorClock` performance optimizations to `VersionVector` and similar types](https://github.com/akkadotnet/akka.net/issues/4956)
To see the [full set of fixes in Akka.NET v1.4.21, please see the milestone on Github](https://github.com/akkadotnet/akka.net/milestone/51).
| COMMITS | LOC+ | LOC- | AUTHOR |
| --- | --- | --- | --- |
| 12 | 999 | 160 | Aaron Stannard |
| 10 | 410 | 299 | Gregorius Soedharmo |
| 4 | 853 | 520 | Ismael Hamed |
| 4 | 5 | 5 | dependabot[bot] |
| 1 | 6 | 2 | Brah McDude |
| 1 | 428 | 67 | Sam Ember |
| 1 | 1 | 1 | Martin |</PackageReleaseNotes>
</PropertyGroup>
<!-- SourceLink support for all Akka.NET projects -->
<ItemGroup>
Expand Down
20 changes: 20 additions & 0 deletions src/contrib/platforms/Akka.Blazor.Tests/Akka.Blazor.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">
<Import Project="..\..\..\common.props" />
<Import Project="..\..\..\xunitSettings.props" />
<PropertyGroup>
<TargetFramework>$(NetTestVersion)</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="bunit" Version="1.1.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
<PackageReference Include="xunit" Version="$(XunitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)" />
<PackageReference Include="FluentAssertions" Version="$(FluentAssertionsVersion)" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\core\Akka.Tests.Shared.Internals\Akka.Tests.Shared.Internals.csproj" />
</ItemGroup>

</Project>
38 changes: 38 additions & 0 deletions src/contrib/platforms/Akka.Blazor.Tests/Counter.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
@using Akka.Actor
@using Akka.Actor.Dsl;
@using Akka.Blazor.Tests.Internal
@using Akka.Configuration
@implements IDisposable;
<h1>Counter</h1>

<p>
Current count: @currentCount
</p>

<button class="btn btn-primary" @onclick="(e => IncrementCount())">Click me</button>

@code {
int currentCount = 0;
private ActorSystem _actorSystem;
private IActorRef _testActor;

protected override void OnInitialized()
{
_actorSystem = ActorSystem.Create("Foo", Config.Empty);
_testActor = _actorSystem.ActorOf(CounterActor.Props, "counter");

base.OnInitialized();
}

async Task IncrementCount()
{
currentCount = await _testActor.Ask<int>(CounterActor.Hit.Instance, TimeSpan.FromSeconds(3));
StateHasChanged();
}

public void Dispose()
{
_actorSystem?.Dispose();
}

}
37 changes: 37 additions & 0 deletions src/contrib/platforms/Akka.Blazor.Tests/CounterCSharpTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using Bunit;
using Bunit.TestDoubles;
using Xunit;

namespace Akka.Blazor.Tests
{
/// <summary>
/// These tests are written entirely in C#.
/// Learn more at https://bunit.egilhansen.com/docs/getting-started/
/// </summary>
public class CounterCSharpTests : TestContext
{
[Fact]
public void CounterStartsAtZero()
{
// Arrange
var cut = RenderComponent<Counter>();

// Assert that content of the paragraph shows counter at zero
cut.Find("p").MarkupMatches("<p>Current count: 0</p>");
}

[Fact]
public void ClickingButtonIncrementsCounter()
{
// Arrange
var cut = RenderComponent<Counter>();

// Act - click button to increment counter
cut.Find("button").Click();

// Assert that the counter was incremented
cut.Find("p").MarkupMatches("<p>Current count: 1</p>");
}
}
}
33 changes: 33 additions & 0 deletions src/contrib/platforms/Akka.Blazor.Tests/Internal/CounterActor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Akka.Actor;

namespace Akka.Blazor.Tests.Internal
{
public sealed class CounterActor : ReceiveActor
{
public static Props Props { get; } = Props.Create(() => new CounterActor(0));

public sealed class Hit
{
public static readonly Hit Instance = new Hit();
private Hit(){}
}

private int _count;

public CounterActor(int count)
{
_count = count;

Receive<Hit>(_ =>
{
_count++;
Sender.Tell(_count);
});
}
}
}
6 changes: 6 additions & 0 deletions src/contrib/platforms/Akka.Blazor.Tests/_Imports.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.JSInterop
@using Microsoft.Extensions.DependencyInjection
@using Bunit
@using Bunit.TestDoubles
@using Xunit
3 changes: 0 additions & 3 deletions src/core/Akka/Actor/Internal/ActorSystemImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,6 @@ public void Start()
{
try
{
// Force TermInfoDriver to initialize in order to protect us from the issue seen in #2432
typeof(Console).GetProperty("BackgroundColor").GetValue(null); // HACK: Only needed for MONO

RegisterOnTermination(StopScheduler);
_provider.Init(this);
LoadExtensions();
Expand Down
5 changes: 2 additions & 3 deletions src/core/Akka/Event/StandardOutLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static StandardOutLogger()
InfoColor = ConsoleColor.White;
WarningColor = ConsoleColor.Yellow;
ErrorColor = ConsoleColor.Red;
UseColors = true;
UseColors = false;
}

/// <summary>
Expand Down Expand Up @@ -67,8 +67,7 @@ protected override void TellInternal(object message, IActorRef sender)
if(message == null)
throw new ArgumentNullException(nameof(message), "The message to log must not be null.");

var logEvent = message as LogEvent;
if (logEvent != null)
if (message is LogEvent logEvent)
{
PrintLogEvent(logEvent);
}
Expand Down
47 changes: 47 additions & 0 deletions src/examples/AspNetCore/Samples.Akka.Blazor/Actors/CounterActor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Akka.Actor;

namespace Samples.Akka.Blazor.Actors
{
public class CounterActor : UntypedActor
{
public static Props Props { get; } = Props.Create(() => new CounterActor());

public sealed class Hit
{
public static readonly Hit Instance = new();
private Hit() { }
}

public sealed class Get
{
public static readonly Get Instance = new();
private Get() { }
}

private int _count = 0;
protected override void OnReceive(object message)
{
switch (message)
{
case Hit _:
{
_count++;
Sender.Tell(_count);
break;
}
case Get _:
{
Sender.Tell(Get.Instance);
break;
}
default:
Unhandled(message);
break;
}
}
}
}
10 changes: 10 additions & 0 deletions src/examples/AspNetCore/Samples.Akka.Blazor/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Router AppAssembly="@typeof(Program).Assembly" PreferExactMatches="@true">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
29 changes: 29 additions & 0 deletions src/examples/AspNetCore/Samples.Akka.Blazor/Pages/Counter.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
@page "/counter"
@using Samples.Akka.Blazor.Services
@using System.Threading
@inject ICounterService counterService;

<h1>Counter</h1>

<p>Current count: @currentCount</p>

<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

@code {
private int currentCount = 0;

protected override async Task OnInitializedAsync()
{
//using var cts = new CancellationTokenSource(3000);
//currentCount = await counterService.GetCount(cts.Token);

await base.OnInitializedAsync();
}

async Task IncrementCount()
{
using var cts = new CancellationTokenSource(3000);
currentCount = await counterService.Increment(cts.Token);
StateHasChanged();
}
}
Loading