Package org.javasimon

Examples of org.javasimon.Stopwatch


  /* (non-Javadoc)
   * @see org.directmemory.supervisor.Supervisor#checkLimits(org.directmemory.CacheStore)
   */
  public void disposeOverflow(CacheStore cache) {
        Stopwatch stopWatch = SimonManager.getStopwatch("supervisor.asyncbatch.checkLimits");
    Split split = stopWatch.start();
   
    if (totalCalls++ >= batchSize) {
      totalCalls = 0;
      new ThreadUsingCache(cache) {
        public void run() {
View Full Code Here


  /* (non-Javadoc)
   * @see org.directmemory.supervisor.Supervisor#checkLimits(org.directmemory.CacheStore)
   */
  public void disposeOverflow(CacheStore cache) {
        Stopwatch stopWatch = SimonManager.getStopwatch("supervisor.batch.checkLimits");
    Split split = stopWatch.start();
   
    if (totalCalls++ >= batchSize) {
      totalCalls = 0;
      logger.debug("checking memory limits");
      cache.disposeHeapOverflow();
View Full Code Here

  /* (non-Javadoc)
   * @see org.directmemory.supervisor.Supervisor#checkLimits(org.directmemory.CacheStore)
   */
  public void disposeOverflow(CacheStore cache) {
        Stopwatch stopWatch = SimonManager.getStopwatch("supervisor.asimple.checkLimits");
    Split split = stopWatch.start();
   
    logger.debug("checking memory limits");
    cache.disposeHeapOverflow();
    cache.disposeOffHeapOverflow();
   
View Full Code Here

 
  /* (non-Javadoc)
   * @see org.directmemory.supervisor.Supervisor#checkLimits(org.directmemory.CacheStore)
   */
  public void disposeOverflow(CacheStore cache) {
    Stopwatch stopWatch = SimonManager.getStopwatch("supervisor.timed.checkLimits");
    Split split = stopWatch.start();
    long passed = new Date().getTime() - lastCheck.getTime();
    if (passed >= batchInterval) {
      lastCheck = new Date();
      new ThreadUsingCache(cache) {
        public void run() {
View Full Code Here

 
  @Override
  public void run() {
//    long started = Calendar.getInstance().getTimeInMillis();
   
        Stopwatch readerMon = SimonManager.getStopwatch("readerMon");
    Stopwatch deserializeMon = SimonManager.getStopwatch("deserializeMon");

//    System.out.println("reader thread started");
    int count = 0;
    for (CacheEntry entry : map.values()) {
      Split split = readerMon.start();
      //System.out.println(entry.key + " of size" + entry.size);
      byte[] dest = new byte[entry.size];
      synchronized (entry.buffer) {
        entry.buffer.position(entry.position);
        entry.buffer.get(dest);
      }
      split.stop();
      try {
        Split deserSplit = deserializeMon.start();
        @SuppressWarnings("unused")
        DummyPojo obj = Starter.deserialize(dest);
        deserSplit.stop();
//        System.out.println(obj.getName() + " count=" + count);
      } catch (IOException e) {
View Full Code Here

 
  public Map<String, CacheEntry> map;
 
  @Override
  public void run() {
        Stopwatch readerMon = SimonManager.getStopwatch("readerMon");
        Stopwatch writerMon = SimonManager.getStopwatch("writerMon");
    Stopwatch serializeMon = SimonManager.getStopwatch("serializeMon");
    Stopwatch deserializeMon = SimonManager.getStopwatch("deserializeMon");

    int count = 0;

    for (CacheEntry entry : map.values()) {
      Split split = readerMon.start();
      byte[] dest = new byte[entry.size];
      synchronized (entry.buffer) {
        entry.buffer.position(entry.position);
        entry.buffer.get(dest);
      }
      split.stop();
      DummyPojo obj = null;
      try {
        Split deserSplit = deserializeMon.start();
        obj = Starter.deserialize(dest);
        deserSplit.stop();
      } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
View Full Code Here

  public static void main(String[] args) throws IOException {
   
    int cacheSize = 5 * 1024 * 1024;
    int objectSize = 2 * 1024;
   
    Stopwatch setupMon = SimonManager.getStopwatch("setupMon");
    Stopwatch readerMon = SimonManager.getStopwatch("readerMon");
    Stopwatch writerMon = SimonManager.getStopwatch("writerMon");
    Stopwatch serializeMon = SimonManager.getStopwatch("serializeMon");
    Stopwatch deserializeMon = SimonManager.getStopwatch("deserializeMon");
   
//    long started = Calendar.getInstance().getTimeInMillis();
    System.out.println("started one thread test for a " + (cacheSize / 1024 / 1024) + "mb cache" + " objectSize=" + objectSize + " serialization buffer=" + serBufferSize);
   
    ByteBuffer buffer = ByteBuffer.allocateDirect(cacheSize);

    Map<String, CacheEntry> map = new ConcurrentHashMap<String, CacheEntry>();
   
    int memoryUsed = 0;
    int count = 0;
   
    while (memoryUsed <= cacheSize - objectSize) {
      CacheEntry entry = new CacheEntry();
      entry.key = "key"+(count++);
      DummyPojo obj = new DummyPojo(entry.key, objectSize);
     
      Split serSplit = serializeMon.start();
      byte[] src = serialize(obj);
      serSplit.stop();
      Split split = setupMon.start();
      entry.size = src.length;
      entry.buffer = buffer.duplicate();
      entry.position = memoryUsed;
      entry.buffer.position(memoryUsed);
     
     
      try {
        entry.buffer.put(src);
      } catch (BufferOverflowException e) {
        // TODO: handle exception
        e.printStackTrace();
      }
      map.put(entry.key, entry);
      memoryUsed+=entry.size;
      split.stop();
    }
       
        System.out.println("setupMon: " + setupMon);
    System.out.println("average append duration: " + (double)(setupMon.getTotal() / setupMon.getCounter())/1000000 + "ms");
    System.out.println("average serialize duration: " + (double)(serializeMon.getTotal() / serializeMon.getCounter())/1000000 + "ms");

    int numOfThreads = 10;
   
    System.out.println("multithread test - starting " + numOfThreads + " threads");
    Thread last = null;
   
    for (int i = 0; i < numOfThreads; i++) {
      Reader reader = new Reader();
      reader.map = map;
      reader.start();
      last = reader;
      Thread.yield();
      Writer writer = new Writer();
      writer.map = map;
      writer.start();
      Thread.yield();
      last = writer;
    }

    while (last.isAlive())
      Thread.yield();

    System.out.println(readerMon);
        System.out.println(writerMon);
    System.out.println(deserializeMon);
        System.out.println(serializeMon);
    System.out.println("average read duration: " + (double)(readerMon.getTotal() / readerMon.getCounter())/1000000 + "ms");
    System.out.println("average write duration: " + (double)(writerMon.getTotal() / writerMon.getCounter())/1000000 + "ms");
    System.out.println("average deserialize duration: " + (double)(deserializeMon.getTotal() / deserializeMon.getCounter())/1000000 + "ms");
    System.out.println("average serialize duration: " + (double)(serializeMon.getTotal() / serializeMon.getCounter())/1000000 + "ms");
  }
View Full Code Here

  /* (non-Javadoc)
   * @see org.directmemory.utils.Serializer#serialize(java.lang.Object, java.lang.Class)
   */
  @SuppressWarnings("unchecked")
  public byte[] serialize(Object obj, @SuppressWarnings("rawtypes") Class clazz) throws IOException {
        Stopwatch stopWatch = SimonManager.getStopwatch("serializer.PSSerialize");
    Split split = stopWatch.start();
    @SuppressWarnings("rawtypes")
    Schema schema = RuntimeSchema.getSchema(clazz);
    final LinkedBuffer buffer = LinkedBuffer.allocate(serBufferSize);
    byte[] protostuff = null;

View Full Code Here

  /* (non-Javadoc)
   * @see org.directmemory.utils.Serializer#deserialize(byte[], java.lang.Class)
   */
  @SuppressWarnings("unchecked")
  public Object deserialize(byte[] source, @SuppressWarnings("rawtypes") Class clazz) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        Stopwatch stopWatch = SimonManager.getStopwatch("serializer.PSDeserialize");
    Split split = stopWatch.start();
    final Object object = clazz.newInstance();
    @SuppressWarnings("rawtypes")
    final Schema schema = RuntimeSchema.getSchema(clazz);
    ProtostuffIOUtil.mergeFrom(source, object, schema);
    split.stop();
View Full Code Here

import org.javasimon.Stopwatch;

public class StandardSerializer implements Serializer {
 
  public byte[] serialize(Object obj, @SuppressWarnings("rawtypes") Class clazz) throws IOException {
        Stopwatch stopWatch = SimonManager.getStopwatch("serializer.javaSerialize");
    Split split = stopWatch.start();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(obj);
    oos.flush();
    oos.close();
View Full Code Here

TOP

Related Classes of org.javasimon.Stopwatch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.