Changes between Version 2 and Version 3 of AdvancedApplicationDevelopment


Ignore:
Timestamp:
09/09/26 02:48:48 (3 days ago)
Author:
232012
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • AdvancedApplicationDevelopment

    v2 v3  
    55
    66== Pooling
     7
     8{{{#!div style="text-align: justify; width: 100%;"
     9Since the backend of our application is developed using ASP.NET Core with Entity Framework Core and PostgreSQL, database connections are managed through Npgsql.
     10
     11In our project, we use the following dependency:
     12
     13{{{
     14<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.8" />
     15}}}
     16
     17The data source is created in Program.cs using NpgsqlDataSourceBuilder:
     18
     19{{{
     20var dataSourceBuilder = new NpgsqlDataSourceBuilder(
     21    builder.Configuration.GetConnectionString("KernelRecords"));
     22
     23var dataSource = dataSourceBuilder.Build();
     24
     25builder.Services.AddDbContext<KernelRecordsContext>(options =>
     26    options.UseNpgsql(dataSource));
     27}}}
     28
     29Npgsql has built-in connection pooling, and pooling is enabled by default. This means that the application does not need to establish a completely new physical connection to the PostgreSQL database every time a database operation is performed.
     30
     31When the application needs access to the database, Npgsql takes an available connection from the connection pool. After the operation is finished, the connection is returned to the pool and can be reused by another request.
     32
     33In our project, we do not manually change the pooling configuration, so the default Npgsql settings are used. Some of the important default values are:
     34
     35{{{
     36Pooling                  = true
     37Minimum Pool Size        = 0
     38Maximum Pool Size        = 100
     39Connection Idle Lifetime = 300 seconds
     40Timeout                  = 15 seconds
     41}}}
     42
     43If needed, these values can be changed through the connection string.
     44
     45Connection pooling improves application performance and reduces resource usage because existing database connections can be reused instead of opening a new connection for every request.
     46}}}