Azure Kubernetes 服务上的 Apache Ignite 性能问题

Apache Ignite performance problem on Azure Kubernetes Service

我在 Azure Kubernetes 上使用 Apache Ignite 作为分布式缓存。 另外,我在 Azure 上有一个基于 .NET6

的网络 API

Ignite 服务在 AKS 上运行稳定且运行良好。

但是在第一次请求时,API 会尝试连接 Ignite,这需要大约 3 秒的时间。之后,Ignite 响应大约需要 100 毫秒,这非常好。这是 GetProduct 函数的 Web API 性能输出。

起初,我尝试将 Ignite 服务添加到 Singleton,但有时会失败 'connection closed'。如何始终保持打开 Ignite 连接?或者有人有更好的主意吗?

这是我最新的 GetProduct 代码,

[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));
}

此外,我在此处添加 CacheManager class;

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;
}
  1. 使其成为单例。 Ignite 节点,即使在客户端模式下,在应用程序的整个生命周期中都应该是 运行。所有 Ignite API 都是 thread-safe。如果出现连接错误,请提供更多详细信息(异常堆栈跟踪、如何创建单例等)。

  2. 您也可以试试Ignite thin client,消耗资源少,连接瞬间:https://ignite.apache.org/docs/latest/thin-clients/dotnet-thin-client.