Examples of DCounter


Examples of edu.vt.rt.datastructures.util.DCounter

    NODE_COUNT = Network.getInstance().nodesCount();
    Random generator = new Random(NODE_ID);
    boolean toggle = false;
    int containsCalls = 0, addCalls = 0, removeCalls = 0;
    SET = (DistributedSet<Integer>) Class.forName("edu.vt.rt.datastructures.lang." + SET_CLASS).getDeclaredConstructor(String.class).newInstance("LinkedList");
    DCounter callCount = new DCounter("callCount");
    DSynchronizer start = new DSynchronizer("startSync"), finished = new DSynchronizer("finishedSync");
    DSynchronizer[]  nodes = new DSynchronizer[NODE_COUNT-1];
    for (int i = 0; i < NODE_COUNT-1; i++) {
      nodes[i] = new DSynchronizer("node " + Integer.toString(i+1) + " finished sync");
    }

    //Start HyFlow
    HyFlow.start(NODE_ID);

    //Populate system
    if (NODE_ID == 0) {
      start.create();
      SET.create();
      callCount.create();
      finished.create();
      //load up the list with some initial values
      Random gen = new Random(1988);
      for (int i = 0; i < NUM_ELEMS; i++) {
        SET.add(gen.nextInt(NUM_SPAN));
      }
      start.setReady();
    }
    else {
      //Make other nodes wait for master to populate data structure
      nodes[NODE_ID-1].create();
      while (!start.isReady()) {}
    }

    //Run Experiment
    long startTime = System.currentTimeMillis(), endTime = startTime;
    while (endTime - startTime < RUN_TIME) {
      int functionType = generator.nextInt(100);
      int value = generator.nextInt(NUM_SPAN);
      if (functionType >= EXPERIMENT) {  //Read function       
        SET.contains(value);
        containsCalls++;
      }
      else //Write function
        toggle = !toggle;  //Keep adds and removes even
        if (toggle) {
          SET.add(value);
          addCalls++;
        }
        else {
          SET.remove(value);
          removeCalls++;
        }
      }
      endTime = System.currentTimeMillis();
    }

    long totalTime = TimeUnit.SECONDS.convert(endTime-startTime, TimeUnit.MILLISECONDS);
    long callsPerSecond = (containsCalls + addCalls + removeCalls) / totalTime;

    if (NODE_ID == 0) {
      //Wait for all other nodes to report results
      int i = 0;
      while (i != NODE_COUNT-1) {
        if (nodes[i].isReady()) {
          i++;
        }
      }
      //Print out total results
      callsPerSecond += callCount.getCount();
      finished.setReady();
      System.out.println(EXPERIMENT + "\t" + NODE_COUNT + "\t" + NUM_ELEMS + "\t" + callsPerSecond);
      //Give other nodes time to determine tests are finished
      Thread.sleep(2000);
    }
    else {
      callCount.add(callsPerSecond);
      nodes[NODE_ID-1].setReady();
      while (!finished.isReady()) {}
    }
    System.exit(0);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.