-
-
Save aboudnik/3419fdc3872cc3051a1d to your computer and use it in GitHub Desktop.
performance degradation when 1/2 of misseses
This file contains 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
package com.epam.ignite; | |
import org.apache.ignite.Ignite; | |
import org.apache.ignite.IgniteCache; | |
import org.apache.ignite.IgniteCountDownLatch; | |
import org.apache.ignite.Ignition; | |
import org.apache.ignite.cache.CacheAtomicityMode; | |
import org.apache.ignite.cache.CacheMode; | |
import org.apache.ignite.cache.CacheWriteSynchronizationMode; | |
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; | |
import org.apache.ignite.transactions.Transaction; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
import java.util.concurrent.TimeUnit; | |
/** | |
* @author Alexandre Boudnik | |
* @since 10/26/2015 | |
* | |
* Shows how performance degrades when 1/2 of all keys are missed. | |
* | |
* It puts 1000000/STEP records in replicated caches attempts then reads 1000000 keys. | |
* <p> | |
* change NODE_COUNT from 1 to 2 and change STEP 1 to 2 | |
* | |
*/ | |
public class Main { | |
public static final String TEST = "test"; | |
public static final int ROWS = 1_000_000; | |
private static final int NODE_COUNT = 1; | |
public static final int STEP = 1; | |
public static void main(String[] args) throws InterruptedException { | |
try { | |
ExecutorService exe = Executors.newFixedThreadPool(NODE_COUNT); | |
TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); | |
for (int i = 0; i < NODE_COUNT; i++) { | |
String nodeName = "jvm-node-" + i; | |
exe.submit(() -> { | |
TcpDiscoverySpi discovery = new TcpDiscoverySpi(); | |
discovery.setIpFinder(ipFinder); | |
CacheConfiguration cache = new CacheConfiguration<>(); | |
cache.setName(TEST); | |
cache.setAtomicityMode(CacheAtomicityMode.ATOMIC); | |
cache.setCacheMode(CacheMode.REPLICATED); | |
cache.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_ASYNC); | |
IgniteConfiguration cfg = new IgniteConfiguration(); | |
cfg.setGridName(nodeName); | |
cfg.setDiscoverySpi(discovery); | |
cfg.setCacheConfiguration(cache); | |
Ignite ignite = Ignition.start(cfg); | |
try { | |
work(ignite); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
return null; | |
}); | |
} | |
exe.shutdown(); | |
exe.awaitTermination(10, TimeUnit.MINUTES); | |
System.out.printf("%n"); | |
} finally { | |
Ignition.stopAll(true); | |
} | |
} | |
private static void work(Ignite ignite) throws Exception { | |
IgniteCountDownLatch latch = ignite.countDownLatch("latch", 1, false, true); | |
IgniteCache<Integer, String> test = ignite.cache(TEST); | |
if (ignite.atomicLong("worker", 1, true).compareAndSet(1, 0)) { | |
System.out.printf("put\t%.3f\t", | |
elapsed(() -> transaction(ignite, () -> { | |
for (int i = 0; i < ROWS; i += STEP) { | |
test.put(i, String.valueOf(i)); | |
} | |
})) / 1_000.0 / ROWS); | |
Thread.sleep(1000); | |
latch.countDown(); | |
} else { | |
latch.await(); | |
} | |
System.out.printf("get\t%.3f\t", | |
elapsed(() -> transaction(ignite, () -> { | |
for (int i = 0; i < ROWS; i++) { | |
test.get(i); | |
} | |
})) / 1_000.0 / ROWS); | |
} | |
static void transaction(Ignite ignite, Runnable runnable) { | |
try (Transaction tx = ignite.transactions().txStart()) { | |
runnable.run(); | |
tx.commit(); | |
} | |
} | |
@SuppressWarnings({"finally", "ReturnInsideFinallyBlock"}) | |
static long elapsed(Runnable runnable) { | |
long s = System.nanoTime(); | |
try { | |
runnable.run(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} finally { | |
return System.nanoTime() - s; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment