Avoiding Getting Throttled
SharePoint Online uses throttling to maintain optimal performance and reliability of the SharePoint Online service. Throttling limits the number of user actions or concurrent calls (by script or code) to prevent overuse of resources.
Every building block uses resources on SharePoint Online and too many of those actions in a short timespan can lead to throttling. Even though the building blocks strive to be as performant as possible and apply best practices to handle trottling, there are some settings available to avoid being throttled.
For more information about throttling, consult the official Microsoft documentation.
Global Security Pages
For optimal performance it's best to only create the security pages on one site collection when working with multiple sites. Creating two security pages adds to the site creation time, thus it's better to only create those pages on one site collection.
Warning
Make sure everyone has access to this site.
1. Execute the 'Ensure Security Pages' Building Block
Execute the Ensure Security Pages building block on the site.
Tip
The redirect client side web part for modern security pages can be found in the setup files.
2. Fill in the Site URL in the Profile
Fill in the GlobalSecurityPagesSiteUrl in the building blocks profile.
Ensure or Delete Multiple Instances with One Building Block
Most building blocks allow you to ensure or delete multiple instances with one building block execution. If you are ensuring 5 different groups for example with the same property but just a different name you can ensure them with one building block by giving the names semicolon separated in the Name field.
Supported Building Bocks
The following building blocks allow multiple instances with one building block execution:
- SharePoint.BuildingBlocks.ContentTypes
- SharePoint.BuildingBlocks.Lists
- SharePoint.BuildingBlocks.Navigation
- SharePoint.BuildingBlocks.Permissions
Consult the API of the building blocks to see which fields support semicolon separated values.
Performance Improvement
Action | Time |
---|---|
Create 5 groups using 5 state actions | 4.12 seconds |
Create 5 groups using a single state action | 1.734 seconds |
In this example you will see a performance improvement of 237% by grouping the creation of the groups in one single building block.
Ensuring Content Types to Lists from Content Type Hub
When working with content types from the content type hub used on multiple lists, make sure to synchronise / pull those content types first before ensuring them to each list. By default the content type is first synchronised from the content type when ensuring a content type to a list. This takes a significant performance hit when ensuring the content type on multiple lists.
Execute the Synchronise ContentType From Hub building block for all the content types used from the content type hub on the site first and make sure the 'Synchronise From Content Type Hub' property is disabled on the 'Ensure ContentType To List' building blocks in your lifecycle configuration.
Ensuring Web Parts on Modern Pages and Publishing
When ensuring web parts on modern pages the page is published by default with every web part building block. Publishing the page for every web part on the page adds a performance penalty. Therefore it's best to only publish the page on the last web part building block for the page.
Configure the building blocks so all web part building blocks except for the last one on the page have the Publish Page disabled.
Use Modern Site Templates on SharePoint Online
Use modern site templates instead of classic site templates when creating sites on SharePoint Online.
- GROUP#0: Modern Team Site with Office 365 Group
- SITEPAGEPUBLISHING#0: Modern Communication Site
- STS#3: Modern Team Site with no Office 365 Group
Configure those templates in the Template field of the lifecycle settings.
Writing Custom Code to SharePoint (Online)
When writing custom code there are some extension methods you can use to avoid being throttled and improve performance. Use the Ometa.Libraries.Internal.All nuget to use those extension methods.
Use the ExecuteQueryWithIncrementalRetry Extension Method
You might be familiar with the ExecuteQueryWithIncrementalRetry extension method in CSOM. Ometa has a custom ExecuteQueryWithIncrementalRetry extension method which sets up a performance group for the whole framework. When throttling occurs in one framework component all requests in the framework are stopped and gradually started again.
Use the CreateClientContext Extension Method
Use the CreateClientContext function to cache the ClientContext connection.
using (var clientContext = Ometa.Utilities.Client.GenericFunctions.CreateClientContext())
Make sure to use the default SharePoint connection parameters in the custom DLL profile:
- Domain
- Username
- Password
- SharePointOnline
- ClientID
- ClientSecret