Created
July 1, 2016 11:43
-
-
Save jackeylu/91f8722cf7cba83a44721bcdb041ea05 to your computer and use it in GitHub Desktop.
Cache Operations, currently only with putting.
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); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment