Entity Framework Core 3.1.3 very slow first query used within AWS Lambda Function(s) and AWS API Gateway serverless API
I encountered this exact issue (hence bringing me here).My lambda was only allocated 128MB and was taking 17 seconds to build up EF.On upping the memory to 2048MB, the same process was reduced to 1 second.The lambda actually only required 168 MB but of course, that's more than the original 128MB.
please try this...
var dupeEmailCustomers = ( from c in loyalty.ContactInformation join cu in loyalty.Customer on c.CustomerInternalId equals cu.CustomerInternalId where cu.Status == Customer.CustomerStates.Active && c.ContactType == "EMAIL" select c ).AsNoTracking() .Union( from c in loyalty.ContactInformation join cu in loyalty.Customer on c.CustomerInternalId equals cu.CustomerInternalId where c.ContactType == "EMAIL" && cu.Status != Customer.CustomerStates.Active && testArray.Contains(cu.StatusReason) select c ).AsNoTracking();
test the timing on these seperately
from c in loyalty.ContactInformation join cu in loyalty.Customer on c.CustomerInternalId equals cu.CustomerInternalId where cu.Status == Customer.CustomerStates.Active && c.ContactType == "EMAIL" select c
and
from c in loyalty.ContactInformation join cu in loyalty.Customer on c.CustomerInternalId equals cu.CustomerInternalId where c.ContactType == "EMAIL" && cu.Status != Customer.CustomerStates.Active && testArray.Contains(cu.StatusReason) select c
you could be missing index.... try add index on ContactType and Status and check out if you need one on StatusReason