Return-Path: X-Original-To: apmail-hadoop-user-archive@minotaur.apache.org Delivered-To: apmail-hadoop-user-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3AA6FD0F0 for ; Mon, 6 Aug 2012 18:53:23 +0000 (UTC) Received: (qmail 9247 invoked by uid 500); 6 Aug 2012 18:53:18 -0000 Delivered-To: apmail-hadoop-user-archive@hadoop.apache.org Received: (qmail 9178 invoked by uid 500); 6 Aug 2012 18:53:18 -0000 Mailing-List: contact user-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@hadoop.apache.org Delivered-To: mailing list user@hadoop.apache.org Received: (qmail 9171 invoked by uid 99); 6 Aug 2012 18:53:17 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Aug 2012 18:53:17 +0000 X-ASF-Spam-Status: No, hits=2.6 required=5.0 tests=FSL_RCVD_USER,HTML_MESSAGE,NO_RDNS_DOTCOM_HELO,RCVD_IN_DNSWL_LOW,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: 216.145.54.172 is neither permitted nor denied by domain of daryn@yahoo-inc.com) Received: from [216.145.54.172] (HELO mrout2.yahoo.com) (216.145.54.172) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Aug 2012 18:53:11 +0000 Received: from SP1-EX07CAS02.ds.corp.yahoo.com (sp1-ex07cas02.ds.corp.yahoo.com [216.252.116.138]) by mrout2.yahoo.com (8.14.4/8.14.4/y.out) with ESMTP id q76Iqm1c098517 for ; Mon, 6 Aug 2012 11:52:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yahoo-inc.com; s=cobra; t=1344279168; bh=vlZ1RxEG7U0dEMmwKE950/PTBri0hOo/hwAOHR9JyLM=; h=From:To:Date:Subject:Message-ID:References:In-Reply-To: Content-Type:MIME-Version; b=sGdUGDiDmwc7mELBMqxGFmpHTVC3DSIy+HGV/u4Pt8TQGqWAVby2pUUXZE2YMWWPU KYhD8qeRGOlmRysbEaK2RRldaazN+C7q3FdQ4B9SaTEBUdKntMAz3jw93Cf71k5D17 r1kiWM/e06liJNAddJEV9u6eZV6D5gXhW8XgXO8I= Received: from SP1-EX07VS02.ds.corp.yahoo.com ([216.252.116.135]) by SP1-EX07CAS02.ds.corp.yahoo.com ([216.252.116.167]) with mapi; Mon, 6 Aug 2012 11:52:47 -0700 From: Daryn Sharp To: "user@hadoop.apache.org" Date: Mon, 6 Aug 2012 11:52:46 -0700 Subject: Re: fs cache giving me headaches Thread-Topic: fs cache giving me headaches Thread-Index: Ac10BKvEFpzD5vOWTFWIZOhyXZEaPw== Message-ID: <1DA607DA-E9D9-43E5-B93F-654C1AA090BE@yahoo-inc.com> References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US Content-Type: multipart/alternative; boundary="_000_1DA607DAE9D943E5B93F654C1AA090BEyahooinccom_" MIME-Version: 1.0 X-Milter-Version: master.31+4-gbc07cd5+ X-CLX-ID: 279168000 X-Virus-Checked: Checked by ClamAV on apache.org --_000_1DA607DAE9D943E5B93F654C1AA090BEyahooinccom_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Yes, the implementation of fs.close() leaves something to be desired. Ther= e's actually been debate in the past about close being a no-op for a cached= fs, but the idea was rejected by the majority of people. In the server case, you can use FileSystem.closeAllForUGI(ugi) at the end o= f a request to flush all the fs cache entries for the ugi. You'll get the = benefit of the cache during execution of the request, and be able to close = the cached fs instances to prevent memory leaks. I hope this helps! Daryn On Aug 6, 2012, at 12:32 PM, Koert Kuipers wrote: ---------- Forwarded message ---------- From: "Koert Kuipers" > Date: Aug 4, 2012 1:54 PM Subject: fs cache giving me headaches To: > nothing has confused me as much in hadoop as FileSystem.close(). any decent java programmer that sees that an object implements Closable wri= tes code like this: Final FileSystem fs =3D FileSystem.get(conf); try { // do something with fs } finally { fs.close(); } so i started out using hadoop FileSystem like this, and i ran into all sort= s of weird errors where FileSystems in unrelated code (sometimes not even m= y code) started misbehaving and streams where unexpectedly shut. Then i rea= lized that FileSystem uses a cache and close() closes it for everyone! Not = pretty in my opinion, but i can live with it. So i checked other code and f= ound that basically nobody closes FileSystems. Apparently the expected way = of using FileSystems is to simple never close them. So i adopted this appro= ach (which i think is really contrary to java conventions for a Closeable). Lately i started working on some code for a daemon/server where many FileSy= stems objects are created for different users (UGIs) that use the service. = As it turns out other projects have run into trouble with the FileSystem ca= che in situations like this (for example, Scribe and Hoop). I imagine the c= ache can get very large and cause problems (i have not tested this myself). Looking at the code for Hoop i noticed they simply turned off the FileSyste= m cache and made sure to close every FileSystem. So here the suggested appr= oach to deal with FileSystems seems to be: Final FileSystem fs =3D FileSystem.newInstance(conf); // or FileSystem.get(= conf) but with caching turned off in the conf try { // do something with fs } finally { fs.close(); } This code bypasses the cache if i understand it correctly, avoiding any cac= he size limitations. However if i adopt this approach i basically can not r= e-use any existing code or libraries that do not close FileSystems, splitti= ng the codebase into two which is pretty ugly. And this code is not efficie= nt in situations where there are very few used FileSystem objects and a cac= he would improve performance, so the split works both ways. In short, there is so single way to code with FileSystem that works in both= situations! Ideally i would have liked fs.close() to do the right thing de= pending in the settings: if cache is turned off it closes the FileSystem, a= nd if it is turned on its a NOOP. That way i could always use FileSystem.ge= t(conf) and always close my filesystems, and the code would be usable irres= pective of whether the cache is turned on or off. Any insights or suggestions? Thanks! --_000_1DA607DAE9D943E5B93F654C1AA090BEyahooinccom_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Yes, the implementation of= fs.close() leaves something to be desired.  There's actually been deb= ate in the past about close being a no-op for a cached fs, but the idea was= rejected by the majority of people.

In the server case,= you can use FileSystem.closeAllForUGI(ugi) at the end of a request to flus= h all the fs cache entries for the ugi.  You'll get the benefit of the= cache during execution of the request, and be able to close the cached fs = instances to prevent memory leaks. I hope this helps!

Daryn


On Aug 6, 2012, at 12:32 PM, Koert Kuipers wrote:

---------- Forwarded message ----------
From: "Koert Kuipers= " <koert@tresata.com>
Dat= e: Aug 4, 2012 1:54 PM
Subject: fs cache giving me headaches
To: <common-user@hadoo= p.apache.org>

nothing has confused me as= much in hadoop as FileSystem.close().
any decent java programmer that s= ees that an object implements Closable writes code like this:
Final FileSystem fs =3D FileSystem.get(conf);
try {
    // do something with fs
} finally {
  &n= bsp; fs.close();
}

so i started out using hadoop FileSystem like = this, and i ran into all sorts of weird errors where FileSystems in unrelat= ed code (sometimes not even my code) started misbehaving and streams where = unexpectedly shut. Then i realized that FileSystem uses a cache and close()= closes it for everyone! Not pretty in my opinion, but i can live with it. = So i checked other code and found that basically nobody closes FileSystems.= Apparently the expected way of using FileSystems is to simple never close = them. So i adopted this approach (which i think is really contrary to java = conventions for a Closeable).

Lately i started working on some code for a daemon/server where many Fi= leSystems objects are created for different users (UGIs) that use the servi= ce. As it turns out other projects have run into trouble with the FileSyste= m cache in situations like this (for example, Scribe and Hoop). I imagine t= he cache can get very large and cause problems (i have not tested this myse= lf).

Looking at the code for Hoop i noticed they simply turned off the FileS= ystem cache and made sure to close every FileSystem. So here the suggested = approach to deal with FileSystems seems to be:
Final FileSystem fs =3D F= ileSystem.newInstance(conf); // or FileSystem.get(conf) but with caching tu= rned off in the conf
try {
    // do something with fs
} finally {
    fs.close();
}

This code bypasses the cache if i understand it correctly, avoiding any= cache size limitations. However if i adopt this approach i basically can n= ot re-use any existing code or libraries that do not close FileSystems, spl= itting the codebase into two which is pretty ugly. And this code is not eff= icient in situations where there are very few used FileSystem objects and a= cache would improve performance, so the split works both ways.

In short, there is so single way to code with FileSystem that works in = both situations! Ideally i would have liked fs.close() to do the right thin= g depending in the settings: if cache is turned off it closes the FileSyste= m, and if it is turned on its a NOOP. That way i could always use FileSyste= m.get(conf) and always close my filesystems, and the code would be usable i= rrespective of whether the cache is turned on or off.

Any insights or suggestions? Thanks!


= --_000_1DA607DAE9D943E5B93F654C1AA090BEyahooinccom_--