|
|
@ -14,6 +14,43 @@ import org.redisson.client.RedisClient;
|
|
|
|
public abstract class BaseConcurrentTest extends BaseTest {
|
|
|
|
public abstract class BaseConcurrentTest extends BaseTest {
|
|
|
|
|
|
|
|
|
|
|
|
protected void testMultiInstanceConcurrency(int iterations, final RedissonRunnable runnable) throws InterruptedException {
|
|
|
|
protected void testMultiInstanceConcurrency(int iterations, final RedissonRunnable runnable) throws InterruptedException {
|
|
|
|
|
|
|
|
System.out.println("Multi Instance Concurrent Job Interation: " + iterations);
|
|
|
|
|
|
|
|
ForkJoinPool pool = new ForkJoinPool(Runtime.getRuntime().availableProcessors() * 2);
|
|
|
|
|
|
|
|
final Map<Integer, RedissonClient> instances = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pool.submit(() -> {
|
|
|
|
|
|
|
|
IntStream.range(0, iterations)
|
|
|
|
|
|
|
|
.parallel()
|
|
|
|
|
|
|
|
.forEach((i) -> instances.put(i, BaseTest.createInstance()));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long watch = System.currentTimeMillis();
|
|
|
|
|
|
|
|
pool.awaitQuiescence(5, TimeUnit.MINUTES);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pool.submit(() -> {
|
|
|
|
|
|
|
|
IntStream.range(0, iterations)
|
|
|
|
|
|
|
|
.parallel()
|
|
|
|
|
|
|
|
.forEach((i) -> runnable.run(instances.get(i)));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pool.shutdown();
|
|
|
|
|
|
|
|
Assert.assertTrue(pool.awaitTermination(RedissonRuntimeEnvironment.isTravis ? 10 : 3, TimeUnit.MINUTES));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println("multi: " + (System.currentTimeMillis() - watch));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pool = new ForkJoinPool();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pool.submit(() -> {
|
|
|
|
|
|
|
|
instances.values()
|
|
|
|
|
|
|
|
.parallelStream()
|
|
|
|
|
|
|
|
.<RedisClient>forEach((r) -> r.shutdown());
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pool.shutdown();
|
|
|
|
|
|
|
|
Assert.assertTrue(pool.awaitTermination(5, TimeUnit.MINUTES));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void testMultiInstanceConcurrencySequentiallyLaunched(int iterations, final RedissonRunnable runnable) throws InterruptedException {
|
|
|
|
System.out.println("Multi Instance Concurrent Job Interation: " + iterations);
|
|
|
|
System.out.println("Multi Instance Concurrent Job Interation: " + iterations);
|
|
|
|
ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2);
|
|
|
|
ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2);
|
|
|
|
|
|
|
|
|
|
|
@ -45,25 +82,25 @@ public abstract class BaseConcurrentTest extends BaseTest {
|
|
|
|
|
|
|
|
|
|
|
|
protected void testSingleInstanceConcurrency(int iterations, final RedissonRunnable runnable) throws InterruptedException {
|
|
|
|
protected void testSingleInstanceConcurrency(int iterations, final RedissonRunnable runnable) throws InterruptedException {
|
|
|
|
System.out.println("Single Instance Concurrent Job Interation: " + iterations);
|
|
|
|
System.out.println("Single Instance Concurrent Job Interation: " + iterations);
|
|
|
|
ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2);
|
|
|
|
final RedissonClient r = BaseTest.createInstance();
|
|
|
|
|
|
|
|
|
|
|
|
final RedissonClient redisson = BaseTest.createInstance();
|
|
|
|
|
|
|
|
long watch = System.currentTimeMillis();
|
|
|
|
long watch = System.currentTimeMillis();
|
|
|
|
for (int i = 0; i < iterations; i++) {
|
|
|
|
|
|
|
|
executor.execute(new Runnable() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
|
|
|
|
runnable.run(redisson);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
executor.shutdown();
|
|
|
|
ForkJoinPool pool = new ForkJoinPool(Runtime.getRuntime().availableProcessors() * 2);
|
|
|
|
Assert.assertTrue(executor.awaitTermination(5, TimeUnit.MINUTES));
|
|
|
|
|
|
|
|
|
|
|
|
pool.submit(() -> {
|
|
|
|
|
|
|
|
IntStream.range(0, iterations)
|
|
|
|
|
|
|
|
.parallel()
|
|
|
|
|
|
|
|
.forEach((i) -> {
|
|
|
|
|
|
|
|
runnable.run(r);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pool.shutdown();
|
|
|
|
|
|
|
|
Assert.assertTrue(pool.awaitTermination(RedissonRuntimeEnvironment.isTravis ? 10 : 3, TimeUnit.MINUTES));
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println(System.currentTimeMillis() - watch);
|
|
|
|
System.out.println(System.currentTimeMillis() - watch);
|
|
|
|
|
|
|
|
|
|
|
|
redisson.shutdown();
|
|
|
|
r.shutdown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|