Return-Path: Delivered-To: apmail-jackrabbit-users-archive@minotaur.apache.org Received: (qmail 58745 invoked from network); 8 Jun 2009 08:33:25 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 8 Jun 2009 08:33:25 -0000 Received: (qmail 6345 invoked by uid 500); 8 Jun 2009 08:33:36 -0000 Delivered-To: apmail-jackrabbit-users-archive@jackrabbit.apache.org Received: (qmail 6278 invoked by uid 500); 8 Jun 2009 08:33:36 -0000 Mailing-List: contact users-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@jackrabbit.apache.org Delivered-To: mailing list users@jackrabbit.apache.org Received: (qmail 6267 invoked by uid 99); 8 Jun 2009 08:33:35 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Jun 2009 08:33:35 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of mreutegg@day.com designates 207.126.148.182 as permitted sender) Received: from [207.126.148.182] (HELO eu3sys201aog002.obsmtp.com) (207.126.148.182) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 08 Jun 2009 08:33:26 +0000 Received: from source ([209.85.220.222]) by eu3sys201aob002.postini.com ([207.126.154.11]) with SMTP ID DSNKSizMv1ybuWL9sosmfpHWR3iMeZxs2pDn@postini.com; Mon, 08 Jun 2009 08:33:06 UTC Received: by fxm22 with SMTP id 22so2887940fxm.9 for ; Mon, 08 Jun 2009 01:33:03 -0700 (PDT) MIME-Version: 1.0 Sender: mreutegg@day.com Received: by 10.204.120.70 with SMTP id c6mr6442336bkr.144.1244449983677; Mon, 08 Jun 2009 01:33:03 -0700 (PDT) In-Reply-To: <4A2847D3.2080103@trivantisdev.com> References: <4A2847D3.2080103@trivantisdev.com> Date: Mon, 8 Jun 2009 10:33:03 +0200 X-Google-Sender-Auth: 008f79715aec5e20 Message-ID: Subject: Re: Performance Improvement Code Fix to AbstractRecord From: Marcel Reutegger To: users@jackrabbit.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org Hi, this has already been reported and fixed. See: https://issues.apache.org/jira/browse/JCR-1988 regards marcel On Fri, Jun 5, 2009 at 00:16, Eric wrote: > We were having performance issues during the commit of a transaction that > contained a huge amount of node inserts. =A0We found that a big chunk of = the > commit time was spent in the method > org.apache.jackrabbit.core.journal.AbstractRecord.getOrCreateIndex(). =A0= In > this class, the uuidIndex instance variable is an ArrayList and > uuidIndex.indexOf(nodeId) is called to search through this ArrayList to s= ee > if a node is already in the list. =A0ArrayList.indexOf() searches the lis= t > from beginning to end calling NodeId.equals() until the entry is located = and > then returns. =A0This can be quite inefficient if the list becomes large. > > In our case, we had *42K* entries in this list with about *400K* calls to > getOrCreateIndex() resulting in over *9 billion* calls to NodeId.equals()= . > =A0By combining a HashMap with the ArrayList and checking the HashMap ins= tead > of the ArrayList to see if the node is in the cache, we traded the 400K > calls to ArrayList.indexOf() (and the subsequent 9 billions calls to > NodeId.equals()) for 400K calls HashMap.get() (and its subsequent calls). > =A0Our commit time went from about 30 minutes to about 3 minutes. > > There may be more elegant ways to fix this problem, but our changes to > AbstractRecord are listed below. =A0Maybe some changes along these lines = could > be incorporated into this class to improve performance. =A0Thanks. > > -------------------- old code -------------------- > > private int getOrCreateIndex(NodeId nodeId) { > =A0 int index =3D uuidIndex.indexOf(nodeId); > > =A0 if (index =3D=3D -1) { > =A0 =A0 =A0 uuidIndex.add(nodeId); > =A0 } > =A0 return index; > } > > -------------------- new code -------------------- > > private final HashMap uuidMap =3D new HashMap Integer>(); > > private int getOrCreateIndex(NodeId nodeId) { > =A0 Integer index =3D uuidMap.get(nodeId.toString()); > > =A0 if (index =3D=3D null) { > =A0 =A0 =A0 uuidIndex.add(nodeId); > =A0 =A0 =A0 uuidMap.put(nodeId.toString(), uuidIndex.size() - 1); > =A0 =A0 =A0 index =3D -1; > =A0 } > =A0 return index; > } > >