Ignite性能测试以及对Redis的对比

为了对Ignite做一个基本了解,做了一个性能测试,测试方法也比较简单主要是针对client模式,因为这种方法和使用redis的方式特别像。测试方法很简单主要是下面几点:

不作参数优化,默认配置进行测试

在一台linux服务器上部署Ignite服务端,然后自己的笔记本作客户端

按1,10,20,50,100,200线程进行测试

测试环境说明

服务器:

[09:36:56] ver. 1.7.0#20160801-sha1:383273e3 [09:36:56] OS: Linux 2.6.32-279.el6.x86_64 amd64 [09:36:56] VM information: Java(TM) SE Runtime Environment 1.7.0_07-b10 Oracle Corporation Java HotSpot(TM) 64-Bit Server VM 23.3-b01 [09:36:56] Configured plugins: [09:36:56] ^-- None [09:36:56] [09:36:56] Security status [authentication=off, tls/ssl=off]

CPU:4核
内存8GB
网卡100M
虚拟机

客户机:

[13:05:32] ver. 1.7.0#20160801-sha1:383273e3 [13:05:32] OS: Windows 7 6.1 amd64 [13:05:32] VM information: Java(TM) SE Runtime Environment 1.8.0_40-b26 Oracle Corporation Java HotSpot(TM) 64-Bit Server VM 25.40-b25 [13:05:32] Initial heap size is 128MB (should be no less than 512MB, use -Xms512m -Xmx512m). [13:05:34] Configured plugins: [13:05:34] ^-- None [13:05:34] [13:05:35] Security status [authentication=off, tls/ssl=off] [13:05:51] Performance suggestions for grid (fix if possible) [13:05:51] To disable, set -DIGNITE_PERFORMANCE_SUGGESTIONS_DISABLED=true [13:05:51] ^-- Decrease number of backups (set 'backups' to 0)

CPU:4核,i5-4210u
内存8GB
笔记本win7 64位
网卡:100M

测试代码

package org.j2server.j2cache.cache.iginte; import java.util.Arrays; import org.apache.ignite.Ignite; import org.apache.ignite.IgniteCache; import org.apache.ignite.Ignition; import org.apache.ignite.cache.CacheMode; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; public class IgniteTest { //测试的数据行数 private static final Integer test_rows = 50000; private static final Integer thread_cnt = 10; private static final String cacheName = "Ignite Cache"; private static Ignite ignite; private static boolean client_mode = false; static { getIgnite(); } public static void main(String[] args) { MultiThread(); } private static Ignite getIgnite() { if (ignite == null) { TcpDiscoverySpi spi = new TcpDiscoverySpi(); TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder(); ipFinder.setAddresses(Arrays.asList("192.168.49.204")); spi.setIpFinder(ipFinder); CacheConfiguration cacheConfiguration = new CacheConfiguration<String, DataClass>(); cacheConfiguration.setCacheMode(CacheMode.PARTITIONED); cacheConfiguration.setBackups(1); IgniteConfiguration cfg = new IgniteConfiguration(); cfg.setClientMode(client_mode); cfg.setDiscoverySpi(spi); cfg.setCacheConfiguration(cacheConfiguration); ignite = Ignition.start(cfg); } System.out.println("是否客户端模式:" + client_mode); return ignite; } private static void MultiThread() { System.out.println("=================================================================="); System.out.println("开始测试多线程写入[线程数:"+thread_cnt+"]"); Long startTime = System.currentTimeMillis(); Thread[] threads = new Thread[thread_cnt]; Ignite ignite = getIgnite(); IgniteCache<String, DataClass> cache = ignite.getOrCreateCache(cacheName); for (int i = 0; i < threads.length; i++) { threads[i] = new Thread(new TestThread(true, cache)); } for (int i = 0; i< threads.length; i++) { threads[i].start(); } for(Thread thread : threads){ try { thread.join(); } catch (InterruptedException e) { e.printStackTrace(); } } Long endTime=System.currentTimeMillis(); //获取结束时间 float interval = endTime-startTime == 0 ? 1 : endTime-startTime; float tpms = (float)test_rows/interval; System.out.println("程序运行时间: "+ interval+"ms"); System.out.println("每毫秒写入:"+tpms+"条。"); System.out.println("每秒写入:"+tpms*1000+"条。"); System.out.println("=================================================================="); System.out.println("开始测试多线程读取[线程数:"+thread_cnt+"]"); startTime = System.currentTimeMillis(); Thread[] readthreads = new Thread[thread_cnt]; for (int i = 0; i < readthreads.length; i++) { readthreads[i] = new Thread(new TestThread(false, cache)); } for (int i = 0; i< readthreads.length; i++) { readthreads[i].start(); } for(Thread thread : readthreads){ try { thread.join(); } catch (InterruptedException e) { e.printStackTrace(); } } endTime=System.currentTimeMillis(); //获取结束时间 interval = endTime-startTime == 0 ? 1 : endTime-startTime; tpms = (float)test_rows/interval; System.out.println("程序运行时间: "+ interval+"ms"); System.out.println("每毫秒读取:"+tpms+"条。"); System.out.println("每秒读取:"+tpms*1000+"条。"); } static class TestThread implements Runnable { private boolean readMode = true; private IgniteCache<String, DataClass> cache; public TestThread(boolean readMode, IgniteCache<String, DataClass> cache){ this.readMode = readMode; this.cache = cache; } @Override public void run() { for (int i = 0; i < test_rows/thread_cnt; i++) { if (this.readMode) { cache.get(Integer.toString(i)); } else { DataClass dc = new DataClass(); dc.setName(Integer.toString(i)); dc.setValue(i); dc.setStrValue("asdfadsfasfda"); cache.put(Integer.toString(i), dc); } } } } } import java.io.Serializable; public class DataClass implements Serializable{ private String name; private long value; private String strValue; public String getName() { return name; } public void setName(String name) { this.name = name; } public long getValue() { return value; } public void setValue(long value) { this.value = value; } public String getStrValue() { return strValue; } public void setStrValue(String strValue) { this.strValue = strValue; } } 测试数据

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/07c00b5156f3a55d80b9ef14b362e720.html