1 public class LookUpService extends Thread {
2 DistributedHashMap mydhmap;
4 * The thread id involved
8 * The total number of threads
10 private int numthreads;
13 * The total number of transactions
18 * The total number of objects created
23 * The probability of initiating a look up
24 * the read probability % between 0-99
28 public LookUpService() {
31 public LookUpService(DistributedHashMap dmap, int threadid, int numthreads, int nobjs, int numtrans, int rdprob) {
33 this.threadid = threadid;
34 this.numthreads = numthreads;
36 this.numtrans = numtrans;
42 barr = new Barrier("128.195.136.162");
46 for(int i = 0; i < nobjs; i++) {
47 Integer key = global new Integer(threadid*nobjs+i);
48 Integer val = global new Integer(i);
55 Barrier.enterBarrier(barr);
57 for (int i = 0; i < ntrans; i++) {
59 Random rand = new Random(i);
60 int rdwr = rand.nextInt(100);
61 int rwkey = rand.nextInt(nobjs*numthreads);
62 Integer key = global new Integer(rwkey);
65 Object o3 = mydhmap.get(o1); //Read
67 Integer val = global new Integer(i);
69 mydhmap.put(o1, o2); //Modify
75 public static void main(String[] args) {
76 LookUpService ls = new LookUpService();
77 LookUpService.parseCmdLine(args,ls);
80 int nthreads = ls.numthreads;
81 int[] mid = new int[8];
82 mid[0] = (128<<24)|(195<<16)|(136<<8)|162;//dc-1
83 mid[1] = (128<<24)|(195<<16)|(136<<8)|163;//dc-2
84 mid[2] = (128<<24)|(195<<16)|(136<<8)|164;//dc-3
85 mid[3] = (128<<24)|(195<<16)|(136<<8)|165;//dc-4
86 mid[4] = (128<<24)|(195<<16)|(136<<8)|166;//dc-5
87 mid[5] = (128<<24)|(195<<16)|(136<<8)|167;//dc-6
88 mid[6] = (128<<24)|(195<<16)|(136<<8)|168;//dc-7
89 mid[7] = (128<<24)|(195<<16)|(136<<8)|169;//dc-8
92 DistributedHashMap dhmap;
94 mybarr = global new BarrierServer(nthreads);
99 dhmap = global new DistributedHashMap(100, 100, 0.75f);
100 lus = global new LookUpService[nthreads];
101 for(int i = 0; i<nthreads; i++) {
102 lus[i] = global new LookUpService(dhmap, i, ls.numthreads, ls.nobjs, ls.numtrans, ls.rdprob);
106 boolean waitfordone=true;
108 atomic { //Master aborts are from here
116 for(int i = 0; i<nthreads; i++) {
124 for(int i = 0; i<nthreads; i++) {
131 System.printString("Finished\n");
135 * Parse the command line options.
137 public static void parseCmdLine(String args[], LookUpService lus) {
140 while(i < args.length && args[i].startsWith("-")) {
143 if(arg.equals("-N")) {
144 if(i < args.length) {
145 lus.numthreads = new Integer(args[i++]).intValue();
147 } else if(arg.equals("-nEntry")) {
148 if(i < args.length) {
149 lus.nobjs = new Integer(args[i++]).intValue();
151 } else if (arg.equals("-nTrans")) {
152 if(i < args.length) {
153 lus.numtrans = new Integer(args[i++]).intValue();
155 } else if(arg.equals("-probRead")) {
156 if(i < args.length) {
157 lus.rdprob = new Integer(args[i++]).intValue();
159 } else if(arg.equals("-h")) {
164 if(lus.nobjs == 0 || lus.numtrans == 0)
169 * The usage routine which describes the program options.
171 public void usage() {
172 System.printString("usage: ./LookUpServiceN.bin master -N <threads> -nEntry <objects in hashmap> -nTrans <number of transactions> -probRead <read probability> \n");
173 System.printString(" -N the number of threads\n");
174 System.printString(" -nEntry the number of objects to be inserted into distributed hashmap\n");
175 System.printString(" -nTrans the number of transactions to run\n");
176 System.printString(" -probRead the probability of read given a transaction\n");
177 System.printString(" -h help with usage\n");