C
C#14mo ago
Senpawaii

✅ Weird values on accessing Database using EF DbContext under throughput load test

Hello! I'm testing an ASP.NET application that uses an SQL Database. To access this database I define a dependency service, that I add to my set of services in the following manner:
services.AddEntityFrameworkSqlServer()
.AddDbContext<DiscountContext>(options => {
options.UseSqlServer(configuration["ConnectionString"],
sqlServerOptionsAction: sqlOptions => {
sqlOptions.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name);
sqlOptions.EnableRetryOnFailure(maxRetryCount: 15, maxRetryDelay: TimeSpan.FromSeconds(30), errorNumbersToAdd: null);
});
});
services.AddEntityFrameworkSqlServer()
.AddDbContext<DiscountContext>(options => {
options.UseSqlServer(configuration["ConnectionString"],
sqlServerOptionsAction: sqlOptions => {
sqlOptions.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name);
sqlOptions.EnableRetryOnFailure(maxRetryCount: 15, maxRetryDelay: TimeSpan.FromSeconds(30), errorNumbersToAdd: null);
});
});
From my understanding a Db Connection is opened and closed in the scope of each request to my application, that is, each request uses its own connection to the Db. Upon testing my application, by varying the throughput of requests to the application, I notice that for lower throughput values the average access to the database is around 20ms. Under load, this value drops to 6ms/req. The executed queries are the same. I would assume that since each request uses its own connection (from the connection pool), the average latency would increase as I increase the throughput. Am I missing any "special" feature of EF that optimizes the accesses to the Db transparently in the background as the load increases? If this question isn't clear, please feel free to note it, I will try to explain it better 😄 thanks
4 Replies
Senpawaii
Senpawaii14mo ago
I should add that all the queries return the expected values (both under load and not under load).
JakenVeina
JakenVeina14mo ago
there's a loooooooooooooooot of things that could be responsible it could be EF caching query compilations it could be the .NET runtime itself applying more aggressive JIT optimizations it could be the database doing some amount of compilation or results caching you are correct in your description of how connections are managed each request gets its own DbConnection object, which pulls actual connections from an underlying connection pool, which grows and shrinks as needed so, under heavy load, you are skipping most or all of the overhead of establishing database connections that could also account for reduced latency
Senpawaii
Senpawaii14mo ago
Ok, I think I get it! Thanks 😄
Accord
Accord14mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts
Properties of IConfigurationSection.Get are null?I have a very simple test case set up using Microsoft.Extensions.Configuration and Microsoft.ExtensiHow do I pass data from my partial view to my main layout in ASP Core?I have this code in my partial view: ``` // Partial View Lesson.html @{ ViewData["LessonTitle"] ✅ [wpf] how to solve autometically closed new window when I create new window..In StickyNotesView.xaml , I create new Window but If I click '+' that new window not only undisplayePlugin attempts to load dependency again, despite it already being loaded?I have a .NET (.NET 7, for posterity) hosting from C++ situation. I followed the .NET hosting tutori❔ Pathing error issue in forms app, only on LinuxHey! So i have this issue currently which i've been somewhat mindboggled over , basically all this f❔ Setting up C# in VSCodeSo I'm trying to learn c# right now, but when I try to run a test program, it just throws an error: ❔ Pan and zoom control zooms into the top left once the content width exceeds the parent width (WPF)I made a control similar to the view box with a horizontal/vertical offset (for panning) and a zoom ❔ how to use List that have struct type ( WPF)public struct Linq { public Window win; public TextBox textBox; } private void newWin❔ My character gets stuck in the falling animation , need help (Unity/ 2D)Hi! I'm having an issue I've been dealing with for a while now and decided to ask on here. In my 2D ❔ Opensource project for AWS deployment?Hi guys! Does anyone know of some open source web app project in ASP.NET that would be suitable for