ç 究ã®ããã«ã cache2kã©ã€ãã©ãªãæéã®ãã£ãã·ã¥ãæã£ãŠããããšã蚌æããããã«èšèšãããcache2k-benchmarkãã³ãããŒã¯ã䜿çšããŸãã ã ããã§åæã«ç¢ºèªããŠãã ããã ãã®èšäºã¯ãå æ¬çãªããã©ãŒãã³ã¹ãã¹ããç®çãšãããã®ã§ã¯ãªããå°ãªããšãç§åŠçã«æå¹ãªãã®ã§ã¯ãããŸãããApacheIgniteéçºè ã«ãããèš±å¯ããŠãã ããã 倧ããã®é åºãäž»ãªæ©èœãã©ã³ãã³ã°ã®çžå¯Ÿçãªäœçœ®ãèŠãã ãã§ãConcurrentHashMapã«ã¯cache2kãšãã€ãã£ããã£ãã·ã¥ããããŸãã
ãã¹ãæ¹æ³
ãã¹ãæ¹æ³è«ã®äžéšãšããŠãç§ã¯è»èŒªãåçºæãããcache2kã«ã€ããŠèª¬æãããã®ãæ¡çšããŸãã ã JMHããŒã¹ã®ã©ã€ãã©ãªã䜿çšããŠãå€ãã®äžè¬çãªæäœã®ããã©ãŒãã³ã¹ãæ¯èŒããŸãã
- è€æ°ã®ã¹ã¬ããã§ãã£ãã·ã¥ãåãã
- èªã¿åãå°çšã®ããã©ãŒãã³ã¹
ãã®ææ³ã®ãªãã¡ã¬ã³ã¹ãšããŠãConcurrentHashMapã«åºã¥ããŠãã£ãã·ã¥ãå®è£ ããããã«ååŸãããå€ãèæ ®ãããŸããããã¯ãããé«éãªãã®ã¯ãªããšæ³å®ãããããã§ãã ãããã£ãŠããã¹ãŠã®ã«ããŽãªã§ãéäºã¯2äœã«ãªããŸãã Cache2k-benchmarkïŒä»¥éCB ïŒã¯ãcache2kããã³ãã®ä»ã®ããã€ãã®ãããã€ããŒïŒCaffeineãEhCacheãGuavaãInfinispanãTCacheïŒãããã³ConcurrentHashMapã«åºã¥ããã€ãã£ãå®è£ çšã®ã¹ã¯ãªãããå®è£ ããŸãã ä»ã®ãã³ãããŒã¯ãCBã«å®è£ ãããŠããŸãããããã2ã€ã«éå®ããŸãã
枬å®ã¯ã次ã®æ¡ä»¶äžã§å®è¡ãããŸããã
- JDK 1.8.0_45
- JMH 1.11.3
- Intel i7-6700 3.40Ghz 16Gb RAM
- Windows 7 x64
- JVMãã©ã°ïŒ-server -Xmx2G
- Apache Ignite 1.7.0
Apache Igniteãã£ãã·ã¥ã®åäœã¯ãããããžïŒããã§ã¯Apache Igniteããããžã®åºæ¬æŠå¿µãæãåºãããšããå§ãããŸãïŒãšè² è·åæ£ãç°ãªãããã€ãã®ã¢ãŒãã§èª¿æ»ãããŸããã
- ãµãŒããŒããŒãã®ããŒã«ã«ãã£ãã·ã¥ïŒcacheMode = LOCALïŒã
- 1å°ã®ãã·ã³äžã®åæ£ãã£ãã·ã¥ïŒcacheMode = PARTITIONEDãFULL_ASYNCïŒããµãŒããŒãµãŒããŒã
CBã®èŠä»¶ã«åŸã£ãŠãIgniteCacheFactoryã¯ã©ã¹ãå®è£ ãããŸããïŒ ã³ãŒã㯠ã CBãã©ãŒã¯ã«åºã¥ããŠGitHubã§å©çšå¯èœã§ã ïŒã ãµãŒããŒãšã¯ã©ã€ã¢ã³ãã¯ã次ã®èšå®ã§äœæãããŸãã
ãµãŒããŒæ§æ
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="ignite.cfg-server" class="org.apache.ignite.configuration.IgniteConfiguration"> <property name="gridName" value="testGrid"/> <property name="clientMode" value="false"/> <property name="peerClassLoadingEnabled" value="false"/> <property name="cacheConfiguration"> <list> <bean class="org.apache.ignite.configuration.CacheConfiguration"> <property name="name" value="testCache"/> <property name="cacheMode" value="LOCAL"/> <property name="statisticsEnabled" value="false" /> <property name="writeSynchronizationMode" value="FULL_ASYNC"/> </bean> </list> </property> <property name="discoverySpi"> <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi"> <property name="ipFinder"> <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder"> <property name="addresses"> <list> <value>127.0.0.1:47520..47529</value> </list> </property> </bean> </property> <property name="localAddress" value="localhost"/> </bean> </property> <property name="communicationSpi"> <bean class="org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi"> <property name="localAddress" value="localhost"/> </bean> </property> </bean> </beans>
ã¯ã©ã€ã¢ã³ããšãµãŒããŒã®ãã£ãã·ã¥èšå®ãåãã§ããããšãéèŠã§ãã
ãµãŒããŒã¯ããªãã·ã§ã³-Xms1g -Xmx14g -server -XXïŒ+ AggressiveOpts -XXïŒMaxMetaspaceSize = 256mã䜿çšããŠãåãJVMã䜿çšããŠãã¹ãå€ã®ã³ãã³ãã©ã€ã³ããäœæãããŸããã€ãŸããã»ãšãã©ãã¹ãŠã®ã¡ã¢ãªãæäŸããŸãã ãµãŒããŒãèµ·åããŠããã€ã¶ãŒã§æ¥ç¶ããŸãïŒè©³çŽ°ã«ã€ããŠã¯ãã·ãªãŒãºã®2çªç®ã®èšäºãåç §ããŠãã ããïŒã cacheã³ãã³ãã䜿çšããŠããã£ãã·ã¥ãååšããåæç¶æ ã§ããããšã確èªããŸãã
ã¯ã©ã¹ã䜿çšããŠCBãšæ¥ç¶ããŸã
ãã³ãããŒã¯çšã®ãã¡ã¯ããªãŒãã£ãã·ã¥
public class IgniteCacheFactory extends BenchmarkCacheFactory { static final String CACHE_NAME = "testCache"; static IgniteCache cache; static Ignite ignite; static synchronized IgniteCache getIgniteCache() { if (ignite == null) ignite = Ignition.ignite("testGrid"); if (cache == null) cache = ignite.getOrCreateCache(CACHE_NAME); return cache; } @Override public BenchmarkCache<Integer, Integer> create(int _maxElements) { return new MyBenchmarkCache(getIgniteCache()); } static class MyBenchmarkCache extends BenchmarkCache<Integer, Integer> { IgniteCache<Integer, Integer> cache; MyBenchmarkCache(IgniteCache<Integer, Integer> cache) { this.cache = cache; } @Override public Integer getIfPresent(final Integer key) { return cache.get(key); } @Override public void put(Integer key, Integer value) { cache.put(key, value); } @Override public void destroy() { cache.destroy(); } @Override public int getCacheSize() { return cache.localSize(); } @Override public String getStatistics() { return cache.toString() + ": size=" + cache.size(); } } }
ããã§ã¯ãã¯ã©ã€ã¢ã³ãã¢ãŒãã§ãµãŒããŒã«æ¥ç¶ãããµãŒããŒãããã£ãã·ã¥ãååŸããŸãã ãã¹ãã®çµäºæã«ã¯ã©ã€ã¢ã³ããåæ¢ããããšãéèŠã§ããããããªããšãJMHã¯ãã¹ãã®çµäºæã«ãŸã ã¹ã¬ãããåäœããŠããããšãèªããŸã-Igniteã¯ãã®æ©èœã®ããã«å€ãã®ã¹ã¬ãããäœæããŸãã ãŸãããªãã»ããã¯åå埩åŸã«ãã£ãã·ã¥ãåé€ããæéã§ããããšã«æ³šæããŠãã ããã ããã調æ»æ¹æ³ã®ã³ã¹ããšèŠãªããŸããã€ãŸãããã£ãã·ã¥èªäœã®ããã©ãŒãã³ã¹ã ãã§ãªãããã£ãã·ã¥ã®ç®¡çã³ã¹ããèæ ®ããŸãã
ãã³ãããŒã¯ã¯ã©ã¹
@State(Scope.Benchmark) public class IgnitePopulateParallelOnceBenchmark extends PopulateParallelOnceBenchmark { Ignite ignite; { if (ignite == null) ignite = Ignition.start("ignite/ignite-cache.xml"); } @TearDown(Level.Trial) public void destroy() { if (ignite != null) { ignite.close(); ignite = null; } } }
çµæ
mvn clean installã䜿çšããŠãããžã§ã¯ãããã«ãããåŸãããšãã°æ¬¡ã®ã³ãã³ãã§ãã¹ããå®è¡ã§ããŸãã
java -jar <BENCHMARK_HOME> \ benchs.jar PopulateParallelOnceBenchmark -jvmArgs "-server -Xmx14G -XXïŒ+ UseG1GC -XXïŒ+ UseBiasedLocking -XXïŒ+ UseCompressedOops" -gc true -f 2 -wi 3 -w r 30s -t 2 -p cacheFactory = org.cache2k.benchmark.thirdparty.IgniteCacheFactory -rf json -rff eïŒ\ tmp \ 1.jsonã JMHèšå®ã¯å ã®ãã³ãããŒã¯ããåããããã®ã§ãããããã§ã¯èª¬æããŸããã ã-t 1ããã©ã¡ãŒã¿ãŒã¯ããã£ãã·ã¥ã§äœ¿çšããã¹ã¬ããã®æ°ã瀺ããŸãã 念ã®ããã14Gbã®ã¡ã¢ãªã瀺ããŸããã ã-f 2ãã¯ã2ã€ã®JVMãã©ãŒã¯ãäžæããŠãã¹ããå®è¡ããããšãæå³ããŸããããã«ãããä¿¡é ŒåºéïŒJMHåºåã®ããšã©ãŒãåïŒãå€§å¹ ã«æžå°ããŸãã
è€æ°ã®ã¹ã¬ããã§ãã£ãã·ã¥ãåãã
ãŸããcacheMode = LOCALã§Apache Igniteã®ãã¹ããå®è¡ããŸãã ãã®å ŽåããµãŒããŒãšå¯Ÿè©±ããæå³ããªãã®ã§ããµãŒããŒã¢ãŒãã§ãã¹ãããããã«ããŒããäžãã誰ã«ãæ¥ç¶ããŸããã 100äžãã100äžã200äžã400äžã800äžã®æ°åããã£ãã·ã¥ããã®ã«ãããæéã枬å®ããŸãã ã¹ã¬ãã1ã4ã8ã®æ°ïŒ8ã³ã¢ããã»ããµãæã£ãŠããŸãïŒã®å Žåãçµæã¯æ¬¡ã®ããã«ãªããŸãã
4ã€ã®ã¹ããªãŒã ã1ã€ã®ã¹ããªãŒã ã®çŽ2åã®é床ã§ããå Žåãããã«4ã€ã®ã¹ããªãŒã ãè¿œå ãããšçŽ20ïŒ ã®ã²ã€ã³ãåŸãããããšãããããŸãã ã€ãŸããã¹ã±ãŒãªã³ã°ã¯éç·åœ¢ã§ãã æ¯èŒã®ããã«ãConcurrentHashMapãšcache2kã衚瀺ãããã®ãèŠãŠã¿ãŸãããã
ConcurrentHashMapïŒ
cache2kïŒ
ãããã£ãŠãããŒã«ã«ã¢ãŒãã§æ¿å ¥ãããšãIgniteãã£ãã·ã¥ã¯ConcurrentHashMapã®çŽ10åãcache2kã®4ã5åé ããªããŸãã 次ã«ãåããã·ã³äžã®2ã€ã®ãµãŒããŒããŒãéã§ãã£ãã·ã¥ãããŒãã£ã·ã§ã³åå²ã§ãããªãŒããŒããããè©äŸ¡ããŠã¿ãŸãããïŒã€ãŸãããã£ãã·ã¥ã¯ååã«åå²ãããŸãïŒã ããšãã°ãç¬èªã®ã·ãªã¢ã«åã䜿çšããŸããããã¯ãç¬èªã®ã·ãªã¢ã«åããã20åé«éã§ãã ãã¹ãäžã«ããã€ã¶ãŒãèŠãããšãã§ããŸããããã¯çã«ããªã£ãŠããŸããããããžããããŸãã
æåŸã«ããããã®æ²æšãªæ°åãèŠãŸãïŒ
ã€ãŸãããã£ãã·ã¥ãåå²ããŠããã³ã¹ãã¯ããã»ã©ããããŸããã§ãããã10åã¯æªåããŸããã REPLICATEDãã£ãã·ã¥ã¢ãŒãã¯èª¿æ»ãããŸããã§ãããããŒã¿ã¯äž¡æ¹ã®ããŒãã«ä¿åãããŸãã
èªã¿åãå°çš
å€ãã®ãã©ã¡ãŒã¿ãŒã§ç¶æ³ãè€éã«ããªãããã«ã4ã€ã®ã¹ã¬ããã§ãã®ãã¹ããè¡ããIgniteã¯ããŒã«ã«ã§ã®ã¿èµ·åããŸãã ããã§ã¯ã ReadOnlyBenchmarkã䜿çšããŸãã ãã£ãã·ã¥ã«ã¯10äžåã®ãšã³ããªãæ ŒçŽãããŠããããããçãç°ãªãå€ããã£ãã·ã¥ããã©ã³ãã ã«éžæãããŸãã 1ç§ãããã®æäœæ°ã枬å®ãããŸãã
Cache2k / ConcurrentHashMap / IgniteããŒã¿ã¯æ¬¡ã®ãšããã§ãã
ã€ãŸããCache2kã¯ConcurrentHashMapã®1.5ã2.5åãIgniteã¯2ã3åãå£ã£ãŠããŸãã
çµè«
ãããã£ãŠãIgniteã¯ãæ§ããã«èšã£ãŠãããã£ãã·ã¥ã®é床ã«è¡æãäžããŸããã ç§ã¯äºåã«å¯èœãªéé£ã«çããããšããŸãïŒ
- 調çæ¹æ³ãããããªãã ã㧠ãIgniteãããã·ã¥ããããšããè¯ããªããŸãã ottyunitã®å Žåããã¹ãŠãããè¯ããªããŸãã äœæ¥ã¯ããã©ã«ãæ§æã§èª¿æ»ãããŸãããã90ïŒ
ã®ã±ãŒã¹ã§æ¬çªç°å¢ã§ãåãã§ãã
- ãªã³ãŽãšããã ãããŸããŸãªã¯ã©ã¹ã®è£œåãé¡åŸ®é¡ã®çªãªã© Inifinispanã®ãããªãã£ãšæŽç·Žããããã®ãšæ¯èŒãã¹ããããããŸãããããã®ç 究ã§ã¯Igniteã«äžå¯èœãèŠæ±ããŸããã§ããã
- ãªãŒããŒããããæé€ã ãããŒããäžããŠãã£ãã·ã¥ãäœæ/åé€ããè²»çšã®ãããæäœãåæ¢ããããŒã¹ããŒãã®é »åºŠãæžãããŸãã ããããç§ãã¡ã¯ç空ã§éŠ¬ã枬å®ããŠããŸãããïŒ;
- ãã®è£œåã¯ããŒã«ã«ã§ã®äœ¿çšãç®çãšããŠããã ããšã³ã¿ãŒãã©ã€ãºæ©åšãå¿
èŠã§ãã å¯èœã§ãããããããžã®ãªãŒããŒãããå
šäœãå¡ãã€ã¶ãã ãã§ãããããã§ã¯äžåºŠã«ãã¹ãŠãèŠãŸããã ãã¹ãäžãCPUãšã¡ã¢ãªã®%%ã100ïŒ
ã«éããããšã¯ãããŸããã§ããã
- ããã¯è£œåã®è©³çŽ°ã§ãã Igniteã®é©ãã¹ãåãèãããšãçµæã¯éåžžã«äŸ¡å€ããããšã¿ãªãããšãã§ããŸãã ãã£ãã·ã³ã°ã¯å¥ã®ã¹ã¬ããã§ããœã±ãããªã©ãä»ããŠè¡ãããããšã«æ³šæããŠãã ããã äžæ¹ãIgniteã«ã¯ä»ã®æ¹æ³ã¯ãããŸããã
ãŸããªã©ã äžè¬çã«ãIgniteã¯ããã©ãŒãã³ã¹ã®ãœãŒã¹ãšããŠã§ã¯ãªããåæ£ã¢ããªã±ãŒã·ã§ã³ã®ã¢ãŒããã¯ãã£ãã¬ãŒã ã¯ãŒã¯ãšããŠäœ¿çšããå¿ èŠããããŸãã ããããã圌ã¯ããã«æå¶ãããäœããå éããããšãã§ããŸãã ãã¡ãããç§èŠã
Igniteã®ããã©ãŒãã³ã¹ã«é¢ããç§ã®èŠè§£ãå ±æããŠãã ããã