Bu Blogda Ara

14 Aralık 2010 Salı

Performance of inserting data on Jboss Cache compared to ConcurrentHashMap.

You can use the below Beanshell script directly with the Jboss Cache 3.2.5 GUI Demo with embedded Beanshell. Just copy the below code piece to a file eg trial.bsh. And to run it from the embedded Beanshell of JBoss Cache GUI Demo do -> source("trial.bsh"). You should see some tps and performance related text output. The below beanshell script file is for ENTRY_COUNT = 120000; You can play with different number of entries. Also do not forget to play with Xms arguments not to get a stack overflow for large entries.


import org.jboss.cache.Fqn;
import java.util.Date;
import java.io.*;
import java.util.concurrent.ConcurrentHashMap;
import java.lang.instrument.*;



public class LocationDataObject implements Externalizable {

private static final long serialVersionUID = 3383966388917008053L;

private Double xCoord;
private Double yCoord;
private Date timeStamp;

public Double getXCoord(){
return xCoord;

}
public Double getYCoord(){
return yCoord;
}
public Date getTimeStamp(){
return timeStamp;
}

public void setXCoord(Double xCoord){
this.xCoord =xCoord ;

}
public void setYCoord(Double yCoord){
this.yCoord = yCoord;
}
public void setTimeStamp(Date timeStamp){
this.timeStamp = timeStamp;
}


public void readExternal(ObjectInput in)
throws IOException,ClassNotFoundException {

xCoord = in.readDouble();
yCoord = in.readDouble();
timeStamp = (Date)in.readObject();
}


public void writeExternal(ObjectOutput out)
throws IOException {
out.writeDouble(xCoord);
out.writeDouble(yCoord);
out.writeObject(timeStamp);
}

};



public class TestJbossCachevsHasmap{
private static final Long ENTRY_COUNT = 120000;

private static Instrumentation instrumentation;

public static void premain(String args, Instrumentation inst) {
instrumentation = inst;
}


public static void main(String [] args){

childFqn1 = Fqn.fromString("/Msisdn");

tm = cache.getTransactionManager();

tm.begin();
msisdnMap = root.addChild(childFqn1);
tm.commit();

locData = new LocationDataObject();

Long startTime = System.currentTimeMillis ();

for(Long fakeMsIsdn=0; fakeMsIsdn < ENTRY_COUNT; fakeMsIsdn++){

locData.setXCoord(10.00D);
locData.setYCoord(20.00D);
Date dateNow = new Date();
locData.setTimeStamp(dateNow);

tm.begin();
msisdnMap.put(fakeMsIsdn.toString(), locData);
tm.commit();

}

Long endTime = System.currentTimeMillis ();

Long executionTime = (endTime - startTime);

double tps = (ENTRY_COUNT*1000)/executionTime;

System.out.println("Duration of Jboss Cache for inserting " + ENTRY_COUNT + " entries in " + executionTime + " msec. Average tps is " +tps );

//System.out.println(ObjectSizeFetcher.getObjectSize(root));

concurrentMap = new ConcurrentHashMap ();

Long startTime2 = System.currentTimeMillis ();

for(Long fakeMsIsdn=0; fakeMsIsdn < ENTRY_COUNT; fakeMsIsdn++){


locData.setXCoord(10.00D);
locData.setYCoord(20.00D);
Date dateNow = new Date();
locData.setTimeStamp(dateNow);
concurrentMap.put(fakeMsIsdn.toString(), locData);

}

Long endTime2 = System.currentTimeMillis ();

Long executionTime2 = endTime2 - startTime2;

double tps2 = (ENTRY_COUNT*1000)/executionTime2;

System.out.println("Duration of ConcurrentHashMap for inserting " + ENTRY_COUNT + " entries in " + executionTime2 + " msec. Average tps is " +tps2 );


}

public static long getObjectSize(Object o) {
return instrumentation.getObjectSize(o);
}



}


TestJbossCachevsHasmap.main(null);

1 yorum:

  1. This of course not a comparision of Jboss Cache with ConcurrentHashmap, it is just to indicate what will be the performance compared to of that a pure HashMap implementation. And second the codes here are running on interpreted time and not compiled time, so there is another performance penalty there.

    YanıtlaSil