Return-Path: X-Original-To: apmail-cassandra-dev-archive@www.apache.org Delivered-To: apmail-cassandra-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7805C115CA for ; Tue, 17 Jun 2014 13:39:13 +0000 (UTC) Received: (qmail 5875 invoked by uid 500); 17 Jun 2014 13:39:12 -0000 Delivered-To: apmail-cassandra-dev-archive@cassandra.apache.org Received: (qmail 5843 invoked by uid 500); 17 Jun 2014 13:39:12 -0000 Mailing-List: contact dev-help@cassandra.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cassandra.apache.org Delivered-To: mailing list dev@cassandra.apache.org Received: (qmail 5832 invoked by uid 99); 17 Jun 2014 13:39:11 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 17 Jun 2014 13:39:11 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of belliottsmith@datastax.com designates 209.85.223.180 as permitted sender) Received: from [209.85.223.180] (HELO mail-ie0-f180.google.com) (209.85.223.180) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 17 Jun 2014 13:39:06 +0000 Received: by mail-ie0-f180.google.com with SMTP id rl12so6339958iec.39 for ; Tue, 17 Jun 2014 06:38:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=iWpYK05dQrYh+RVcoHpIF3BhnlaM0nzqoJQaZXvm4bk=; b=T5lsyjJtGynUif7oFy8QjVL4diyTx7vaslKDm9A0BvRtZoU9Z5k92+Wb3e8Wwkc63P 5+KXvv3WXgiHuoNyhsVZJY884ZPYksoGziyXe6AgS90CEGx+wzhqCA/aG4WazYZv804n Jxgo+8Q/LtM7fi/XOCnOMT20oJ1NrIpKwGYbgjmgT03uelVdEDa0wxo9Mqc8yvpREFhA ZNa9L1KBR8qE0W6Kl3zEGJmO/hX5xpMJusz2nK69sLRZQgakgdEXG5Aln2/1K79BI2Jm 2O3m54p8xvPitA5psXPBRBWZOC0Hno6T3dJS3743iQ3BNMEM9xJtbT0ikZ6SrP22uE2f 9e8w== X-Gm-Message-State: ALoCoQmjDNrMns21YwU9f3fGdZRatQ9zsJX3bmUO2iWc7/TabXm7mwG7qZuFwFRtNhuI3iPJyq0F MIME-Version: 1.0 X-Received: by 10.42.12.6 with SMTP id w6mr9809403icw.69.1403012325499; Tue, 17 Jun 2014 06:38:45 -0700 (PDT) Received: by 10.43.9.200 with HTTP; Tue, 17 Jun 2014 06:38:45 -0700 (PDT) In-Reply-To: <5CD4FBAA-4FB1-4387-9596-7F8F52351734@vast.com> References: <78BBD6DB-F9A4-44CE-9CB7-41AAC1C6DA38@vast.com> <6370EB47-6ECD-432A-823A-3682E44ED2AF@vast.com> <5161B90E-1A6D-4F4F-BE36-F700B6BB4A55@vast.com> <56FC9731-2BE6-47FE-868B-0C1424738830@vast.com> <8B425023-8DE0-4F89-9387-E9AD4604BFA7@vast.com> <5CD4FBAA-4FB1-4387-9596-7F8F52351734@vast.com> Date: Tue, 17 Jun 2014 14:38:45 +0100 Message-ID: Subject: Re: CMS GC / fragmentation / memtables etc From: Benedict Elliott Smith To: dev@cassandra.apache.org Content-Type: multipart/alternative; boundary=20cf301d3d8c47012004fc0843a1 X-Virus-Checked: Checked by ClamAV on apache.org --20cf301d3d8c47012004fc0843a1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable The discussion about virtual methods was around a number of considerations, as there was some work to refactor the hierarchy and introduce more virtual methods for a single allocator's cell hierarchies. The allocator also does not determine the total set of possible cell implementations, as in-flight data always exists as an on-heap buffer for this version of Cassandra, so your supposition is a bit optimistic I'm afraid. This may change in a future version, but depends on the zero-copy patch that has, as I mentioned, been shelved for the moment. 1) offheap_objects refers to the fact that we serialize the whole object into an offheap region of memory, except for a single object reference to it for accessing this data; they are still (currently) allocated as regions of offheap memory, so there should not be fragmentation of the native heap 2) Yes, although obviously they are slightly more experimental so will not be the default memtable type when 2.1 first drops 3) I doubt there would be much difference in the current implementation for offheap memtables (possibly for row cache) as we allocate large (1M) regions of native memory to save space and fragmentation (native allocations typically have ~16 byte overhead which is significant at the cell level). Currently we support jemalloc as an alternative allocator, but I would benchmark this allocator in your environment, as it has very high deallocation costs in some environments. Tuning these variables will, as with everything, be highly workload dependent. A rule of thumb for offheap_objects: heap: 100 bytes per partition, 20 bytes per cell; offheap: 8 (timestamp) + 8 (overhead) + {clustering+name+data size} per cell On a memtable flush you will see information printed about occupancy of each limit, so you will be able to tune accordingly if your data is consistent. On Sun, Jun 15, 2014 at 11:52 PM, graham sanderson wrote: > Hi Benedict thanks once again for your explanations (hopefully these are > my last questions!)=E2=80=A6 I just read > https://issues.apache.org/jira/browse/CASSANDRA-6694 really quickly, so > didn=E2=80=99t follow all the discussions=E2=80=A6. one thing to note tha= t was argued in > the middle was about the cost of virtual methods with multiple > implementations. c2 certainly has fast path for 1, and N known > implementations where 1 de/re-compile on optimistic assumption failure, or actually when new > classes appear). AFAIK this is also tracked per call site, and since the > choice of allocator is static on startup, these calls are actually > monomorphic and inline-able (note I don=E2=80=99t work on the compilers, = nor have I > looked closely at the code, but this is my understanding). Anyway I don= =E2=80=99t > think this affected your final implementation, but should be how it works > for hot code. > > The questions: > > 1) Is it fair to say offheap_objects is similar to offheap_buffers, but > with the added benefit of being able to store (large numbers of) individu= al > objects which weren=E2=80=99t kept in the Regions on heap either, because= they > needed to be tracked as actual objects? > > 2) That offheap_objects is probably the way to go. > > Is/there or will there be some suggestions on tuning > > memtable_heap_space_in_mb; > memtable_offheap_space_in_mb; > > compared to memtable_total_space_in_mb today (note > memtable_total_space_in_mb is actually what is still in cassandra.yaml) > > 3) I saw somewhere some talk of using a different malloc implementation > for less native heap fragmentation, but can=E2=80=99t find it now - do yo= u have a > recommendation to use the non-standard (have to install it yourself) one. > > Thanks, > > Graham. > > On Jun 15, 2014, at 2:04 PM, Benedict Elliott Smith < > belliottsmith@datastax.com> wrote: > > The current implementation is slower for a single memtable-only read > (dependent on workload, but similar ball park to on heap), but can store > substantially more per memtable under offheap_objects (again dependent on > workload, but as much as 8x in extreme cases) which means more queries ar= e > answerable from memtable, and write amplification is reduced accordingly, > improving write throughput. > On 15 Jun 2014 13:32, "graham sanderson" wrote: > > Hi Benedict, > > Ah, my mistake, I had assumed that since the memory backing the off heap > ByteBuffer Regions was freed on discard, that the Regions would be > immediately recyclable in the on heap case. > > I guess I=E2=80=99ll just configure for one of the off-heap variants when= 2.1 > comes out=E2=80=A6 > > Any idea of the performance of offheap_buffers and offheap_objects > (ignoring GC) compared to heap_buffers? I assume offheap_objects must hav= e > some benefits but presumably at the cost of fragmentation of the native > heap=E2=80=A6 obviously I=E2=80=99ll play with it when it comes out=E2=80= =A6 right now we are > testing something else, so I don=E2=80=99t have a good environment to try= 2.1 - and > that is always kind of meaningless anyways, since we have many different > apps using cassandra with different usage patterns, and it is hard to mim= ic > production load on all of them at the same time in beta > > Thanks anyway for your detailed explanations, > > Graham > > On Jun 15, 2014, at 1:11 PM, Benedict Elliott Smith < > belliottsmith@datastax.com> wrote: > > Hi Graham, > > Unfortunately the problem is more difficult than you might think. > References to the buffers can persist in-flight to clients long after the > memtable is discarded, so you would be introducing a subtle corruption > > risk > > for data returned to clients. Unfortunately the current implementation in > 2.1 won't solve this problem for on-heap buffers without introducing a > performance penalty (by copying data from the buffers on read, as we > currently do for off-heap data), so I don't expect this change will be > introduced until zero-copy offheap memtables are introduced, which have > been shelved for the moment. > > > On 15 Jun 2014 10:53, "graham sanderson" wrote: > > Hi Benedict, > > So I had a look at the code, and as you say it looked pretty easy to > recycle on heap slabs=E2=80=A6 there is already RACE_ALLOCATED which keep= s a > strongly referenced pool, however I was thinking in this case of just > WeakReferences. > > In terms of on heap slabs, it seemed to me that recycling the oldest > > slab > > you have is probably the best heuristic, since it is less likely to be > > in > > eden (of course re-using in eden is no worse than worst case today), > however since the problem tends to be promotion failure of slabs due to > fragmentation of old gen, recycling one that is already there is even > better - better still if it has been compacted somewhere pretty stable. > > I > > think this heuristic would also work well for G1, though I believe the > recommendation is still not to use that with cassandra. > > So for implementation of that I was thinking of using a > ConcurrentSkipListMap, from a Long representing the allocation order of > > the > > Region to a weak reference to the Region (just regular 1M sized ones)=E2= =80=A6 > allocators can pull oldest and discard cleared references (might need a > scrubber if the map got too big and we were only checking the first > > entry). > > Beyond that I don=E2=80=99t think there is any need for a configurable-le= ngthed > collection of strongly referenced reusable slabs. > > Question 1: > > This is easy enough to implement, and probably should just be turned on > > by > > an orthogonal setting=E2=80=A6 I guess on heap slab is the current defaul= t, so > > this > > feature will be useful > > Question 2: > > Something similar could be done for off heap slabs=E2=80=A6 this would se= em more > like it would want a size limit on the number of re-usable slabs=E2=80=A6= strong > references with explicit clean() is probably better, than using > weak-references and letting PhantomReference cleaner on > > DirectByteBuffer do > > the cleaning later. > > Let me know any thoughts and I=E2=80=99ll open an issue (probably 2 - one= for on > heap one for off)=E2=80=A6 let me know whether you=E2=80=99d like me to a= ssign the > > first to > > you or me (I couldn=E2=80=99t work on it before next week) > > Thanks, > > Graham. > > On May 21, 2014, at 2:20 AM, Benedict Elliott Smith < > belliottsmith@datastax.com> wrote: > > Graham, > > This is largely fixed in 2.1 with the introduction of partially > > off-heap > > memtables - the slabs reside off-heap, so do not cause any GC issues. > > As it happens the changes would also permit us to recycle on-heap slabs > reasonable easily as well, so feel free to file a ticket for that, > > although > > it won't be back ported to 2.0. > > > On 21 May 2014 00:57, graham sanderson wrote: > > So i=E2=80=99ve been tinkering a bit with CMS config because we are still > > seeing > > fairly frequent full compacting GC due to framgentation/promotion > > failure > > > As mentioned below, we are usually too fragmented to promote new > > in-flight > > memtables. > > This is likely caused by sudden write spikes (which we do have), > > though > > actually the problems don=E2=80=99t generally happen at that time of our > > largest > > write spikes (though any write spikes likely cause spill of both new > memtables along with many other new objects of unknown size into the > tenured gen, so they cause fragmentation if not immediate GC issue). > > We > > have lots of things going on in this multi-tenant cluster (GC pauses > > are of > > course extra bad, since they cause spike in hinted-handoff on other > > nodes > > which were already busy etc=E2=80=A6) > > Anyway, considering possibilities: > > 0) Try and make our application behavior more steady state - this is > probably possible, but there are lots of other things (e.g. > > compaction, > > opscenter, repair etc.) which are both tunable and generally > > throttle-able > > to think about too. > 1) Play with tweaking PLAB configs to see if we can ease fragmentation > (I=E2=80=99d be curious what the =E2=80=9Ccrud=E2=80=9D is in particular = that is getting > > spilled - > > presumably it is larger objects since it affects the binary tree of > > large > > objects) > 2) Given the above, if we can guarantee even > 24 hours without full > > GC, I > > don=E2=80=99t think we=E2=80=99d mind running a regular rolling re-start = on the > > servers > > during off hours (note usually the GCs don=E2=80=99t have a visible impac= t, > > but > > when they hit multiple machines at once they can) > 3) Zing is seriously an option, if it would save us large amounts of > tuning, and constant worry about the =E2=80=9Cnext=E2=80=9D thing tweakin= g the > > allocation > > patterns - does anyone have any experience with Zing & Cassandra > 4) Given that we expect periodic bursts of writes, > memtable_total_space_in_mb is bounded, we are not actually short of > > memory > > (it just gets fragmented), I=E2=80=99m wondering if anyone has played wit= h > > pinning > > (up to or initially?) that many 1MB chunks of memory via SlabAllocator > > and > > re-using=E2=80=A6 It will get promoted once, and then these 1M chunks won= =E2=80=99t be > > part > > of the subsequent promotion hassle=E2=80=A6 it will probably also allow m= ore > > crud > > to die in eden under write load since we aren=E2=80=99t allocating these = large > chunks in eden at the same time. Anyway, I had a little look at the > > code, > > and the life cycles of memtables is not trivial, but was considering > attempting a patch to play with=E2=80=A6 anyone have any thoughts? > > Basically in summary, the Slab allocator helps by allocating and > > freeing > > lots of objects at the same time, however any time slabs are allocated > under load, we end up promoting them with whatever other live stuff in > > eden > > is still there. If we only do this once and reuse the slabs, we are > > likely > > to minimize our promotion problem later (at least for these large > > objects) > > > On May 16, 2014, at 9:37 PM, graham sanderson > > wrote: > > > Excellent - thank you=E2=80=A6 > > On May 16, 2014, at 7:08 AM, Samuel CARRIERE < > > samuel.carriere@urssaf.fr> > > wrote: > > > Hi, > This is arena allocation of memtables. See here for more infos : > > http://www.datastax.com/dev/blog/whats-new-in-cassandra-1-0-performance > > > > > > De : graham sanderson > A : dev@cassandra.apache.org, > Date : 16/05/2014 14:03 > Objet : Things that are about 1M big > > > > So just throwing this out there for those for whom this might ring a > > bell. > > > I?m debugging some CMS memory fragmentation issues on 2.0.5 - and > interestingly enough most of the objects giving us promotion > > failures > > are > > of size 131074 (dwords) - GC logging obviously doesn?t say what > > those > > are, > > but I?d wager money they are either 1M big byte arrays, or less > > likely > > 256k entry object arrays backing large maps > > So not strictly critical to solving my problem, but I was wondering > > if > > anyone can think of any heap allocated C* objects which are (with no > significant changes to standard cassandra config) allocated in 1M > > chunks. > > (It would save me scouring the code, or a 9 gig heap dump if I need > > to > > figure it out!) > > Thanks, > > Graham > > > > > > > > > > --20cf301d3d8c47012004fc0843a1--