Dear,
My command test:
In my test, I start memcached with memcached -m 1024 =>1G to prevent miss cache
and infinispan with param:-Xmx1G
Monitor java memory used:
I use ubuntu and I see the memory column from "System Monitor(in Ubuntu) for Infinispan.
In my test code, I only put once time for one key ( that mean no version for data)
You can see my code test by put to memcached and infinispan with the same code(only change port):
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import net.spy.memcached.
MemcachedClient;
/**
* /usr/bin/memcached -m 1024 -u nobody -p 11211 -l 127.0.0.1* ./startServer.sh -r memcached -p 4567* @author root
*/
public class ServerDemo {
private static final String HOST = "localhost";
// private static final int PORT = 4567;//inf
private static final int PORT = 11211;//mem
private static final int TOTAL_PUT = 500000;
private static final int DATA_LENGTH = 1000;
public static void main(String[] args) throws Exception {
Thread t = new Thread() {
@Override
public void run() {
try {
long beginTime = System.currentTimeMillis();
put(TOTAL_PUT, DATA_LENGTH);
long endTime = System.currentTimeMillis() - beginTime;
System.out.println("cost = " + endTime);
System.gc();
} catch (Exception e) {
}
}
};
t.start();
}
private static String getStringByLength(int size) {
String s = "";
for (int i = 0; i < size; i++) {
s += "1";
}
return s;
}
private static CommentItem getCommentInstance(String content) {
int time = new Long(System.currentTimeMillis()).intValue();
CommentItem commentItem = new CommentItem(new Long(123), 12345, 456, time, content.getBytes(), (byte) 1);
return commentItem;
}
private static byte[] comment2Bytes(CommentItem commentItem) throws Exception {
DataOutputBuffer dos = new DataOutputBuffer();
CommentItemSerializer.getInstance().serialize(commentItem, dos);
System.out.println("dos.getData()=" + dos.getData().length);
return dos.getData();
}
private static void putComment2Cached(int keyPrefix, byte[] bytes, MemcachedClient mcc) throws Exception {
mcc.set("node_" + keyPrefix, 3600, bytes);
byte[] result = (byte[]) mcc.get("node_" + keyPrefix);
DataInputStream stream = new DataInputStream(new ByteArrayInputStream(
result));
CommentItem getBackItem = CommentItemSerializer.getInstance().deserialize(stream);
// if (!commentItem.equals(getBackItem)) {
// System.out.println("fail i= node_" + keyPrefix);
// }
}
private static void put(int loop, int size) throws IOException, Exception {
MemcachedClient mcc = new MemcachedClient(new InetSocketAddress(HOST, PORT));
String testData = getStringByLength(size);
CommentItem commentItem = getCommentInstance(testData);
byte[] bytes = comment2Bytes(commentItem);
for (int i = 0; i < loop; i++) {
putComment2Cached(i, bytes, mcc);
}
}
}
MemcachedClient;
/**
* /usr/bin/memcached -m 1024 -u nobody -p 11211 -l 127.0.0.1* ./startServer.sh -r memcached -p 4567* @author root
*/
public class ServerDemo {
private static final String HOST = "localhost";
// private static final int PORT = 4567;//inf
private static final int PORT = 11211;//mem
private static final int TOTAL_PUT = 500000;
private static final int DATA_LENGTH = 1000;
public static void main(String[] args) throws Exception {
Thread t = new Thread() {
@Override
public void run() {
try {
long beginTime = System.currentTimeMillis();
put(TOTAL_PUT, DATA_LENGTH);
long endTime = System.currentTimeMillis() - beginTime;
System.out.println("cost = " + endTime);
System.gc();
} catch (Exception e) {
}
}
};
t.start();
}
private static String getStringByLength(int size) {
String s = "";
for (int i = 0; i < size; i++) {
s += "1";
}
return s;
}
private static CommentItem getCommentInstance(String content) {
int time = new Long(System.currentTimeMillis()).intValue();
CommentItem commentItem = new CommentItem(new Long(123), 12345, 456, time, content.getBytes(), (byte) 1);
return commentItem;
}
private static byte[] comment2Bytes(CommentItem commentItem) throws Exception {
DataOutputBuffer dos = new DataOutputBuffer();
CommentItemSerializer.getInstance().serialize(commentItem, dos);
System.out.println("dos.getData()=" + dos.getData().length);
return dos.getData();
}
private static void putComment2Cached(int keyPrefix, byte[] bytes, MemcachedClient mcc) throws Exception {
mcc.set("node_" + keyPrefix, 3600, bytes);
byte[] result = (byte[]) mcc.get("node_" + keyPrefix);
DataInputStream stream = new DataInputStream(new ByteArrayInputStream(
result));
CommentItem getBackItem = CommentItemSerializer.getInstance().deserialize(stream);
// if (!commentItem.equals(getBackItem)) {
// System.out.println("fail i= node_" + keyPrefix);
// }
}
private static void put(int loop, int size) throws IOException, Exception {
MemcachedClient mcc = new MemcachedClient(new InetSocketAddress(HOST, PORT));
String testData = getStringByLength(size);
CommentItem commentItem = getCommentInstance(testData);
byte[] bytes = comment2Bytes(commentItem);
for (int i = 0; i < loop; i++) {
putComment2Cached(i, bytes, mcc);
}
}
}
Hi Infinispan Devs,I used memcached all time. I am research Infinispan and make a compare with memcached.I have just make a memory test between memcached and infinispan to choose which one better(best memory saved).I run Infinispan from command line: ./startServer.sh -r memcached -p 4567 ( I am fresh download and run it with no custom any config file)and also memcached from command line: /usr/bin/memcached -m 1024 -u nobody -p 11211 -l 127.0.0.1with testcase 10000 key and every key has value is byte array with length= 1024Infinispan : => memory: 58MBMemcached: => memory: 14MBwith testcase 500000 key and every key has value is byte array with length= 1024Infinispan : => memory: 920MBMemcached: => memory: 565MBIn Infinispan, any config param familiar with memory cost? and how i can reduce this cost? why they have a big difference?thanks and best regards.