Optimize for performance
Default optimizations
The .NET Core Renderer application communicates with the CMS through HTTP calls over the IRestClient interface.
Sitefinity has the following calls optimized out-of-the-box:
- The web service responses from coming from Sitefinity CMS are cached.
- The Renderer leverages its own internal per-request cache.
This way, it does not send duplicate CMS requests during the execution of a single page render request. - For faster communication, the
IRestClientuses the HTTP 2 protocol underneath. - The Renderer uses page-level caching to cash the entire page.
For more information, see Configure output cache.
Recommended optimizations
In addition to the above optimizations, you can further optimize the requests to Sitefinity CMS in the following ways:
-
Fetch only the data that you need.
When fetching a collection of items usingIRestClient.GetItems, make sure to pass a filter,SkipandTake, andFieldsas parameters to fetch the minimum amount of data that is needed.
This is useful, because when the response comes in the HTTP protocol, it is in text format (JSON) and can get big, if the amount of data requested is large. -
Avoid N+1 requests.
For example, if you fetch the items for a given collection of taxons, instead of making a request to the CMS for every taxon, consider combining them into a single request.EXAMPLE: You can see examples at Sitefinity GitHub Repository » Filter items.
-
To check how many requests each page makes and which
ViewComponentis making them, you can use page diagnostics.
For more information, see Diagnostics and Troubleshooting » Page diagnostics.
Long running and bulky requests are problematic and you should avoided them, if possible. -
Sitefinity CMS and the Renderer must be closely deployed - in the same network.
This way, you achieve a minimum roundtrip time for each request. -
To fetch a collection of items for multiple
MixedContentContextobjects, use the helper methods in the namespaceProgress.Sitefinity.AspNetCore.RestSdk.EXAMPLE: You can see examples at Sitefinity GitHub Repository » SelectorDemoUsageViewComponent.cs.
-
Use
IHttpClientFactoryfor making requests to external services.
Using this interface is recommended by Microsoft, because theIHttpClientFactoryreuses the same underlying TCP connection and automatically opens a new connection, if there is the need to.
UsingHttpClientand disposing it puts the underlying connection in aTIME_WAITstate, therefore blocking it for use. -
When possible, use HTTP2 protocol when making web requests.