-
Notifications
You must be signed in to change notification settings - Fork 811
Load balancing backoffice documentation #7545
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
Changes from 7 commits
3258116
c976614
15eaa32
67ab39d
0b29068
e187796
5aa185d
a359f91
69d8f86
6b571b5
d8f0fd1
edf87a4
a387438
add8792
f36fb86
d7debe5
8482136
41bf3c5
78c68be
3becae2
630cc8e
f758cfd
5feb2fe
201786f
8409fea
8258d7b
e4c3109
37566a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| # Load Balancing the Backoffice | ||
|
|
||
| This article contains specific information about load balancing the Umbraco backoffice, ensure you read the [Load Balancing Overview](./) and relevant articles about general load balancing principles before you begin. | ||
|
Check warning on line 3 in 17/umbraco-cms/fundamentals/setup/server-setup/load-balancing/load-balancing-backoffice.md
|
||
nikolajlauridsen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| By default, the Umbraco load balancing setup assumes there are a single backoffice server, and multiple front-end servers. From version 17 it's possible to load balance the backoffice, meaning there's no need to differentiate from backoffice servers and front-end servers, however, this requires some additional configuration steps. | ||
|
Check warning on line 5 in 17/umbraco-cms/fundamentals/setup/server-setup/load-balancing/load-balancing-backoffice.md
|
||
nikolajlauridsen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Server Role Accessor | ||
|
|
||
| Umbraco has the concept of server roles, to differentiate between backoffice servers and front-end servers. Since all servers will be backoffice servers, we need to add a custom `IServerRoleAccessor` to specify this. | ||
eshanrnh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Start by implementing a custom `IServerRoleAccessor` that pins the role as `SchedulingPublisher`: | ||
|
|
||
| ```csharp | ||
| public class StaticServerAccessor : IServerRoleAccessor | ||
| { | ||
| public ServerRole CurrentServerRole => ServerRole.SchedulingPublisher; | ||
| } | ||
| ``` | ||
|
|
||
| You can now register this accessor, either in `Program.cs` or via a Composer: | ||
eshanrnh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```csharp | ||
| umbracoBuilder.SetServerRegistrar(new StaticServerAccessor()); | ||
| ``` | ||
|
|
||
| This will ensure that all servers are treated as backoffice servers. | ||
|
|
||
| ## Load balancing Isolated Caches | ||
nikolajlauridsen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| One of the issues with load balancing the backoffice is that all servers will have their own isolated caches. This means that if you make a change on one server, it won't be reflected on the other servers until their cache expires. | ||
|
|
||
| To solve this issue a cache versioning mechanism is used, this is similar to optimistic concurrency control, where each server has a version number for its cache. When a server makes a change, it changes the version identifier. The other servers can then check the version identifier before accessing the cache and invalidate their cache if it's out of date. | ||
|
Check warning on line 32 in 17/umbraco-cms/fundamentals/setup/server-setup/load-balancing/load-balancing-backoffice.md
|
||
nikolajlauridsen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| This does mean that the server needs to check this version identifier before a cache lookup, so by default this behaviour is disabled as it's only required when load balancing the backoffice. | ||
|
Check warning on line 34 in 17/umbraco-cms/fundamentals/setup/server-setup/load-balancing/load-balancing-backoffice.md
|
||
|
|
||
| You can enable this on the Umbraco builder, either in `Program.cs` or via a Composer: | ||
|
|
||
| ```csharp | ||
| umbracoBuilder.LoadBalanceIsolatedCaches(); | ||
| ``` | ||
|
|
||
| ## SignalR | ||
|
|
||
| The Umbraco Backoffice uses SignalR for multiple things, including real-time updates and notifications. When load balancing the backoffice, it's important to ensure that SignalR is configured correctly. See the [SignalR in a Backoffice Load Balanced Environment](./signalR-in-backoffice-load-balanced-environment.md) document for information regarding this. | ||
|
|
||
|
|
||
| ## Background Jobs | ||
|
|
||
| If you have any custom recurring background jobs that should only run on a single server, you'll need to implement `IDistributedBackgroundJob`, see [Scheduling documentation](../../../../reference/scheduling.md#background-jobs-when-load-balancing-the-backoffice) for more information. | ||
|
Check warning on line 49 in 17/umbraco-cms/fundamentals/setup/server-setup/load-balancing/load-balancing-backoffice.md
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| # SignalR in a Backoffice Load Balanced Environment | ||
| When load balancing the backoffice, we also need to take care of the client to server communication outside of web requests. | ||
eshanrnh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Umbraco uses SignalR to abstract away these types of communication. This also allows us to support load balancing by replacing how the communication is done by introducing a backplane. | ||
|
|
||
| ## Introducing a SignalR Backplane | ||
| A SignalR backplane is akin to a load balancer for direct client to server web traffic. It keeps track of which client is connected to which server. So that when a client sends a message, it arrives at the right server. It also allows any connected server to send a message to all clients, even those that are not directly connected to it. | ||
eshanrnh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Choosing the right backplane | ||
| Choosing the right backplane comes down to a few things | ||
eshanrnh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - Message throughput | ||
| - Cost | ||
| - What infrastructure you already have in place | ||
|
|
||
| Microsoft has a good list of available backplanes in its [SignalR load balancing article](https://learn.microsoft.com/en-us/aspnet/core/signalr/scale?view=aspnetcore-10.0), including a list of well known [third party offerings](https://learn.microsoft.com/en-us/aspnet/core/signalr/scale?view=aspnetcore-9.0#third-party-signalr-backplane-providers). | ||
|
|
||
| ## Code examples | ||
| The following code examples show you how you can activate SignalR load balancing using an Umbraco composer. | ||
eshanrnh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Note: Both Umbraco Core and these composers use `.AddSignalR().` which is ok since the underlying code registers the required services as singletons. | ||
nikolajlauridsen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ### Using existing infrastructure | ||
| It is possible to use your existing database as a backplane. If this database is hosted in Azure it is not possible to enable Service Broker which will have an impact on message throughput. We do however feel that when you start out with load balancing, it might be enough to cover your needs. | ||
nikolajlauridsen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| For more information, check out the [Github page](https://github.com/IntelliTect/IntelliTect.AspNetCore.SignalR.SqlServer). | ||
|
Check warning on line 22 in 17/umbraco-cms/fundamentals/setup/server-setup/load-balancing/signalR-in-backoffice-load-balanced-environment.md
|
||
| - Add a reference to the IntelliTect.AspNetCore.SignalR.SqlServer NuGet package | ||
eshanrnh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - Add the following composer to your project | ||
eshanrnh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ```csharp | ||
| using Umbraco.Cms.Core.Composing; | ||
|
|
||
| namespace Umbraco.Cms.Web.UI.SignalRLoadBalancing; | ||
|
|
||
| public class SignalRComposer : IComposer | ||
| { | ||
| public void Compose(IUmbracoBuilder builder) | ||
| { | ||
| var connectionString = builder.Config.GetUmbracoConnectionString(); | ||
| if (connectionString is null) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| builder.Services.AddSignalR().AddSqlServer(connectionString); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Azure SignalR Service | ||
| - Setup a resource as described in the [Microsoft tutorial](https://learn.microsoft.com/en-us/azure/azure-signalr/signalr-quickstart-dotnet-core#create-an-azure-signalr-resource) | ||
| - Make sure the connectionstring is setup under the following key: `Azure:SignalR:ConnectionString` | ||
| - Add a reference to the Microsoft.Azure.SignalR NuGet package | ||
| - Add the following composer to your project | ||
eshanrnh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ```csharp | ||
| using Umbraco.Cms.Core.Composing; | ||
|
|
||
| namespace Umbraco.Cms.Web.UI.SignalRLoadBalancing; | ||
|
|
||
| public class SignalRComposer : IComposer | ||
| { | ||
| public void Compose(IUmbracoBuilder builder) => builder.Services.AddSignalR().AddAzureSignalR(); | ||
| } | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # Distributed jobs settings | ||
|
|
||
| The distributed jobs settings allow you to configure how Umbraco handles distributed background jobs in a load-balanced environment. | ||
|
|
||
| ## Configuration | ||
| ```json | ||
| "Umbraco": { | ||
| "CMS": { | ||
| "DistributedJobs": { | ||
| "Period": "00:00:05", | ||
| "Delay": "00:01:00" | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Settings | ||
|
|
||
| ### Period | ||
|
|
||
| **Default:** `00:00:05` (5 seconds) | ||
|
|
||
| Specifies how frequently each server checks for distributed background jobs that need to be run. | ||
|
|
||
| A shorter period means jobs are picked up more quickly, but increases the frequency of database queries. A longer period reduces overhead but may introduce delays in job execution. | ||
|
|
||
| ### Delay | ||
|
|
||
| **Default:** `00:01:00` (1 minute) | ||
|
|
||
| Specifies how long the server should wait after initial startup before beginning to check for and run distributed background jobs. This startup delay ensures that the application is fully initialized and stable before participating in distributed job processing. |
Uh oh!
There was an error while loading. Please reload this page.