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/26 20:00:08 UTC

Read-through cache performance

Hi,

I use the following code to find the maximum speed of a read-through cache.
I use 

cacheCfg.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(Duration.ZERO));
and the load function just returns null:

public static class NullCache extends CacheStoreAdapter<Long, Long> {
	@Override public Long load(Long key) { return null; /* MAX PERFORMANCE */ }
	@Override public void write(Cache.Entry<? extends Long, ? extends Long>
entry) {}
	@Override public void delete(Object key) { }
	@Override public void loadCache(IgniteBiInClosure<Long, Long> clo,
Object... args) { }
}
public static void testReadPerformance() {
	IgniteConfiguration cfg = new IgniteConfiguration();
	Ignite ignite = Ignition.start(cfg);
	final long itemCount = 1000000;
	for (int readThrough = 0; readThrough <= 1; readThrough++) {
		CacheConfiguration<Long, Long> cacheCfg = new CacheConfiguration<>();
		cacheCfg.setCacheMode(CacheMode.LOCAL);
		cacheCfg.setOnheapCacheEnabled(true);
		cacheCfg.setBackups(0);
		cacheCfg.setName(readThrough==1 ? "ReadThroughCache" : "EmptyCache");
		if (readThrough == 1) {
			cacheCfg.setCacheStoreFactory(FactoryBuilder.factoryOf(NullCache.class));
			cacheCfg.setReadThrough(true);
		
cacheCfg.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(Duration.ZERO));
		}

		IgniteCache<Long, Long> longCache = ignite.getOrCreateCache(cacheCfg);
		Instant t1 = Instant.now();
		for (long i = 0; i < itemCount; i++) {
			Long l = longCache.get(i);
		}
		Instant t2 = Instant.now();
		long readPerformance = (1000L * itemCount) /
java.time.Duration.between(t1, t2).toMillis();
		System.out.println(longCache.getName() + ": " + readPerformance + "
reads/second");
	}
}

Result:	
	"C:\Program Files\Java\jdk1.8.0_45\bin\java"
	[21:17:35] ver. 2.0.0#20170430-sha1:d4eef3c6
	[21:17:35] OS: Windows 7 6.1 amd64
	[21:17:39] Topology snapshot [ver=1, servers=1, clients=0, CPUs=12,
heap=7.1GB]
*	EmptyCache: 928505 reads/second
	ReadThroughCache: 29709 reads/second*

I don't expect the same speed as an empty cache, but something seems wrong.
How can I improve this?
Thanks.
Pascal





--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Read-through-cache-performance-tp14085.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Read-through cache performance

Posted by Pascal <pa...@gmail.com>.
Because I want the cache to not consume any memory. Is there a better way to
achieve this?

A) When I leave out setExpiryPolicyFactory(), it gets a little better:
	63195 63488 66804 65116 64771 64045 64234 65057 63991 64061 64213 64374 

B) When I then replace Long l = longCache.get(i); with longCache.put(i, i);
Long l = longCache.get(i); I get:
	255167 407166 321233 454752 455788 460617 426439 375939 471698 409165
469483 452079 
  Note that each run uses the same cache.

In my understanding, the difference between A and B is the call to
NullCache.load() for A. Why is that so slow? Is it possible other ways of
retrieving the data are tried first, and then, after those fail, the
NullCache is used?
Thanks again for your help.
Pascal




--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Read-through-cache-performance-tp14085p14116.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Read-through cache performance

Posted by Yakov Zhdanov <yz...@apache.org>.
Any reason why you left expiry policy?

--Yakov

Re: Read-through cache performance

Posted by Pascal <pa...@gmail.com>.
Hi Yakov,

I wanted to compare read-through to normal operation. For a non-read-through
cache I get 600.000+ reads/second. Below is the code with an extra loop and
the results:

IgniteConfiguration cfg = new IgniteConfiguration();
Ignite ignite = Ignition.start(cfg);
for(int run=0; run<60; run++) {
	final long itemCount = 1000000;
	CacheConfiguration<Long, Long> cacheCfg = new CacheConfiguration<>();
	cacheCfg.setCacheMode(CacheMode.LOCAL);
	cacheCfg.setOnheapCacheEnabled(true);
	cacheCfg.setBackups(0);
	cacheCfg.setName("ReadThroughCache");
	cacheCfg.setCacheStoreFactory(FactoryBuilder.factoryOf(NullCache.class));
	cacheCfg.setReadThrough(true);

cacheCfg.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(Duration.ZERO));
	IgniteCache<Long, Long> longCache = ignite.getOrCreateCache(cacheCfg);
	Instant t1 = Instant.now();
	for (long i = 0; i < itemCount; i++) {
		Long l = longCache.get(i);
	}
	Instant t2 = Instant.now();
	long readPerformance = (1000L * itemCount) / java.time.Duration.between(t1,
t2).toMillis();
	System.out.println(longCache.getName() + ": " + readPerformance + "
reads/second");
}

ReadThroughCache: 43708 reads/second
ReadThroughCache: 44334 reads/second
ReadThroughCache: 44128 reads/second
ReadThroughCache: 43777 reads/second
ReadThroughCache: 44603 reads/second
ReadThroughCache: 44251 reads/second
ReadThroughCache: 42959 reads/second
ReadThroughCache: 44109 reads/second
ReadThroughCache: 47496 reads/second
ReadThroughCache: 42749 reads/second
ReadThroughCache: 46713 reads/second
ReadThroughCache: 42810 reads/second
ReadThroughCache: 43005 reads/second
ReadThroughCache: 44521 reads/second
ReadThroughCache: 44812 reads/second
ReadThroughCache: 45326 reads/second
ReadThroughCache: 43859 reads/second
ReadThroughCache: 42718 reads/second
ReadThroughCache: 44351 reads/second
ReadThroughCache: 42676 reads/second
ReadThroughCache: 43775 reads/second
ReadThroughCache: 43738 reads/second
ReadThroughCache: 44334 reads/second
ReadThroughCache: 43248 reads/second
ReadThroughCache: 46490 reads/second
ReadThroughCache: 44460 reads/second
ReadThroughCache: 42235 reads/second
ReadThroughCache: 44111 reads/second
ReadThroughCache: 42946 reads/second
ReadThroughCache: 44614 reads/second
ReadThroughCache: 43181 reads/second
ReadThroughCache: 42784 reads/second
ReadThroughCache: 44686 reads/second
ReadThroughCache: 42435 reads/second
ReadThroughCache: 43865 reads/second
ReadThroughCache: 45026 reads/second
ReadThroughCache: 43101 reads/second
ReadThroughCache: 43652 reads/second
ReadThroughCache: 43645 reads/second
ReadThroughCache: 43406 reads/second
ReadThroughCache: 45934 reads/second
ReadThroughCache: 43940 reads/second
ReadThroughCache: 42947 reads/second
ReadThroughCache: 45587 reads/second
ReadThroughCache: 43497 reads/second
ReadThroughCache: 49925 reads/second
ReadThroughCache: 57696 reads/second
ReadThroughCache: 58190 reads/second
ReadThroughCache: 47160 reads/second
ReadThroughCache: 49212 reads/second
ReadThroughCache: 46886 reads/second
ReadThroughCache: 55987 reads/second
ReadThroughCache: 50666 reads/second
ReadThroughCache: 46674 reads/second
ReadThroughCache: 45922 reads/second
ReadThroughCache: 44537 reads/second
ReadThroughCache: 46838 reads/second
ReadThroughCache: 44929 reads/second
ReadThroughCache: 47001 reads/second
ReadThroughCache: 49743 reads/second

Thank you for your help.
Pascal




--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Read-through-cache-performance-tp14085p14106.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Read-through cache performance

Posted by Yakov Zhdanov <yz...@apache.org>.
Pascal,

Why do you have expiry policy in one run and do not have it in another?
Please remove it and rerun your test. Also, can you please wrap your loop
in another loop and take 60 measurements in a row.

--Yakov