Created
March 18, 2012 09:30
-
-
Save fehmicansaglam/2070166 to your computer and use it in GitHub Desktop.
Memcached, Redis ve Hazelcast performans karşılaştırması
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
package concurrency; | |
import com.hazelcast.client.ClientConfig; | |
import com.hazelcast.client.HazelcastClient; | |
import com.hazelcast.core.HazelcastInstance; | |
import java.util.concurrent.CountDownLatch; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
import org.junit.Test; | |
import workers.HazelcastWorker; | |
public class HazelcastWithJavaClientTest { | |
public HazelcastWithJavaClientTest() { | |
} | |
private void test(final int threadCount) throws Exception { | |
final int opCount = 131072 / threadCount; | |
final CountDownLatch startGate = new CountDownLatch(1); | |
final CountDownLatch endGate = new CountDownLatch(threadCount); | |
final ExecutorService executor = Executors.newFixedThreadPool(threadCount + 1); | |
ClientConfig clientConfig = new ClientConfig(); | |
clientConfig.getGroupConfig().setName("dev").setPassword("dev-pass"); | |
clientConfig.addAddress("10.35.1.43"); | |
final HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig); | |
for (int i = 0; i < threadCount; ++i) { | |
executor.execute(new HazelcastWorker(client, opCount, startGate, endGate, i)); | |
} | |
long start = System.nanoTime(); | |
startGate.countDown(); | |
endGate.await(); | |
long end = System.nanoTime(); | |
System.out.println("HazelcastWithJavaClient: Thread count: " + threadCount + " Time: " + (end - start) / 1000 + "ms"); | |
} | |
@Test | |
public void testRun() throws Exception { | |
System.out.println("HazelcastWithJavaClient test started"); | |
test(1); | |
System.out.println("----------------------"); | |
test(2); | |
System.out.println("----------------------"); | |
test(4); | |
System.out.println("----------------------"); | |
test(8); | |
System.out.println("----------------------"); | |
test(16); | |
System.out.println("----------------------"); | |
test(32); | |
System.out.println("----------------------"); | |
test(64); | |
System.out.println("----------------------"); | |
test(128); | |
System.out.println("----------------------"); | |
} | |
} |
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
package concurrency; | |
import java.net.InetSocketAddress; | |
import java.util.concurrent.CountDownLatch; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
import net.spy.memcached.MemcachedClient; | |
import org.junit.Test; | |
import workers.MemcachedWorker; | |
public class HazelcastWithMemcachedClientTest { | |
public HazelcastWithMemcachedClientTest() { | |
} | |
private void test(final int threadCount) throws Exception { | |
final int opCount = 131072 / threadCount; | |
final CountDownLatch startGate = new CountDownLatch(1); | |
final CountDownLatch endGate = new CountDownLatch(threadCount); | |
final ExecutorService executor = Executors.newFixedThreadPool(threadCount + 1); | |
MemcachedClient mc = new MemcachedClient( | |
new InetSocketAddress("10.35.1.43", 5701)); | |
for (int i = 0; i < threadCount; ++i) { | |
executor.execute(new MemcachedWorker(mc, opCount, startGate, endGate, i)); | |
} | |
long start = System.nanoTime(); | |
startGate.countDown(); | |
endGate.await(); | |
long end = System.nanoTime(); | |
System.out.println("HazelcastWithMemcachedClient: Thread count: " + threadCount + " Time: " + (end - start) / 1000 + "ms"); | |
} | |
@Test | |
public void testRun() throws Exception { | |
System.out.println("HazelcastWithMemcachedClient test started"); | |
test(1); | |
System.out.println("----------------------"); | |
test(2); | |
System.out.println("----------------------"); | |
test(4); | |
System.out.println("----------------------"); | |
test(8); | |
System.out.println("----------------------"); | |
test(16); | |
System.out.println("----------------------"); | |
test(32); | |
System.out.println("----------------------"); | |
test(64); | |
System.out.println("----------------------"); | |
test(128); | |
System.out.println("----------------------"); | |
} | |
} |
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
package workers; | |
import com.hazelcast.core.HazelcastInstance; | |
import java.util.Map; | |
import java.util.concurrent.CountDownLatch; | |
public final class HazelcastWorker extends LatchWorker { | |
private final HazelcastInstance client; | |
private final int opCount; | |
public HazelcastWorker(HazelcastInstance client, int opCount, CountDownLatch startGate, CountDownLatch endGate, int id) { | |
super(startGate, endGate, id); | |
this.client = client; | |
this.opCount = opCount; | |
} | |
@Override | |
void doJob() { | |
for (int i = 0; i < opCount; ++i) { | |
Map<String, String> map = client.getMap("foo"); | |
map.put("foo", "1234567890123456"); | |
map = client.getMap("foo"); | |
String value = map.get("foo"); | |
} | |
} | |
} |
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
package workers; | |
import java.util.concurrent.CountDownLatch; | |
public abstract class LatchWorker implements Runnable { | |
private final int id; | |
private final CountDownLatch startGate; | |
private final CountDownLatch endGate; | |
public LatchWorker(CountDownLatch startGate, CountDownLatch endGate, int id) { | |
this.id = id; | |
this.startGate = startGate; | |
this.endGate = endGate; | |
} | |
@Override | |
public void run() { | |
System.out.println("Thread[" + this.id + "]: waiting for latch"); | |
try { | |
startGate.await(); | |
System.out.println("Thread[" + this.id + "]: started"); | |
doJob(); | |
System.out.println("Thread[" + this.id + "] completed"); | |
endGate.countDown(); | |
} catch (InterruptedException ex) { | |
} | |
} | |
abstract void doJob(); | |
} |
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
package concurrency; | |
import java.net.InetSocketAddress; | |
import java.util.concurrent.CountDownLatch; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
import net.spy.memcached.MemcachedClient; | |
import org.junit.Test; | |
import workers.MemcachedWorker; | |
public class MemcachedTest { | |
public MemcachedTest() { | |
} | |
private void test(final int threadCount) throws Exception { | |
final int opCount = 131072 / threadCount; | |
final CountDownLatch startGate = new CountDownLatch(1); | |
final CountDownLatch endGate = new CountDownLatch(threadCount); | |
final ExecutorService executor = Executors.newFixedThreadPool(threadCount + 1); | |
MemcachedClient mc = new MemcachedClient( | |
new InetSocketAddress("localhost", 11211)); | |
for (int i = 0; i < threadCount; ++i) { | |
executor.execute(new MemcachedWorker(mc, opCount, startGate, endGate, i)); | |
} | |
long start = System.nanoTime(); | |
startGate.countDown(); | |
endGate.await(); | |
long end = System.nanoTime(); | |
System.out.println("Memcached: Thread count: " + threadCount + " Time: " + (end - start) / 1000 + "ms"); | |
} | |
@Test | |
public void testRun() throws Exception { | |
System.out.println("Memcached test started"); | |
test(1); | |
System.out.println("----------------------"); | |
test(2); | |
System.out.println("----------------------"); | |
test(4); | |
System.out.println("----------------------"); | |
test(8); | |
System.out.println("----------------------"); | |
test(16); | |
System.out.println("----------------------"); | |
test(32); | |
System.out.println("----------------------"); | |
test(64); | |
System.out.println("----------------------"); | |
test(128); | |
System.out.println("----------------------"); | |
} | |
} |
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
package workers; | |
import java.util.concurrent.CountDownLatch; | |
import net.spy.memcached.MemcachedClient; | |
public final class MemcachedWorker extends LatchWorker { | |
private final MemcachedClient mc; | |
private final int opCount; | |
public MemcachedWorker(MemcachedClient mc, int opCount, CountDownLatch startGate, CountDownLatch endGate, int id) { | |
super(startGate, endGate, id); | |
this.mc = mc; | |
this.opCount = opCount; | |
} | |
@Override | |
void doJob() { | |
for (int i = 0; i < opCount; ++i) { | |
mc.set("foo", 3600, "1234567890123456"); | |
Object value = mc.get("foo"); | |
} | |
} | |
} |
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
package concurrency; | |
import java.util.concurrent.CountDownLatch; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
import org.junit.Test; | |
import redis.clients.jedis.JedisPool; | |
import workers.RedisWorker; | |
public class RedisTest { | |
public RedisTest() { | |
} | |
private void test(final int threadCount) throws InterruptedException { | |
final int opCount = 131072 / threadCount; | |
final CountDownLatch startGate = new CountDownLatch(1); | |
final CountDownLatch endGate = new CountDownLatch(threadCount); | |
final ExecutorService executor = Executors.newFixedThreadPool(threadCount + 1); | |
final JedisPool jedisPool = new JedisPool("localhost", 6379); | |
for (int i = 0; i < threadCount; ++i) { | |
executor.execute(new RedisWorker(jedisPool, opCount, startGate, endGate, i)); | |
} | |
long start = System.nanoTime(); | |
startGate.countDown(); | |
endGate.await(); | |
long end = System.nanoTime(); | |
System.out.println("Redis: Thread count: " + threadCount + " Time: " + (end - start) / 1000 + "ms"); | |
} | |
@Test | |
public void testRun() throws InterruptedException { | |
System.out.println("Redis test started"); | |
test(1); | |
System.out.println("----------------------"); | |
test(2); | |
System.out.println("----------------------"); | |
test(4); | |
System.out.println("----------------------"); | |
test(8); | |
System.out.println("----------------------"); | |
test(16); | |
System.out.println("----------------------"); | |
test(32); | |
System.out.println("----------------------"); | |
test(64); | |
System.out.println("----------------------"); | |
test(128); | |
System.out.println("----------------------"); | |
} | |
} |
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
package workers; | |
import java.util.concurrent.CountDownLatch; | |
import redis.clients.jedis.Jedis; | |
import redis.clients.jedis.JedisPool; | |
public final class RedisWorker extends LatchWorker { | |
private final JedisPool pool; | |
private final int opCount; | |
public RedisWorker(JedisPool pool, int opCount, CountDownLatch startGate, CountDownLatch endGate, int id) { | |
super(startGate, endGate, id); | |
this.pool = pool; | |
this.opCount = opCount; | |
} | |
@Override | |
void doJob() { | |
for (int i = 0; i < opCount; ++i) { | |
Jedis jedis = pool.getResource(); | |
jedis.set("foo", "1234567890123456"); | |
String value = jedis.get("foo"); | |
pool.returnResource(jedis); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment