Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IGNITE-23703 .NET: Add client pool #4763

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

ptupitsyn
Copy link
Contributor

@ptupitsyn ptupitsyn commented Nov 20, 2024

Add IgniteClientPool to simplify DI integration.

IgniteClient.StartAsync is asynchronous and can't be easily used in DI containers, which typically require a synchronous factory method. Also, multiple client instances might be required for high load scenarios.

Usage example:

// Register in DI container
builder.Services.AddSingleton<IgniteClientPool>(_ => new IgniteClientPool(
        new IgniteClientPoolConfiguration
        {
            Size = 3,
            ClientConfiguration = new("localhost"),
        }));

...

// Invoke in a controller
public async Task<IActionResult> Index([FromServices] IgniteClientPool ignite)
{
    var client = await ignite.GetClientAsync();
    var tables = await client.Tables.GetTablesAsync();
    return Ok(tables);
}

@ptupitsyn ptupitsyn self-assigned this Nov 20, 2024
@gurustron
Copy link
Contributor

Maybe move the following:

builder.Services.AddSingleton<IgniteClientPool>(_ => new IgniteClientPool(

Into a specific AddIgniteClientPool method accepting setup action.

int index = Interlocked.Increment(ref _clientIndex) % _clients.Length;

IgniteClientInternal? client = _clients[index];
if (client is { IsDisposed: false })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not thread safe =)))

@gurustron
Copy link
Contributor

Maybe follow the factory pattern - as EF Core does with IDbContextFactory? Pool without returning to the pool is a bit confusing TBH.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants