gpt4 book ai didi

c# - 将 AzureSearch SDK 与 30-40 个 ISearchIndexClient 的静态字典结合使用的影响

转载 作者:行者123 更新时间:2023-12-03 01:49:04 25 4
gpt4 key购买 nike

我有一个 ASP.NET Web 应用程序,它在 5-6 个搜索服务中使用 30-40 个不同的搜索索引(不同的客户端处于不同的定价级别)。

目前,我正在编码 ISearchServiceClient 的新实例,然后根据进行调用的客户端为所需的特定索引编码适当的 ISearchIndexClient

为了提高性能,我正在考虑在应用程序启动时整理所有 ISearchIndexClients 并将它们放入 Dictionary 对象中:

public static Dictionary<String, SearchIndexClient> SearchIndexes;

这样任何特定的索引都可以直接从静态字典中调用并使用,如下所示:

SearchIndexes["IndexName"].Documents.Search(searchText, searchParameters);

我希望这将加快查询和索引更新时间,尤其是在“热”索引上。我担心这可能会导致内存泄漏、性能问题和其他未知问题。

我还没有看到任何使用静态可用的 SearchServiceClientSearchIndexClient 的示例,因此我对继续使用这种方法感到有点不安。我向社区提出的问题是:

  1. 我的计划合理吗?
  2. 它真的会提高性能吗?
  3. 有哪些缺点或影响(如果有的话?)
  4. 如果索引数量随着时间的推移而增加(例如增加到 60-70),我会开始看到缺点吗?
  5. SearchServiceClients 编码到字典中并根据需要从那里连接到适当的 SearchIndexClient 是否更有意义,如下所示:

    public static Dictionary<String, SearchServiceClient> SearchServices;

    var searchIndexClient = SearchServices["ServiceName"].Indexes.GetClient("IndexName");
    searchIndexClient.Documents.Search(searchText, searchParameters);

最佳答案

此策略可能无法扩展到您想要的索引数量。最可能的结果是您将耗尽可用 TCP 连接池。更好的方法是实现以索引名称为键的 SearchIndexClient 实例的缓存。在缓存未命中时,您可以获得对最近最少使用的客户端的独占访问权限并设置 IndexName其上的属性(property)。正是针对这种情况,该可设置属性已添加到 SearchIndexClient 中(请注意,它取代了已弃用的 TargetDifferentIndex 方法)。

您可以在 GitHub 上找到有关共享 SearchIndexClients 的影响的更多讨论和背景信息。 ,MSDN forums ,和this related StackOverflow question .

关于c# - 将 AzureSearch SDK 与 30-40 个 ISearchIndexClient 的静态字典结合使用的影响,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41769937/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com