SOLR работает медленно при первом фасетном запросе, но достаточно быстро для последующих запросов.

Я пытаюсь понять, почему мой экземпляр SOLR (4.1) очень медленный для фасетных запросов. Индекс содержит около 200 миллионов документов, а сервер имеет 64 ГБ ОЗУ.

Мой запрос выглядит так:

q=CampaignId:1462%0ASourceDateUtc:[2014-01-01T00:00:00.000Z TO 2014-01-30T00:00:00.000Z]
&wt=xml&indent=true&rows=0
&facet=true&facet.field=UserName&facet.mincount=10&facet.method=fc

Это займет около 6 минут для первого попадания, но когда результат возвращается, я снова ищу с тем же запросом или немного меняю диапазон в SourceDateUtc, он работает довольно быстро.

Вот мой solrconfig.xml (раздел запросов)

<query>
  <!-- Cache used by SolrIndexSearcher for filters (DocSets),
         unordered sets of *all* documents that match a query.
         When a new searcher is opened, its caches may be prepopulated
         or "autowarmed" using data from caches in the old searcher.
         autowarmCount is the number of items to prepopulate.  For LRUCache,
         the autowarmed items will be the most recently accessed items.
       Parameters:
         class - the SolrCache implementation (currently only LRUCache)
         size - the maximum number of entries in the cache
         initialSize - the initial capacity (number of entries) of
           the cache.  (seel java.util.HashMap)
         autowarmCount - the number of entries to prepopulate from
           and old cache.

    <filterCache
      class="solr.LRUCache"
      size="1024"
      initialSize="512"
      autowarmCount="0"/>-->

   <!-- queryResultCache caches results of searches - ordered lists of
         document ids (DocList) based on a query, a sort, and the range
         of documents requested.  -->
    <queryResultCache
      class="solr.LRUCache"
      size="10000"
      initialSize="512"
      autowarmCount="0"/>

  <!-- documentCache caches Lucene Document objects (the stored fields for each document).
       Since Lucene internal document ids are transient, this cache will not be autowarmed.  -->
    <documentCache
      class="solr.LRUCache"
      size="1024"
      initialSize="512"
      autowarmCount="0"/>

    <!-- Example of a generic cache.  These caches may be accessed by name
         through SolrIndexSearcher.getCache().cacheLookup(), and cacheInsert().
         The purpose is to enable easy caching of user/application level data.
         The regenerator argument should be specified as an implementation
         of solr.search.CacheRegenerator if autowarming is desired.  -->
    <!--
    <cache name="myUserCache"
      class="solr.LRUCache"
      size="4096"
      initialSize="1024"
      autowarmCount="1024"
      regenerator="org.mycompany.mypackage.MyRegenerator"
      />
    -->

    <!-- An optimization that attempts to use a filter to satisfy a search.
         If the requested sort does not include a score, then the filterCache
         will be checked for a filter matching the query.  If found, the filter
         will be used as the source of document ids, and then the sort will be
         applied to that.
      -->
    <useFilterForSortedQuery>true</useFilterForSortedQuery>

    <!-- An optimization for use with the queryResultCache.  When a search
         is requested, a superset of the requested number of document ids
         are collected.  For example, of a search for a particular query
         requests matching documents 10 through 19, and queryWindowSize is 50,
         then documents 0 through 50 will be collected and cached. Any further
         requests in that range can be satisfied via the cache.
    -->
    <queryResultWindowSize>100</queryResultWindowSize>

    <!-- This entry enables an int hash representation for filters (DocSets)
         when the number of items in the set is less than maxSize. For smaller
         sets, this representation is more memory efficient, more efficient to
         iterate over, and faster to take intersections.
     -->
    <HashDocSet maxSize="3000" loadFactor="0.75"/>


    <!-- boolToFilterOptimizer converts boolean clauses with zero boost
         cached filters if the number of docs selected by the clause exceeds the
         threshold (represented as a fraction of the total index)
    -->
    <boolTofilterOptimizer enabled="true" cacheSize="32" threshold=".05"/>

    <!-- Lazy field loading will attempt to read only parts of documents on disk that are
         requested.  Enabling should be faster if you aren't retrieving all stored fields.
    -->
    <enableLazyFieldLoading>false</enableLazyFieldLoading>

    <!-- Use Cold Searcher

         If a search request comes in and there is no current
         registered searcher, then immediately register the still
         warming searcher and use it.  If "false" then all requests
         will block until the first searcher is done warming.
    -->
    <useColdSearcher>true</useColdSearcher>

</query>

Я также пытался включить filterCache, но это не помогает.

Спасибо.


person Van Thoai Nguyen    schedule 04.02.2014    source источник
comment
Еще одна вещь, которую вы можете сделать, может ускорить ответ и воспользоваться преимуществами filterCache, чтобы использовать запросы фильтрации в полях, которым не нужны функции полнотекстового поиска. q=*:*&fq=CampaignId:1462&fq=SourceDateUtc:[2014-01-01T00:00:00.000Z TO 2014-01-30T00:00:00.000Z]&facet=true...   -  person d whelan    schedule 06.02.2014


Ответы (1)


Скорее всего проблема с прогревом. Кэш поля прогрева (facet.method=fc) очень важен для эффективной работы solr. Если вы не настроили предварительные запросы, рассмотрите возможность добавления фасетного запроса, как в вашем примере, в разделы newsearcher и firstsearcher в solrconfig.xml.

http://wiki.apache.org/solr/SolrConfigXml#A.22Query.22_Related_Event_Listeners

<listener event="firstSearcher" class="solr.QuerySenderListener">
      <arr name="queries">
        <lst> <str name="q">*:*</str>
              <str name="start">0</str>
              <str name="rows">10</str>
              <str name="facet">true</str>
              <str name="facet.field">UserName</str>
              <str name="facet.mincount">10</str>
              <str name="facet.method">fc</str>
        </lst>
      </arr>
</listener>

Вы также можете отключить использование ColdSearher

<useColdSearcher>true</useColdSearcher>

Дальнейшее чтение:

Что делает хороший запрос на автопотепление в Solr и как они работают?

http://wiki.apache.org/solr/SolrFacetingOverview

person leoh    schedule 05.02.2014
comment
Спасибо, это работает. Но у меня есть небольшая проблема: из-за запроса * : * при перезагрузке индекса он читает все из индекса в память, что не идеально, потому что мои данные слишком велики. - person Van Thoai Nguyen; 05.02.2014
comment
Рад помочь. Это также зависит от того, как вы настроите параметры кеша... но обычно для фасетирования на *:* не требуется столько памяти. Раньше у меня было собрание около 100G, но брал только 17G heap memory с фацетированием на *:* - person leoh; 05.02.2014
comment
Привет. Могу ли я использовать строку ‹str name=facet.field›UserName‹/str› несколько раз? - person Kalpesh Boghara; 17.08.2016