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
29 * The number of look up operations
33 public LookUpService() {
36 public LookUpService(DistributedHashMap dmap, int threadid, int numthreads, int nobjs, int numtrans, int rdprob, int nLookUp) {
38 this.threadid = threadid;
39 this.numthreads = numthreads;
41 this.numtrans = numtrans;
43 this.nLookUp = nLookUp;
53 Random rand = new Random(0);
55 for (int i = 0; i < ntrans; i++) {
57 for(int j = 0; j < nLookUp; j++) {
58 int rdwr = rand.nextInt(100);
59 int rwkey = rand.nextInt(nobjs);
60 Integer key = global new Integer(rwkey);
62 Object o3 = mydhmap.get(key); //Read
64 Integer val = global new Integer(j);
65 mydhmap.put(key, val); //Modify
72 public static void main(String[] args) {
73 LookUpService ls = new LookUpService();
74 LookUpService.parseCmdLine(args,ls);
76 int nthreads = ls.numthreads;
77 int[] mid = new int[8];
78 mid[0] = (128<<24)|(195<<16)|(136<<8)|162;//dc-1
79 mid[1] = (128<<24)|(195<<16)|(136<<8)|163;//dc-2
80 mid[2] = (128<<24)|(195<<16)|(136<<8)|164;//dc-3
81 mid[3] = (128<<24)|(195<<16)|(136<<8)|165;//dc-4
82 mid[4] = (128<<24)|(195<<16)|(136<<8)|166;//dc-5
83 mid[5] = (128<<24)|(195<<16)|(136<<8)|167;//dc-6
84 mid[6] = (128<<24)|(195<<16)|(136<<8)|168;//dc-7
85 mid[7] = (128<<24)|(195<<16)|(136<<8)|169;//dc-8
88 DistributedHashMap dhmap;
91 dhmap = global new DistributedHashMap(100, 100, 0.75f);
93 for(int i = 0; i < ls.nobjs; i++) {
94 Integer key = global new Integer(i);
95 Integer val = global new Integer(i*i);
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, ls.nLookUp);
108 for(int i = 0; i<nthreads; i++) {
116 for(int i = 0; i<nthreads; i++) {
123 System.printString("Finished\n");
127 * Parse the command line options.
129 public static void parseCmdLine(String args[], LookUpService lus) {
132 while(i < args.length && args[i].startsWith("-")) {
135 if(arg.equals("-N")) {
136 if(i < args.length) {
137 lus.numthreads = new Integer(args[i++]).intValue();
139 } else if(arg.equals("-nEntry")) {
140 if(i < args.length) {
141 lus.nobjs = new Integer(args[i++]).intValue();
143 } else if (arg.equals("-nTrans")) {
144 if(i < args.length) {
145 lus.numtrans = new Integer(args[i++]).intValue();
147 } else if(arg.equals("-probRead")) {
148 if(i < args.length) {
149 lus.rdprob = new Integer(args[i++]).intValue();
151 } else if(arg.equals("-nLookUp")) {
152 if(i < args.length) {
153 lus.nLookUp = new Integer(args[i++]).intValue();
155 } else if(arg.equals("-h")) {
160 if(lus.nobjs == 0 || lus.numtrans == 0)
165 * The usage routine which describes the program options.
167 public void usage() {
168 System.printString("usage: ./LookUpServiceN.bin master -N <threads> -nEntry <objects in hashmap> -nTrans <number of transactions> -probRead <read probability> -nLookUp <number of lookups>\n");
169 System.printString(" -N the number of threads\n");
170 System.printString(" -nEntry the number of objects to be inserted into distributed hashmap\n");
171 System.printString(" -nTrans the number of transactions to run\n");
172 System.printString(" -probRead the probability of read given a transaction\n");
173 System.printString(" -nLookUp the number of lookups per transaction\n");
174 System.printString(" -h help with usage\n");