Sunday, September 30, 2012

Coherence Cluster Capacity

Hello!, Understanding the capacity of a cluster is very important, as an overloaded cluster will not perform well.

The overall capacity of a cluster is determined by how many members it has, two physical resources determine the number of members that can be available at a given time, memory and cpu cores.

CPU Considerations:
It is important to understand that coherence is a series of services running in a jvm and these services are asynchronous named threads, all of which require CPU cycles to work, as does the JVM, and the OS, so, when determining your capacity it is very important to remember that each member will increase this overhead, limiting the number of members per box.

Memory Considerations:When deciding the amount of data it is vital to remember that not all of the heap space in the storage node is available for primary storage, in fact, most of it is not. There are several overheads that need to be accounted for:

  • For Partitioned caches each piece of data is backed up on a different JVM, therefore we must account for the size of twice the serialized object size per Object.
  • For Replicated caches the objects are kept unserialized after the first access, and are present in every member and must be sized accordingly.
  • The Keys of the objects and Indexed data are kept unserialized.
  • Every Named Cache has an overhead of 250kb
  • Each entry has an overhead of 144 bytes.
  • Coherence needs some scrap space; that is, space to unserialize and work with objects, when executing listeners, entry processors and aggregators.
  • The JVM has its own overhead and to perform optimally should not be executed over 75 to 80% capacity.  

Sizing your members:
Taking all of those overheads into consideration, we can start to size our members, the sum of whom will be our total capacity.
  • ¼ of the capacity should remain unused to ensure optimal performance by the JVM.
  • ¼ of the capacity should not be used for primary storage and will be used for the overheads Coherence needs.
  • This leaves us with ½ of the JVM to use as storage in to be used in a mix of Partitioned and Replicated storage, however, it is important to take into consideration that:
    • For Partitioned caches you must consider twice the size of the pof serialized object, as it will be stored twice.
    • For Replicated caches you must take into account the native size of the objects.
Taking this into account once you know the size of your objects it becomes trivial to determine how much data you can store per storage node.

Enforcing your cache sizing:
In order to ensure that coherence enforces your cache sizing you must specify on the backing map of each cache Binary as the unit calculator, the maximum size in bytes of primary storage for that cache (remembering that for Partitioned caches the actual memory spent spent is twice that due to the backup) and the eviction strategy.

The dangers of wildcards:As explained above, the sizing is performed per cache, so wildcards break this contract and if you are using wildcards there is no way to directly enforce a sizing policy.
For instance, if you have a cache mapping of my-cache-* and set a high units count to 100MB. When you create a cache named my-cache-one, the maximum amount of data that can be added is 100MB. The problem is you can create an unlimited number of caches using that mapping, and each of them will allow 100MB, therefore, potentially resulting in a out of memory exception.  

Sizing your cluster:
Based on these considerations we can determine how many storage nodes we will need to store the data required by applying a simple formula where x is the number of nodes required:



Which in essence means that you must add the size of each object that you aim to place into a distributed cache and multiply it by the number of objects in that cache, multiply it by two to account for the backups, and divide that by the storage capacity of the JVM, which is, as discussed in the previous session half of the JVM size, minus the size times the number of objects of each replicated cache, as they will take up space in every JVM.
After calculating the number of members that are necessary, you must add overhead to account for the loss of one physical machine, so, if each physical machine holds 3 members, you must add 3.
For instance, if you had three distributed caches, one with 100,000 5k objects, 50,000 1Mb objects, and 1,000,000 2k objects and one replicated cache with 4,000 50k objects, and we are hosting 3 processes per physical machines making the calculation:



next we convert all to the same unit and get our final value:


so, now we know we will need 35 storage enabled members to store the data.


Calculating the number of Members per physical server:
Once the number of members has been determined, you can decide how many members will be in each physical box, however there are some more things to consider, the server hosting the member still needs memory and cycles for the OS to work optimally, and paging/swapping should never be used, so we need to make sure not to use all of the available physical memory with Coherence members.
The CPU usage, as explained above is also very important and if not correctly managed performance will be greatly degraded due to threads fighting over cores.The exact number of members per core will depend on the load, but one core per member is a reasonable starting number, but this should be profiled and tuned by running tests and checking the task backlog Mbean and the CPU usage in the OS, making sure that it is not running too hot or too slow, and adjusting the number of members per box accordingly.

Calculating the number of extend members per cluster
Members running the Coherence*Extend service should be storage disabled and should have JVM’s the same size as the other members, because, even though they will not store data they will potentially be doing multiple aggregations for different clients. It is important to remember that you will need one Thread per active concurrent connection by setting the Thread-count on the proxy configuration, and should derive the number of proxies you need from that, keeping in mind the cpu considerations discussed earlier and that you should at the very least have two on different physical machines for reliability.


Cheers,

3 comments:

  1. Nice article....
    Only a small glitch though with the example showing
    calculation of storage members..I would have expected multiplication by 2 to account for backups. :)

    ReplyDelete
  2. These are genuinely fantastic ideas in regarding blogging. You have touched some fastidious factors here. Any way keep up wrinting. gmail email login

    ReplyDelete