Re: [EXTERNAL] Re: JVM Heap erratic

2018-07-06 Thread Randy Lynn
Alaine - Awesome information!!!
I had made some changes before seeing your email.

Current setup
CMS
16G heap
6G Eden
I also reduced Initiating Occupancy from 75 to 60. The thinking was that GC
will happen sooner giving me room for a burst to let GC catch up?? Maybe
that's completely wrong thinking?

MaxTenuring is still set to 1, so I'm eager to try what you're suggesting.
Our survivor ratio is set to 8 also.

Thanks for a well thought out, and detailed explanation!!

Randy

On Tue, Jul 3, 2018 at 8:27 AM, Durity, Sean R 
wrote:

> THIS! A well-reasoned and clear explanation of a very difficult topic.
> This is the kind of gold that a user mailing list can provide. Thank you,
> Alain!
>
>
>
>
>
> Sean Durity
>
>
>
> *From:* Alain RODRIGUEZ 
> *Sent:* Tuesday, July 03, 2018 6:37 AM
> *To:* user cassandra.apache.org 
> *Subject:* [EXTERNAL] Re: JVM Heap erratic
>
>
>
> Hello Randy,
>
>
>
> It's normal that the memory in the heap is having this pattern. Java uses
> memory available and when needed clean some memory for new needs, that's
> the variation you see. In your case, it's not really regular but this can
> depend on the workload as well.
>
>
>
> I'm a C# .NET guy, so I have no idea if this is normal Java behavior.
>
>
>
> I feel you. I started operating Cassandra with no clue about the Garbage
> collection and other JVM stuff. When I started tuning it the first time
> with some former colleagues, we ended up removing half of the nodes of the
> cluster and still divided latency per 2. It is an important part of
> Cassandra to tune and often people (including myself) overlook it because
> it's too complex. I'll try to give you a big picture so you can have some
> analysis of what's going on and hopefully do some good to this cluster
> ("some good" - maybe not remove half of the nodes and reduce the latency,
> this was really a strong improvement on a badly tuned GC, but let's see :)
> ).
>
>
>
> The heap is a limited amount of memory used to store Java objects. It's
> composed of 3 sections: The New Generation, The Old Generation, the
> Permananent Generation. New objects go to the New Gen ('HEAP_NEW_SIZE' in
> CMS, auto in G1GC - do not set). From time to time, depending on usage and
> tuning, surviving objects are pushed from the Eden Space where they first
> land to one of the 2 survivor space (the other one is empty). Then,
> depending on the tenuring threshold option (in CMS, auto in G1GC too I
> believe), the data will be passed from one survivor to the other one,
> expiring old data in the process. This cleaning process in the New Gen is
> called the minor garbage collection (Minor GC) and is triggered when Eden
> is full. After the tenuring threshold is reached and the object was moved
> around survivor spaces x times, surviving objects will be promoted (or
> tenured) to the Old Gen. This promotion of living objects is referenced as
> a Major GC.
> This is the most expensive GC, and even though it will have to happen from
> time to time in almost all cases, it's interesting to reduce the total
> duration and frequency of Major GC to improve GC statistics overall. We can
> ignore the permanent Gen that is not triggering any important GC activity.
>
>
>
> Some more information is available here: http://www.oracle.com/
> webfolder/technetwork/tutorials/obe/java/gc01/index.html
> 
>
> In Cassandra, especially, in read-heavy workloads, objects can often
> expire before being promoted if given enough space and time to do so. And
> this is way more performant than promoting objects because we hadn't them
> surviving long enough in the New Gen.
>
>
>
> Using CMS with 20 GB is not recommended (out of the box, as a starting
> point at least) because CMS performances are known to degrade quickly with
> bigger heap than 8 GB. 20 GB is a lot. It also depends on the total memory
> available.
>
>
>
> tried 8GB = OOM
>
> tried 12GB = OOM
>
> tried 20GB w/ G1 = OOM (and long GC pauses usually over 2 secs)
>
> tried 20GB w/ CMS = running
>
>
>
> OOM are not only related to the space available but also to the
> impossibility to clean the heap efficiently enough before we need the
> space. Thus tuning some more option than just the heap size might help.
>
>
> CMS (over G1CG)
> HEAP: 8 to 16 GB.
>
> NEW_HEAP: 25 to 50 % - nothing to do with CPU core contrary to
> documentation/comments in the file imho
>
> MaxTenuringThreshold: 15 - From 1 all the way up to 15, that's what gave
> me the best results in the past, it reduces major GC and makes the most of
> New Gen/minor GC, that are less impacting, but still "stop the world GC".
> Default is 1, which is often way to short to expire objects...
>
> SurvarorRatio: 2 to 8 - co

RE: [EXTERNAL] Re: JVM Heap erratic

2018-07-03 Thread Durity, Sean R
THIS! A well-reasoned and clear explanation of a very difficult topic. This is 
the kind of gold that a user mailing list can provide. Thank you, Alain!


Sean Durity

From: Alain RODRIGUEZ 
Sent: Tuesday, July 03, 2018 6:37 AM
To: user cassandra.apache.org 
Subject: [EXTERNAL] Re: JVM Heap erratic

Hello Randy,

It's normal that the memory in the heap is having this pattern. Java uses 
memory available and when needed clean some memory for new needs, that's the 
variation you see. In your case, it's not really regular but this can depend on 
the workload as well.

I'm a C# .NET guy, so I have no idea if this is normal Java behavior.

I feel you. I started operating Cassandra with no clue about the Garbage 
collection and other JVM stuff. When I started tuning it the first time with 
some former colleagues, we ended up removing half of the nodes of the cluster 
and still divided latency per 2. It is an important part of Cassandra to tune 
and often people (including myself) overlook it because it's too complex. I'll 
try to give you a big picture so you can have some analysis of what's going on 
and hopefully do some good to this cluster ("some good" - maybe not remove half 
of the nodes and reduce the latency, this was really a strong improvement on a 
badly tuned GC, but let's see :) ).

The heap is a limited amount of memory used to store Java objects. It's 
composed of 3 sections: The New Generation, The Old Generation, the Permananent 
Generation. New objects go to the New Gen ('HEAP_NEW_SIZE' in CMS, auto in G1GC 
- do not set). From time to time, depending on usage and tuning, surviving 
objects are pushed from the Eden Space where they first land to one of the 2 
survivor space (the other one is empty). Then, depending on the tenuring 
threshold option (in CMS, auto in G1GC too I believe), the data will be passed 
from one survivor to the other one, expiring old data in the process. This 
cleaning process in the New Gen is called the minor garbage collection (Minor 
GC) and is triggered when Eden is full. After the tenuring threshold is reached 
and the object was moved around survivor spaces x times, surviving objects will 
be promoted (or tenured) to the Old Gen. This promotion of living objects is 
referenced as a Major GC.
This is the most expensive GC, and even though it will have to happen from time 
to time in almost all cases, it's interesting to reduce the total duration and 
frequency of Major GC to improve GC statistics overall. We can ignore the 
permanent Gen that is not triggering any important GC activity.

Some more information is available here: 
http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/gc01/index.html

In Cassandra, especially, in read-heavy workloads, objects can often expire 
before being promoted if given enough space and time to do so. And this is way 
more performant than promoting objects because we hadn't them surviving long 
enough in the New Gen.

Using CMS with 20 GB is not recommended (out of the box, as a starting point at 
least) because CMS performances are known to degrade quickly with bigger heap 
than 8 GB. 20 GB is a lot. It also depends on the total memory available.

tried 8GB = OOM
tried 12GB = OOM
tried 20GB w/ G1 = OOM (and long GC pauses usually over 2 secs)
tried 20GB w/ CMS = running

OOM are not only related to the space available but also to the impossibility 
to clean the heap efficiently enough before we need the space. Thus tuning some 
more option than just the heap size might help.

CMS (over G1CG)
HEAP: 8 to 16 GB.
NEW_HEAP: 25 to 50 % - nothing to do with CPU core contrary to 
documentation/comments in the file imho
MaxTenuringThreshold: 15 - From 1 all the way up to 15, that's what gave me the 
best results in the past, it reduces major GC and makes the most of New 
Gen/minor GC, that are less impacting, but still "stop the world GC". Default 
is 1, which is often way to short to expire objects...
SurvarorRatio: 2 to 8 - controls survivor spaces size. It will be: 'Survivor 
total space = New Gen Size / (SurvarorRatio + 2)'. Dividing by 2 you have the 
size of each survivor. Here it will depend how fast the Eden space is 
allocated. Increasing the survivor space will disminuish the Eden space (where 
new objects are allocated) and there is a tradeoff here as well and a balance 
to find.

I would try with these settings on a canary node:
HEAP - 16 GB (if read heavy, if not probably between 8 and 12 GB is better).
NEW_HEAP - 50% of the heap (4 - 8GB)
MaxTenuringThreshold: 15
SurvarorRatio: 4,

When testing GC, there is not a better way than using a canary node, pick one 
rack and node(s) you want in this rack to test. This should no