Home:ALL Converter>Sometimes Entity Framewok queries are very slow

Sometimes Entity Framewok queries are very slow

Ask Time:2019-11-28T18:28:34         Author:FrankDrebin893

Json Formatter

We have the following piece of code:

        public async Task<bool> AreConsumerIdAndSecretExistAsync(AuthenticateConsumerRequest request)
    {
        return await _pplEntities.ApiConsumers.AnyAsync(ac =>
            ac.ConsumerId.Equals(request.ConsumerId) && ac.ConsumerSecret.Equals(request.ConsumerSecret));
    }

This queries a table containing only three rows of data. For some reason, it sometimes takes a long time to execute the above method. It's not the only place, where this issue occurs. It seems like in other places that run multiple SQL queries, it takes a long time to run the first queries, and other queries seem to be problem free. If I run the application locally, it's very fast, except for the first query.

Below is a picture of a New Relic trace showing how slow the application is. In other environments, we experience that the whole request takes upwards of 15 seconds; it's very confusing.

We're running on .NET 4.6.1.

enter image description here

Author:FrankDrebin893,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/59086689/sometimes-entity-framewok-queries-are-very-slow
yy