Last active
July 1, 2016 12:16
-
-
Save jackeylu/a4f8b1f4dbb4c55031becfa036a5cb34 to your computer and use it in GitHub Desktop.
Benchmark on simple put and put with event listener.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CacheOperations { | |
public void putOperations(Ignite ignite, String cache_name, int thread_num) { | |
TimeRecord tr = new TimeRecord(); | |
tr.reset(); | |
int step = 20000; | |
PutTask[] tasks = new PutTask[thread_num]; | |
for (int i = 0; i < thread_num; i++) { | |
tasks[i] = new PutTask(ignite, cache_name, step*(i-1), step*i); | |
tasks[i].start(); | |
} | |
for (PutTask task: tasks){ | |
try { | |
task.join(); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
long cost = tr.end(); | |
System.out.println(Format.ops(thread_num*step, cost)); | |
} | |
private class PutTask extends Thread{ | |
private IgniteCache cache; | |
private int begin; | |
private int end; | |
public PutTask(Ignite ignite, String cache_name, int begin, int end){ | |
this.cache = ignite.getOrCreateCache(cache_name); | |
this.begin = begin; | |
this.end = end; | |
} | |
@Override | |
public void run() { | |
for (int i = begin; i < end; i++){ | |
cache.put(i, i); | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Format { | |
public static String ops(long op_num, long milliseconds) { | |
if (milliseconds <= 0) return "NA"; | |
return String.format("%d OPS", op_num*1000/milliseconds); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<beans xmlns="http://www.springframework.org/schema/beans" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" | |
xsi:schemaLocation="http://www.springframework.org/schema/beans | |
http://www.springframework.org/schema/beans/spring-beans.xsd | |
http://www.springframework.org/schema/util | |
http://www.springframework.org/schema/util/spring-util.xsd"> | |
<bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration"> | |
<property name="publicThreadPoolSize" value="64"/> | |
<property name="includeEventTypes"> | |
<list> | |
<util:constant static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_PUT"/> | |
<util:constant static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_REMOVED"/> | |
</list> | |
</property> | |
<property name="discoverySpi"> | |
<bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi"> | |
<property name="localPort" value="8088" /> | |
<property name="ipFinder"> | |
<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder"> | |
<property name="addresses"> | |
<list> | |
<value>x.x.x.x:8088</value> <!-- sample value --> | |
<value>y.y.y.y:8088</value> | |
<value>z.z.z.z:8088</value> | |
</list> | |
</property> | |
</bean> | |
</property> | |
</bean> | |
</property> | |
</bean> | |
</beans> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class IgniteClientCacheEventPut { | |
public static void main(String[] args) { | |
Ignition.setClientMode(true); | |
try (Ignite ignite = Ignition.start(args[0])){ | |
String cache_name = "ignite-cache"; | |
IgniteCache cache = ignite.getOrCreateCache(cache_name); | |
UUID uuid = addEventListener(ignite, cache_name); | |
new CacheOperations().putOperations(ignite, cache_name, Integer.valueOf(args[1])); | |
removeEventListener(ignite, uuid); | |
System.out.println("Cache size: "+cache.size()); | |
ignite.destroyCache(cache_name); | |
} | |
} | |
private static UUID addEventListener(Ignite ignite, final String cache_name) { | |
IgniteBiPredicate<UUID, CacheEvent> localLsnr = new IgniteBiPredicate<UUID, CacheEvent>() { | |
@Override | |
public boolean apply(UUID uuid, CacheEvent event) { | |
return true; | |
} | |
}; | |
IgnitePredicate<CacheEvent> rmtFilter = new IgnitePredicate<CacheEvent>() { | |
@Override | |
public boolean apply(CacheEvent event) { | |
return event.cacheName().equals(cache_name); | |
} | |
}; | |
UUID uuid = ignite.events(ignite.cluster().forServers()).remoteListen(localLsnr, rmtFilter, | |
EventType.EVT_CACHE_OBJECT_PUT, EventType.EVT_CACHE_OBJECT_REMOVED); | |
return uuid; | |
} | |
private static void removeEventListener(Ignite ignite, UUID uuid) { | |
System.out.println("Stopping remote listeners with uuid " + uuid); | |
ignite.events().stopRemoteListen(uuid); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class IgniteClientSimplePut { | |
public static void main(String[] args) { | |
Ignition.setClientMode(true); | |
try (Ignite ignite = Ignition.start(args[0])){ | |
String cache_name = "ignite-cache"; | |
IgniteCache cache = ignite.getOrCreateCache(cache_name); | |
new CacheOperations().putOperations(ignite, cache_name, Integer.valueOf(args[1])); | |
System.out.println("Cache size: "+cache.size()); | |
ignite.destroyCache(cache_name); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
export IGNITE_HOME=`pwd` | |
export classpath=lib/ignite1.6/*:target/classes/ | |
export MAIN_CLASS=example.IgniteClientCacheEventPut | |
export IGNTIE_CONF=lib/ignite1.6/ignite.xml | |
export JVVM_OPT="-Xms512m" | |
java $JVVM_OPT -cp $classpath $MAIN_CLASS $IGNTIE_CONF $1 $2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
export IGNITE_HOME=`pwd` | |
export classpath=lib/ignite1.6/*:target/classes/ | |
export MAIN_CLASS=org.apache.ignite.startup.cmdline.CommandLineStartup | |
export IGNTIE_CONF=lib/ignite1.6/ignite.xml | |
export JVVM_OPT="-Xms512m" | |
java $JVVM_OPT -cp $classpath $MAIN_CLASS $IGNTIE_CONF |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
export IGNITE_HOME=`pwd` | |
export classpath=lib/ignite1.6/*:target/classes/ | |
export MAIN_CLASS=example.IgniteClientSimplePut | |
export IGNTIE_CONF=lib/ignite1.6/ignite.xml | |
export JVVM_OPT="-Xms512m" | |
java $JVVM_OPT -cp $classpath $MAIN_CLASS $IGNTIE_CONF $1 $2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TimeRecord { | |
private long start_time; | |
private long cost_time; | |
/** | |
* reset the time record. | |
* @return the current time in milliseconds. | |
*/ | |
public long reset() { | |
start_time = System.currentTimeMillis(); | |
cost_time = 0; | |
return start_time; | |
} | |
/** | |
* return cost time in milliseconds | |
* @return cost time in milliseconds | |
*/ | |
public long end() { | |
cost_time = System.currentTimeMillis() - start_time; | |
return cost_time; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment