Search code examples
igniteazure-aks.net-6.0

Apache Ignite performance problem on Azure Kubernetes Service


I'm using Apache Ignite on Azure Kubernetes as a distributed cache. Also, I have a web API on Azure based on .NET6

The Ignite service works stable and very well on AKS.

But at first request, the API tries to connect Ignite and it takes around 3 seconds. After that, Ignite responses take around 100 ms which is great. Here are my Web API performance outputs for the GetProduct function.

enter image description here

At first, I've tried adding the Ignite Service to Singleton but it failed sometimes as 'connection closed'. How can I keep open the Ignite connection always? or does anyone has something better idea?

here is my latest GetProduct code,

[HttpGet("getProduct")]
public IActionResult GetProduct(string barcode)
{
    
    Stopwatch _stopWatch = new Stopwatch();
    _stopWatch.Start();

    Product product;
    CacheManager cacheManager = new CacheManager();
    cacheManager.ProductCache.TryGet(barcode, out product);

    if(product == null)
    {
        return NotFound(new ApiResponse<Product>(product));
    }

    cacheManager.DisposeIgnite();
    
    _logger.LogWarning("Loaded in " + _stopWatch.ElapsedMilliseconds + " ms...");

    return Ok(new ApiResponse<Product>(product));
}

Also, I add CacheManager class here;

public CacheManager()
{
    ConnectIgnite();
    InitializeCaches();
}

public void ConnectIgnite()
{
    _ignite = Ignition.StartClient(GetIgniteConfiguration());
}

public IgniteClientConfiguration GetIgniteConfiguration()
{
    var appSettingsJson = AppSettingsJson.GetAppSettings();

    var igniteEndpoints = appSettingsJson["AppSettings:IgniteEndpoint"];
    var igniteUser = appSettingsJson["AppSettings:IgniteUser"];
    var ignitePassword = appSettingsJson["AppSettings:IgnitePassword"];
    var nodeList = igniteEndpoints.Split(",");

    var config = new IgniteClientConfiguration
        {
            Endpoints = nodeList,
            UserName = igniteUser,
            Password = ignitePassword,
            EnablePartitionAwareness = true,
            SocketTimeout = TimeSpan.FromMilliseconds(System.Threading.Timeout.Infinite)
        };

    return config;
}

Solution

    1. Make it a singleton. Ignite node, even in client mode, is supposed to be running for the entire lifetime of your application. All Ignite APIs are thread-safe. If you get a connection error, please provide more details (exception stack trace, how do you create the singleton, etc).

    2. You can also try the Ignite thin client which consumes fewer resources and connects instantly: https://ignite.apache.org/docs/latest/thin-clients/dotnet-thin-client.