new benchmark for lookup service
[IRC.git] / Robust / src / Benchmarks / Distributed / LookUpService / LookUpService.java
1 public class LookUpService extends Thread {
2   DistributedHashMap mydhmap;
3   int threadid;
4   int numthreads;
5
6   public LookUpService(DistributedHashMap dmap, int threadid, int numthreads) {
7     mydhmap = dmap;
8     this.threadid = threadid;
9     this.numthreads = numthreads;
10   }
11
12   public void run() {
13     //Add to the hash map
14     int nobjs = 10;
15     // Do read/writes
16     int numtrans = 1000;
17     // read probability % between 0-99
18     int rdprob = 90;
19     atomic {
20       for(int i = 0; i < nobjs; i++) {
21         Integer key = global new Integer(threadid*nobjs+i);
22         Integer val = global new Integer(i);
23         Object o1 = key;
24         Object o2 = val;
25         mydhmap.put(o1, o2);
26       }
27     }
28     for (int i = 0; i < numtrans; i++) {
29       Random rand = new Random(i);
30       int rdwr = rand.nextInt(100);
31       int rwkey = rand.nextInt(nobjs*numthreads);
32       Integer k = new Integer(rwkey);
33       if (rdwr < rdprob) {
34         Integer tmp = mydhmap.get(k);
35       } else {
36         Integer val = global new Integer(i);
37         mydhmap.put(k, val);
38       }
39     }
40   }
41
42   public static void main(String[] args) {
43     int nthreads;
44     if(args.length>0)
45       nthreads = Integer.parseInt(args[0]);
46
47     int[] mid = new int[8];
48     mid[0] = (128<<24)|(195<<16)|(175<<8)|79;//dc-1
49     mid[1] = (128<<24)|(195<<16)|(136<<8)|163;//dc-2
50     mid[2] = (128<<24)|(195<<16)|(136<<8)|164;//dc-3
51     mid[3] = (128<<24)|(195<<16)|(136<<8)|165;//dc-4
52     mid[4] = (128<<24)|(195<<16)|(136<<8)|166;//dc-5
53     mid[5] = (128<<24)|(195<<16)|(136<<8)|167;//dc-6
54     mid[6] = (128<<24)|(195<<16)|(136<<8)|168;//dc-7
55     mid[7] = (128<<24)|(195<<16)|(136<<8)|169;//dc-8
56
57     LookUpService[] lus;
58     DistributedHashMap dhmap;
59     //DistributedHashEntry dhe;
60
61     
62     atomic {
63       dhmap = global new DistributedHashMap(100, 100, 0.75f);
64       lus = global new LookUpService[nthreads];
65       for(int i = 0; i<nthreads; i++) {
66         lus[i] = global new LookUpService(dhmap, i, nthreads);
67       }
68     }
69
70     LookUpService tmp;
71     /* Start threads */
72     for(int i = 0; i<nthreads; i++) {
73       atomic {
74         tmp = lus[i];
75       }
76       tmp.start(mid[i]);
77     }
78
79     /* Join threads */
80     for(int i = 0; i<nthreads; i++) {
81       atomic {
82         tmp = lus[i];
83       }
84       tmp.join();
85     }
86
87     System.printString("Finished\n");
88   }
89 }