Return-Path: Delivered-To: apmail-hadoop-hive-dev-archive@minotaur.apache.org Received: (qmail 94779 invoked from network); 3 Feb 2009 16:11:45 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 3 Feb 2009 16:11:44 -0000 Received: (qmail 76649 invoked by uid 500); 3 Feb 2009 16:11:44 -0000 Delivered-To: apmail-hadoop-hive-dev-archive@hadoop.apache.org Received: (qmail 76632 invoked by uid 500); 3 Feb 2009 16:11:44 -0000 Mailing-List: contact hive-dev-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: hive-dev@hadoop.apache.org Delivered-To: mailing list hive-dev@hadoop.apache.org Received: (qmail 76621 invoked by uid 99); 3 Feb 2009 16:11:44 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Feb 2009 08:11:44 -0800 X-ASF-Spam-Status: No, hits=0.7 required=10.0 tests=SPF_SOFTFAIL X-Spam-Check-By: apache.org Received-SPF: softfail (nike.apache.org: transitioning domain of jssarma@facebook.com does not designate 69.63.179.25 as permitted sender) Received: from [69.63.179.25] (HELO mailout-snc1.facebook.com) (69.63.179.25) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Feb 2009 16:11:36 +0000 Received: from mail.thefacebook.com (intlb01.snat.snc1.facebook.com [10.128.203.18] (may be forged)) by pp01.snc1.tfbnw.net (8.14.1/8.14.1) with ESMTP id n13GBEDT006492 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NOT) for ; Tue, 3 Feb 2009 08:11:14 -0800 Received: from SC-MBXC1.TheFacebook.com ([192.168.18.102]) by sc-hub01.TheFacebook.com ([192.168.18.104]) with mapi; Tue, 3 Feb 2009 08:11:13 -0800 From: Joydeep Sen Sarma To: "hive-dev@hadoop.apache.org" Date: Tue, 3 Feb 2009 08:11:15 -0800 Subject: RE: better caching for UDF states in map-side group bys Thread-Topic: better caching for UDF states in map-side group bys Thread-Index: AcmFsdMQtzh8XLV4RgqRm9LJ0jpWxQAZ9e8Q Message-ID: In-Reply-To: <34fd060d0902021936x6a38d94fs7e3e00b732d4418e@mail.gmail.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=1.12.7400:2.4.4,1.2.40,4.0.166 definitions=2009-02-03_07:2009-01-29,2009-02-03,2009-02-03 signatures=0 X-Virus-Checked: Checked by ClamAV on apache.org Currently the flush can only flush part of the hashmap (under memory pressu= re). This makes sense (especially combined with a lfu replacement strategy)= . So based on this - the free slot management would be necessary. If we can make the serialization fast enough - key serialization could a bi= g win .. -----Original Message----- From: Zheng Shao [mailto:zshao9@gmail.com]=20 Sent: Monday, February 02, 2009 7:36 PM To: hive-dev@hadoop.apache.org Subject: Re: better caching for UDF states in map-side group bys Yeah that will only work with a customized HashMap, but it's definitely possible to do. We might want to serialize the key to byte[] as well (using TBinarySortableProtocol etc). The free slot management does not seem to be a necessity, since when we flush all slots will be free. Zheng On Mon, Feb 2, 2009 at 6:04 PM, Joydeep Sen Sarma wro= te: > So I had this thought - why not use arrays of primitive types to store UD= F > state instead of objects. > > The background is that if one stores int [] intarray - then java uses 4 > bytes for each additional element in the array (verified). Instead if one > stores an array of objects that store an int - then there seems to be abo= ut > 16-20 bytes of extra overhead per object (not sure precisely - this is wh= at > it seems on my limited experiments). > > So imagine that: > - we maintained states for UDFs in primitive arrays (this is the > UDFs responsibility) > - we had a customized HashMap implementation that stored an inde= x > (int) as value for a key (keys are still objects - but values are just 4 > byte ints) > o looked at the jdk source - this seems straightforward > - to update state - we give the index to the evaluator. The > evaluator can then index into whatever arrays it maintains and do whateve= r > it wants. If it allocates a new slot in the array - then it can return th= e > allocated index back to the framework (to store against the key) > > this way - at least we can get rid of the object overhead from the value > part of the hashmap. > > Somewhat hacky (getting Java to work like C) - but this can be made to wo= rk > I think. > > There is the issue of managing the free slots on the array (which are > created on a flush) - but I think we can overlap a free list on top of th= e > primitive array (say every free slot stores the index of the next free sl= ot. > When slots are freed - we can chain the new free slots into the existing > head of the free list). > > Thoughts? > --=20 Yours, Zheng