Launch price: every exam for $29.99 a year, for the first 300 buyers. See the price

CertStreak
Menu

Implement connection optimization to improve throughput and minimize latency

A worked example

Single answer

A .NET recommendation service uses Npgsql to run vector queries against a single database in Azure Database for PostgreSQL. Three components run in the same application process and create connections directly using new NpgsqlConnection(connectionString). Each component builds its own connection string. The strings are otherwise identical, but each sets a different Maximum Pool Size value.

Monitoring shows far more open server connections than the team expects. You need to make sure that all components share a single connection pool, without adding packages to the solution.

What should you do?

Choose one answer
Why

Npgsql enables pooling by default. With connections constructed directly from connection strings in the same process, using identical strings lets the components share a pool. Standardizing the strings removes the separate pools caused by their different maximum-size settings, without requiring another package.

  • Not correct: Add the psycopg_pool package to each component. The task forbids new packages, and Npgsql already provides pooling. The cited psycopg_pool package provides pooling for Python psycopg.
  • Not correct: Double Maximum Pool Size in each component's connection string. Doubling the three different values leaves them different, so the components still use separate pools with larger connection limits.
  • Not correct: Add Pooling=false to the connection string in each component. Disabling Npgsql pooling prevents connection reuse through its built-in pools; it does not provide the required shared pool.
  • Correct: Use one identical connection string in all three components. For this connection-creation pattern within one process, Npgsql associates pools with connection strings. Identical strings let all three components use the same built-in pool.

Practise this topic until it's automatic.

Ten questions a day, every answer explained, and misses that come back until you beat them.

Start free