Return-Path: Delivered-To: apmail-jackrabbit-dev-archive@www.apache.org Received: (qmail 21314 invoked from network); 11 Jun 2007 08:17:26 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 11 Jun 2007 08:17:26 -0000 Received: (qmail 30767 invoked by uid 500); 11 Jun 2007 08:17:28 -0000 Delivered-To: apmail-jackrabbit-dev-archive@jackrabbit.apache.org Received: (qmail 30723 invoked by uid 500); 11 Jun 2007 08:17:27 -0000 Mailing-List: contact dev-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list dev@jackrabbit.apache.org Received: (qmail 30714 invoked by uid 99); 11 Jun 2007 08:17:27 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 Jun 2007 01:17:27 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of mreutegg@gmail.com designates 66.249.92.168 as permitted sender) Received: from [66.249.92.168] (HELO ug-out-1314.google.com) (66.249.92.168) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 Jun 2007 01:17:23 -0700 Received: by ug-out-1314.google.com with SMTP id u2so1561951uge for ; Mon, 11 Jun 2007 01:17:01 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:subject:references:in-reply-to:content-type:content-transfer-encoding:sender; b=P4aDjp0gBnkwxM6Qp19Xf0SNNiuZNKX4/QFSCiTlqRXB9xL3R8sv1KjHt8iYsGM1S1GPosQEbLsr0Z0DQ9P+wLrQLNWhLFnPLVAGY45l4mJ8JMqLa59ujGVNecw2hyqAcYhPjmaVArT44W/H8SN9+SlLPu3HUq82jvACFwqVXQ4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:user-agent:mime-version:to:subject:references:in-reply-to:content-type:content-transfer-encoding:sender; b=khhrl1hUP5DdegT98x8gB0t2YXys63TWuA6Zz28aTDhGlQ1SFjgD3OiOXEoN/Vf1d+KTnDNj9Xh0Zd6e8QYGmsop+3djWa0L/LpEbdVFAqY4RJVlqrL8j2aYzxM1YUJfgDfONujkBFFwZc9VEAcDKUi8KKmTTK51pY6kF5XAOrU= Received: by 10.82.189.6 with SMTP id m6mr10317926buf.1181549821478; Mon, 11 Jun 2007 01:17:01 -0700 (PDT) Received: from ?10.0.0.159? ( [62.192.10.254]) by mx.google.com with ESMTP id 7sm16140273nfv.2007.06.11.01.16.59 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 11 Jun 2007 01:16:59 -0700 (PDT) Message-ID: <466D04F8.8030304@day.com> Date: Mon, 11 Jun 2007 10:16:56 +0200 From: Marcel Reutegger User-Agent: Thunderbird 1.5.0.12 (Windows/20070509) MIME-Version: 1.0 To: dev@jackrabbit.apache.org Subject: Re: Optimize search performance References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Sender: Marcel Reutegger X-Virus-Checked: Checked by ClamAV on apache.org Hi Christoph, Christoph Kiehl wrote: > I had a look at the search related code during the last days, because we > need better performance for range queries on date fields as well as for > sorting by date fields. These are my thoughts so far: > > 1. Wouldn't it make sense to exclude the index for the "jcr:system" tree > (which is located at repository/index by default) if the query to > execute doesn't include items from the "jcr:system" tree. > Take for example a query like "my:app//element(*, foo:bar)". This query > only searches for nodes located under "my:app" which excludes nodes from > "jcr:system" and therefore doesn't need to search in the "jcr:system" > index. I think this is doable. Can you please file a jira issue about this? > As the "jcr:system" might grow quite quickly if you create a lot > versions it might be worth to exclude it. > I'm not sure though how hard it would be to find out if a query needs to > include the "jcr:system" index. There are two relevant nodes in the query tree to find that out. - what's the first location step and does it include the jcr:system tree? I think that's an easy one. - does the query contain a jcr:deref node? If there is an intermediate result of a query may dereference into the jcr:system tree. > 2. Lucene uses the FieldCaches to speed up sorting and range queries > which is exactly what we are after. Those FieldCaches are per IndexReader. > Jackrabbit uses an IndexSearcher which searches on a single IndexReader > which is most likely to be an instance of CachingMultiReader. So on > every search which builds up a FieldCache this FieldCache instance is > associated with this instance of a CachingMultiReader. On successive > queries which operate on this CachingMultiReader you will get a > tremendous speedup for queries which can reuse those associated > FieldCache instances. > The problem is that Jackrabbit creates a new CachingMultiReader > _everytime_ one of the underlying indexes are modified. This means if > you just change _one_ item in the repository you will need to rebuild > all those FieldCaches because the existing FieldCaches are associated > with the old instance of CachingMultiReader. > This does not only lead to slow search response times for queries which > contains range queries or are sorted by a field but also leads to > massive memory consumption (depending on the size of your indexes) > because there might be multiple instances of CachingMultiReaders in use > if you have a scenario where a lot of queries and item modifications are > executed concurrently. > As far as I understand the solution is to use a MultiSearcher which uses > multiple IndexReaders. Since due to the merging strategy most of the > indexes are stable this means the FieldCaches can be used for a much > longer time. this is all correct but does not work because. and you actually already found out why: > I just tried to quickly modify SearchIndex to use a MultiSearcher with > multiple IndexReaders wrapped by IndexSearchers but wasn't successful > because somewhere in DescendantSelfAxisWeight the index readers are > required to implement HierarchyResolver which ReadOnlyIndexReader doesn't. Using a multi searcher means that you must be able to execute a query on each of the index segments independently. this is not possible because hierarchy information is always spread across multiple segments. e.g. a node in one segment may reference a parent in another segment. there's also another reason why a multi searcher is not the best solution. it requires that the fields of a returned FieldDoc contain the values of the indexed property. If there are lots of values to order the complete set of values needs to be read into memory. With the current implementation this is not needed because there is just a single FieldCache that uses integers instead of the real value. See class SharedFieldSortComparator [1]. the downside of this approach is that you cannot do a merge sort just using those integers. a viable solution maybe is a combination of both approaches. use a FieldCache per index segment (which allows us to cache them for a longer period) but still use integer values for ordering of nodes within a segment. Then do a merge sort with a modified SharedFieldSortComparator that reads property values from the item state manager when nodes are compared across index segments. even though this requires reading property state, the performance shouldn't suffer too much, I think. the properties would be read anyway when the query result is iterated, so it shouldn't harm if they are read already during query execution. regards marcel [1] https://svn.apache.org/repos/asf/jackrabbit/tags/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SharedFieldSortComparator.java