You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by Pascal <pa...@gmail.com> on 2017/06/24 14:40:38 UTC
Measuring cache size and performance
Hi,
I'm trying to test the singlethreaded-performance and memory consumption of
an Ignite cache using the following code:
public class CachePerformance {
public static class PerformancePerson {public long id; public long
orgId; public String name; public int salary;
public PerformancePerson(long id, long orgId, String name, int
salary) {
this.id = id; this.orgId = orgId; this.name = name; this.salary
= salary;
}
}
public static void performanceTest() throws
java.lang.InterruptedException {
long personCount = 5000000;
Boolean onHeapCache = true;
final String PERSON_CACHE = "myPersonCache";
final long QUERY_COUNT = 1000000;
CacheConfiguration<Long, PerformancePerson> personCacheCfg = new
CacheConfiguration<>(PERSON_CACHE);
personCacheCfg.setCacheMode(CacheMode.LOCAL);
personCacheCfg.setOnheapCacheEnabled(onHeapCache);
personCacheCfg.setBackups(0);
IgniteConfiguration cfg = new IgniteConfiguration();
cfg.setPublicThreadPoolSize(1);
Ignite ignite = Ignition.start(cfg);
IgniteCache<Long, PerformancePerson> personCache =
ignite.getOrCreateCache(personCacheCfg);
long usageEmpty = MemoryUtil.deepMemoryUsageOf(personCache);
Instant t1 = Instant.now();
for (long i = 0; i < personCount; i++) {
personCache.put(i, new PerformancePerson(i, i/10, "SampleName" +
i, 10000 + (int) i * 10));
}
Instant t2 = Instant.now();
long usageFull = MemoryUtil.deepMemoryUsageOf(personCache);
Instant t3 = Instant.now();
for(long i=0; i< QUERY_COUNT; i++) {
long id = ThreadLocalRandom.current().nextLong(personCount);
PerformancePerson p = personCache.get(id);
}
Instant t4 = Instant.now();
Duration writeDuration = Duration.between(t1, t2);
Duration readDuration = Duration.between(t3, t4);
System.out.println("OnHeap="+onHeapCache + " PersonCount=" +
personCount +
" avgItemSize=" + (usageFull - usageEmpty) / personCount + "
"
+(1000L * personCount) / writeDuration.toMillis() + "
writes/second "
+(1000L * QUERY_COUNT) / readDuration.toMillis() +"
reads/second");
}
}
Result:
"C:\Program Files\Java\jdk1.8.0_45\bin\java"
[15:15:06] ver. 2.0.0#20170430-sha1:d4eef3c6
[15:15:06] OS: Windows 7 6.1 amd64
[15:15:10] Topology snapshot [ver=1, servers=1, clients=0, CPUs=12,
heap=7.1GB]
*OnHeap=true PersonCount=5000000 avgItemSize=332 183170 writes/second
647249 reads/second*
A few questions I have:
1) I use version 0.03 of Classmexer to estimate the size of the cache. Do
you know of a more reliable way to do this? I tried, JOL, but it doesn't
show the entire cache size. I explicitely want to include any indexes,
hashmaps and other (pre-)allocated space in the cache.
2) Are these timings and sizes realistic for Ignite? The avgItemSize is
about twice as high as I would expect for such a simple POJO together with a
hashmap.
3) Can my code be improved to more reliably measure the real-world
performance of Ignite?
Thank you very much for your help.
Pascal
--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Measuring-cache-size-and-performance-tp14072.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.
Re: Measuring cache size and performance
Posted by Andrey Mashenkov <an...@gmail.com>.
Hi,
Looks like:
- "size" is a difference between retention size of cache before and after
test.
- "avgItemSize" is just "size/count"
So, avgItemSize also includes key and value size.
Assume, we have 64-bit JVM with compressed oops, so links has 4 bytes
overhead and there is 8 bytes alignment.
Key size - 8 (long) ~ 24 (as wrapped Long object with aligment).
Value size - 12 (obj header) +8(long) +8(long) + 4(ref to String) + 4(int)
~ 40 (with 8 byte alignment)
Value String field size - 12 (obj header) + 4(hash) + 4(ref to char[]) + ~
24 (with 8 byte alignment)
Char array - 12 (obj header) + 4 (size) + 2*17 (chars) ~ 56 (with 8 byte
alignment)
Total value size: 120 bytes
Total overhead: ~ 147 bytes + (primary index for sql) - (Hashmap buckets
size).
On Fri, Jun 30, 2017 at 9:56 PM, Pascal <pa...@gmail.com> wrote:
> Hi Andrew,
>
> I measured this on 2.0.
> size= 0MB count=64 avgItemSize=7431
> size= 0MB count=128 avgItemSize=3852
> size= 0MB count=256 avgItemSize=2061
> size= 0MB count=512 avgItemSize=1164
> size= 0MB count=1024 avgItemSize=716
> size= 0MB count=2048 avgItemSize=492
> size= 1MB count=4096 avgItemSize=380
> size= 2MB count=8192 avgItemSize=324
> size= 4MB count=16384 avgItemSize=303
> size= 8MB count=32768 avgItemSize=286
> size= 17MB count=65536 avgItemSize=284
> size= 34MB count=131072 avgItemSize=277
> size= 69MB count=262144 avgItemSize=276
> size= 137MB count=524288 avgItemSize=275
> size= 279MB count=1048576 avgItemSize=279
> size= 551MB count=2097152 avgItemSize=275
> size= 1103MB count=4194304 avgItemSize=275
> I assume the amount of unsued free space is negligible with caches bigger
> than +/- 32MB. Correct?
>
> Pascal
>
>
>
> --
> View this message in context: http://apache-ignite-users.
> 70518.x6.nabble.com/Measuring-cache-size-and-performance-
> tp14072p14187.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>
--
Best regards,
Andrey V. Mashenkov
Re: Measuring cache size and performance
Posted by Pascal <pa...@gmail.com>.
Hi Andrew,
I measured this on 2.0.
size= 0MB count=64 avgItemSize=7431
size= 0MB count=128 avgItemSize=3852
size= 0MB count=256 avgItemSize=2061
size= 0MB count=512 avgItemSize=1164
size= 0MB count=1024 avgItemSize=716
size= 0MB count=2048 avgItemSize=492
size= 1MB count=4096 avgItemSize=380
size= 2MB count=8192 avgItemSize=324
size= 4MB count=16384 avgItemSize=303
size= 8MB count=32768 avgItemSize=286
size= 17MB count=65536 avgItemSize=284
size= 34MB count=131072 avgItemSize=277
size= 69MB count=262144 avgItemSize=276
size= 137MB count=524288 avgItemSize=275
size= 279MB count=1048576 avgItemSize=279
size= 551MB count=2097152 avgItemSize=275
size= 1103MB count=4194304 avgItemSize=275
I assume the amount of unsued free space is negligible with caches bigger
than +/- 32MB. Correct?
Pascal
--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Measuring-cache-size-and-performance-tp14072p14187.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.
Re: Measuring cache size and performance
Posted by Andrey Mashenkov <an...@gmail.com>.
Hi Pascal,
What version of Ignite do you use?
From 2.0 version, Ignite has different memory model like - page memory.
So, memory allocated on page basis and you can have partially free pages.
On Wed, Jun 28, 2017 at 8:21 PM, Pascal <pa...@gmail.com> wrote:
> Thank you for your answer Andrew.
>
> From [1]: /GridGain/ will typically add around 200 bytes overhead to each
> entry
>
> I found ObjectProfiler.sizeof() gives a more reliable size size indication
> than Classmexer. It now gives me an average size of 275 bytes, which seems
> about right.
>
> Thanks again.
> Pascal
>
>
>
> --
> View this message in context: http://apache-ignite-users.
> 70518.x6.nabble.com/Measuring-cache-size-and-performance-
> tp14072p14147.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>
--
Best regards,
Andrey V. Mashenkov
Re: Measuring cache size and performance
Posted by Pascal <pa...@gmail.com>.
Thank you for your answer Andrew.
From [1]: /GridGain/ will typically add around 200 bytes overhead to each
entry
I found ObjectProfiler.sizeof() gives a more reliable size size indication
than Classmexer. It now gives me an average size of 275 bytes, which seems
about right.
Thanks again.
Pascal
--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Measuring-cache-size-and-performance-tp14072p14147.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.
Re: Measuring cache size and performance
Posted by Andrey Mashenkov <an...@gmail.com>.
Hi Pascal,
1,2. Please, read the article [1] for capacity planning. Ignite has an
overhead on each entry for internal purposes.
3. Ignite is designed as distributed in-memory solution. Try to add more
nodes, switch cache to PARTITIONED [2] mode and use data streamer [3] for
populating the cache.
[1] https://apacheignite.readme.io/docs/capacity-planning
[2] https://apacheignite.readme.io/docs/cache-modes#partitioned-mode
[3] https://apacheignite.readme.io/docs/data-streamers#ignitedatastreamer
On Sat, Jun 24, 2017 at 5:40 PM, Pascal <pa...@gmail.com> wrote:
> Hi,
>
> I'm trying to test the singlethreaded-performance and memory consumption of
> an Ignite cache using the following code:
>
> public class CachePerformance {
> public static class PerformancePerson {public long id; public long
> orgId; public String name; public int salary;
> public PerformancePerson(long id, long orgId, String name, int
> salary) {
> this.id = id; this.orgId = orgId; this.name = name;
> this.salary
> = salary;
> }
> }
>
> public static void performanceTest() throws
> java.lang.InterruptedException {
> long personCount = 5000000;
> Boolean onHeapCache = true;
>
> final String PERSON_CACHE = "myPersonCache";
> final long QUERY_COUNT = 1000000;
> CacheConfiguration<Long, PerformancePerson> personCacheCfg = new
> CacheConfiguration<>(PERSON_CACHE);
> personCacheCfg.setCacheMode(CacheMode.LOCAL);
> personCacheCfg.setOnheapCacheEnabled(onHeapCache);
> personCacheCfg.setBackups(0);
> IgniteConfiguration cfg = new IgniteConfiguration();
> cfg.setPublicThreadPoolSize(1);
> Ignite ignite = Ignition.start(cfg);
> IgniteCache<Long, PerformancePerson> personCache =
> ignite.getOrCreateCache(personCacheCfg);
> long usageEmpty = MemoryUtil.deepMemoryUsageOf(personCache);
> Instant t1 = Instant.now();
>
> for (long i = 0; i < personCount; i++) {
> personCache.put(i, new PerformancePerson(i, i/10, "SampleName"
> +
> i, 10000 + (int) i * 10));
> }
> Instant t2 = Instant.now();
> long usageFull = MemoryUtil.deepMemoryUsageOf(personCache);
>
> Instant t3 = Instant.now();
> for(long i=0; i< QUERY_COUNT; i++) {
> long id = ThreadLocalRandom.current().nextLong(personCount);
> PerformancePerson p = personCache.get(id);
> }
> Instant t4 = Instant.now();
> Duration writeDuration = Duration.between(t1, t2);
> Duration readDuration = Duration.between(t3, t4);
> System.out.println("OnHeap="+onHeapCache + " PersonCount=" +
> personCount +
> " avgItemSize=" + (usageFull - usageEmpty) / personCount +
> "
> "
> +(1000L * personCount) / writeDuration.toMillis() + "
> writes/second "
> +(1000L * QUERY_COUNT) / readDuration.toMillis() +"
> reads/second");
> }
> }
>
> Result:
> "C:\Program Files\Java\jdk1.8.0_45\bin\java"
> [15:15:06] ver. 2.0.0#20170430-sha1:d4eef3c6
> [15:15:06] OS: Windows 7 6.1 amd64
> [15:15:10] Topology snapshot [ver=1, servers=1, clients=0, CPUs=12,
> heap=7.1GB]
> *OnHeap=true PersonCount=5000000 avgItemSize=332 183170
> writes/second
> 647249 reads/second*
>
> A few questions I have:
> 1) I use version 0.03 of Classmexer to estimate the size of the cache. Do
> you know of a more reliable way to do this? I tried, JOL, but it doesn't
> show the entire cache size. I explicitely want to include any indexes,
> hashmaps and other (pre-)allocated space in the cache.
> 2) Are these timings and sizes realistic for Ignite? The avgItemSize is
> about twice as high as I would expect for such a simple POJO together with
> a
> hashmap.
> 3) Can my code be improved to more reliably measure the real-world
> performance of Ignite?
>
> Thank you very much for your help.
> Pascal
>
>
>
> --
> View this message in context: http://apache-ignite-users.
> 70518.x6.nabble.com/Measuring-cache-size-and-performance-tp14072.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>
--
Best regards,
Andrey V. Mashenkov