将 AzureSearch SDK 与包含 30-40 个 ISearchIndexClient 的静态字典一起使用的含义
Implications of using AzureSearch SDK with static Dictionary of 30-40 ISearchIndexClients
我有一个 ASP.NET Web 应用程序,它在 5-6 个搜索服务中使用 30-40 个不同的搜索索引(各种客户端处于不同的定价层)。
目前,我正在整理 ISearchServiceClient 的新实例,然后是适当的 ISearchIndexClient ,用于根据客户端制作所需的特定索引电话。
为了提高性能,我正在考虑在应用程序启动时整理所有 ISearchIndexClients 并将它们放入 Dictionary 对象中:
public static Dictionary<String, SearchIndexClient> SearchIndexes;
以便可以直接从静态字典中调用任何特定索引并像这样使用:
SearchIndexes["IndexName"].Documents.Search(searchText, searchParameters);
我希望这会加快查询和索引更新时间,尤其是在 "hot" 索引上。我担心这可能会引入内存泄漏、性能问题和其他未知因素。
我还没有看到任何使用静态可用 SearchServiceClient 或 SearchIndexClient 的示例,因此我对继续使用这种方法感到有些不安。我对社区的问题是:
- 我的计划合理吗?
- 它真的会提高性能吗?
- 有什么缺点或影响(如果有的话?)
- 如果索引的数量随着时间的推移而增加(例如增加到 60-70),那么我会开始看到缺点吗?
将 SearchServiceClients 编组到字典中并连接到适当的 SearchIndexClient 是否更有意义有需要像这样:
public static Dictionary<String, SearchServiceClient> SearchServices;
var searchIndexClient = SearchServices["ServiceName"].Indexes.GetClient("IndexName");
searchIndexClient.Documents.Search(searchText, searchParameters);
此策略可能无法扩展到您想要的索引数量。最可能的结果是您将耗尽可用 TCP 连接池。更好的方法是实现 SearchIndexClient
个实例的缓存,这些实例以索引名称为键。在缓存未命中时,您可以获得对 least-recently-used 客户端的独占访问权并在其上设置 IndexName 属性。该可设置 属性 已添加到 SearchIndexClient
中,正是针对这种情况(请注意,它取代了已弃用的 TargetDifferentIndex
方法)。
您可以在 GitHub, the MSDN forums, and 上找到更多关于分享 SearchIndexClients
的影响的讨论和背景信息。
我有一个 ASP.NET Web 应用程序,它在 5-6 个搜索服务中使用 30-40 个不同的搜索索引(各种客户端处于不同的定价层)。
目前,我正在整理 ISearchServiceClient 的新实例,然后是适当的 ISearchIndexClient ,用于根据客户端制作所需的特定索引电话。
为了提高性能,我正在考虑在应用程序启动时整理所有 ISearchIndexClients 并将它们放入 Dictionary 对象中:
public static Dictionary<String, SearchIndexClient> SearchIndexes;
以便可以直接从静态字典中调用任何特定索引并像这样使用:
SearchIndexes["IndexName"].Documents.Search(searchText, searchParameters);
我希望这会加快查询和索引更新时间,尤其是在 "hot" 索引上。我担心这可能会引入内存泄漏、性能问题和其他未知因素。
我还没有看到任何使用静态可用 SearchServiceClient 或 SearchIndexClient 的示例,因此我对继续使用这种方法感到有些不安。我对社区的问题是:
- 我的计划合理吗?
- 它真的会提高性能吗?
- 有什么缺点或影响(如果有的话?)
- 如果索引的数量随着时间的推移而增加(例如增加到 60-70),那么我会开始看到缺点吗?
将 SearchServiceClients 编组到字典中并连接到适当的 SearchIndexClient 是否更有意义有需要像这样:
public static Dictionary<String, SearchServiceClient> SearchServices; var searchIndexClient = SearchServices["ServiceName"].Indexes.GetClient("IndexName"); searchIndexClient.Documents.Search(searchText, searchParameters);
此策略可能无法扩展到您想要的索引数量。最可能的结果是您将耗尽可用 TCP 连接池。更好的方法是实现 SearchIndexClient
个实例的缓存,这些实例以索引名称为键。在缓存未命中时,您可以获得对 least-recently-used 客户端的独占访问权并在其上设置 IndexName 属性。该可设置 属性 已添加到 SearchIndexClient
中,正是针对这种情况(请注意,它取代了已弃用的 TargetDifferentIndex
方法)。
您可以在 GitHub, the MSDN forums, and SearchIndexClients
的影响的讨论和背景信息。