Return-Path: X-Original-To: apmail-lucene-java-user-archive@www.apache.org Delivered-To: apmail-lucene-java-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 04DF99952 for ; Fri, 2 Mar 2012 23:57:37 +0000 (UTC) Received: (qmail 65482 invoked by uid 500); 2 Mar 2012 23:57:34 -0000 Delivered-To: apmail-lucene-java-user-archive@lucene.apache.org Received: (qmail 65443 invoked by uid 500); 2 Mar 2012 23:57:34 -0000 Mailing-List: contact java-user-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: java-user@lucene.apache.org Delivered-To: mailing list java-user@lucene.apache.org Received: (qmail 65434 invoked by uid 99); 2 Mar 2012 23:57:34 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Mar 2012 23:57:34 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of matthewb@labkey.com designates 209.85.160.48 as permitted sender) Received: from [209.85.160.48] (HELO mail-pw0-f48.google.com) (209.85.160.48) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Mar 2012 23:57:30 +0000 Received: by pbcup7 with SMTP id up7so3222488pbc.35 for ; Fri, 02 Mar 2012 15:57:09 -0800 (PST) Received-SPF: pass (google.com: domain of matthewb@labkey.com designates 10.68.229.67 as permitted sender) client-ip=10.68.229.67; Authentication-Results: mr.google.com; spf=pass (google.com: domain of matthewb@labkey.com designates 10.68.229.67 as permitted sender) smtp.mail=matthewb@labkey.com Received: from mr.google.com ([10.68.229.67]) by 10.68.229.67 with SMTP id so3mr21812708pbc.163.1330732629474 (num_hops = 1); Fri, 02 Mar 2012 15:57:09 -0800 (PST) Received: by 10.68.229.67 with SMTP id so3mr18211755pbc.163.1330732629288; Fri, 02 Mar 2012 15:57:09 -0800 (PST) MIME-Version: 1.0 Received: by 10.142.70.20 with HTTP; Fri, 2 Mar 2012 15:56:49 -0800 (PST) In-Reply-To: References: From: Matthew Bellew Date: Fri, 2 Mar 2012 15:56:49 -0800 Message-ID: Subject: Re: CloseableThreadLocal problem To: java-user@lucene.apache.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Gm-Message-State: ALoCoQmsZfkos/RFsCSK5UiLkcpZxHdbb2bwLT5VKqvi8xvhyI06U+V6ViwVnGAZwQUPRJYBYjfO X-Virus-Checked: Checked by ClamAV on apache.org Thanks for your reply MIke, I create this bug. https://issues.apache.org/jira/browse/LUCENE-3841 Matt On Thu, Mar 1, 2012 at 2:32 PM, Michael McCandless wrote: > Phew, tricky. > > The problem is purging is potentially costly... it iterates all > entries in the map (threads that have called get) looking for dead > threads. > > Can you open an issue...? =C2=A0We can iterate there. =C2=A0Thanks for ra= ising this, > > Mike McCandless > > http://blog.mikemccandless.com > > On Wed, Feb 29, 2012 at 12:17 PM, Matthew Bellew wr= ote: >> We tracked down a large memory leak (effectively a leak anyway) caused >> by how Analyzer users CloseableThreadLocal. >> CloseableThreadLocal.hardRefs holds references to Thread objects as >> keys. =C2=A0The problem is that it only frees these references in the se= t() >> method, and SnowballAnalyzer will only call set() when it is used by a >> NEW thread. >> >> The problem scenario is as follows: >> >> The server experiences a spike in usage (say by robots or whatever) >> and many threads are created and referenced by >> CloseableThreadLocal.hardRefs. =C2=A0The server quiesces and lets many o= f >> these threads expire normally. =C2=A0Now we have a smaller, but adequate >> thread pool. =C2=A0So CloseableThreadLocal.set() may not be called by >> SnowBallAnalyzer (via Analyzer) for a _long_ time. =C2=A0The purge code = is >> never called, and these threads along with their thread local storage >> (lucene related or not) is never cleaned up. >> >> I think calling the purge code in both get() and set() would have >> avoided this problem, perhaps using WeakHashMap instead of HashMap may >> also have helped (WeakHashMap purges on get() and set()) >> >> Our current work around is to not share SnowBallAnalyzer instances >> among HTTP searcher threads. =C2=A0We open and close one on every reques= t. >> >> Thanks, >> Matt >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org >> For additional commands, e-mail: java-user-help@lucene.apache.org >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org > For additional commands, e-mail: java-user-help@lucene.apache.org > --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org For additional commands, e-mail: java-user-help@lucene.apache.org