I am performing loading tests (250 requests/s) on a project, and the database CPU (Azure SQL) quickly reaches 100%.
In the diagnostics, it tells me that the query is being executed millions of times.
(@0 int) SELECT value FROM umbracoLock WITH (REPEATABLEREAD) WHERE id=@0
I looked into the code, specifically the content service:
public IContent? GetById(Guid key)
{
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
{
scope.ReadLock(Constants.Locks.ContentTree);
return _documentRepository.Get(key);
}
}
Before returning the content, it executes the lock instruction.
The Get method fetches the data from the cache :
public TEntity? Get(TId? id) => CachePolicy.Get(id, PerformGet, PerformGetAll);
My question is: If this is retrieving from the cache, why is it hitting the database for a lock first?
Isn't the whole point of having a cache to avoid unnecessary database access?
Please correct me if my logic is wrong, or does anyone have a solution for the 100% CPU issue?
As far as I know, the ContentService will always query the database, since it's use is centered around content manipulation and not displaying the content.
It would help us a lot to know which code you're performance testing as bad-practice content queries can have a very serious impact on performance.
Granted, I don't know which version of Umbraco you're using and not how you're querying for content.
My advise, based on the limited information you're providing, I would suggest you try and look at the specific query code you have that could call the database.
You should determine if this is actually required and what you need.
If it isn't strictly required to have the raw data from the database, then you should switch over to a cached service.
This could come in the form of IPublishedContentQuery, or if you're inside a razor page, then do the query directly on the @Model
Millions of "SELECT value FROM umbracoLock"
I am performing loading tests (250 requests/s) on a project, and the database CPU (Azure SQL) quickly reaches 100%.
In the diagnostics, it tells me that the query is being executed millions of times.
I looked into the code, specifically the content service:
Before returning the content, it executes the lock instruction. The Get method fetches the data from the cache :
My question is: If this is retrieving from the cache, why is it hitting the database for a lock first? Isn't the whole point of having a cache to avoid unnecessary database access?
Please correct me if my logic is wrong, or does anyone have a solution for the 100% CPU issue?
Not sure how the caching works but just a thought - is MainDomLock set to SqlMainDomLock?
In that case reading from a cache (which might be a resource shared with other sites), will cause that lock to be set in db.
As far as I know, the
ContentService
will always query the database, since it's use is centered around content manipulation and not displaying the content.It would help us a lot to know which code you're performance testing as bad-practice content queries can have a very serious impact on performance.
Granted, I don't know which version of Umbraco you're using and not how you're querying for content.
My advise, based on the limited information you're providing, I would suggest you try and look at the specific query code you have that could call the database.
You should determine if this is actually required and what you need.
If it isn't strictly required to have the raw data from the database, then you should switch over to a cached service.
This could come in the form of IPublishedContentQuery, or if you're inside a razor page, then do the query directly on the
@Model
is working on a reply...