2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
6 package TransactionalIO.benchmarks;
8 import TransactionalIO.core.Defaults;
9 import TransactionalIO.core.TransactionalFile;
10 import java.io.FileNotFoundException;
11 import java.io.IOException;
12 import java.io.RandomAccessFile;
13 import java.util.Collections;
14 import java.util.HashMap;
16 import java.util.Random;
17 import java.util.Vector;
18 import java.util.concurrent.locks.Lock;
19 import java.util.concurrent.locks.ReentrantLock;
20 import java.util.concurrent.locks.ReentrantReadWriteLock;
21 import java.util.logging.Level;
22 import java.util.logging.Logger;
29 public class benchmark {
30 static public HashMap TransactionalFiles = new HashMap();
31 static public HashMap hotwords = new HashMap();
32 static public HashMap names = new HashMap();
33 static public HashMap reversenames = new HashMap();
35 public static String msg = new String();
36 public static ReentrantLock lock = new ReentrantLock();
37 public static Vector transacctions = new Vector();
38 public static ReentrantLock filelock = new ReentrantLock();
43 public static String[] stocks;
50 private static void preparenamelist(){
52 byte[] data = new byte[1];
53 char[] name = new char[20];
54 RandomAccessFile file = new RandomAccessFile("/scratch/TransactionalIO/FinancialTransactionBenchmarkFiles/namelist.text", "rw");
55 RandomAccessFile file2 = new RandomAccessFile("/scratch/TransactionalIO/FinancialTransactionBenchmarkFiles/financialtransaction.text", "rw");
56 RandomAccessFile file3 = new RandomAccessFile("/scratch/TransactionalIO/FinancialTransactionBenchmarkFiles/accountbalance.text", "rw");
59 stocks = new String[20];
62 stocks[2] = "Microsoft";
63 stocks[3] = "Broadcom";
65 stocks[5] = "Qualcom";
72 stocks[12] = "Motorolla";
73 stocks[13] = "Samsung";
74 stocks[14] = "TMobile";
80 /* boolean hh = false;
81 boolean found = false;
85 System.out.println(file4.getFilePointer()-1);
86 file4.seek(file4.getFilePointer()-1);
88 file4.write(stocks[(int)(Math.random()*10)].getBytes());
95 while (data[0] != '\n') {
97 tt = file4.read(data);
106 boolean flag = false;
107 boolean done = false;
114 // System.out.println("At " + wordcounter + " inserted " +String.copyValueOf(name, 0, counter));
115 m3.put(Integer.valueOf(wordcounter), String.copyValueOf(name, 0, counter));
116 m4.put(String.copyValueOf(name, 0, counter), Integer.valueOf(wordcounter));
122 while (data[0] != '\n') {
124 res = file.read(data);
129 //System.out.println((char)data[0]);
130 if (!(Character.isLetter((char) data[0]))) {
133 name[counter] = (char)data[0];
141 while (counter <30000) {
142 int index1 = (int)(Math.random()*50);
143 int stocktrade = (int)(Math.random()*100);
144 while (stocktrade == 0)
145 stocktrade = (int)(Math.random()*100);
146 int index2 = (int)(Math.random()*50);
147 while (index2 == index1)
148 index2 = (int)(Math.random()*50);
149 //System.out.println(index);
150 String towrite = (String)m3.get(Integer.valueOf(index1)) + " ";
151 towrite += String.valueOf(stocktrade) + " ";
152 towrite += (String)m3.get(Integer.valueOf(index2)) + " ";
153 towrite += stocks[(int)(Math.random()*20)] + "\n";
155 file2.write(towrite.getBytes());
156 // System.out.println(towrite);
159 // for (int i=0; i<50*Defaults.FILEFRAGMENTSIZE; i++)
163 for (int i=0; i<50; i++){
164 String towrite = (String)m3.get(Integer.valueOf(i)) +"\n";
165 for (int j=0; j<stocks.length; j++)
166 towrite += stocks[j] + " Stock Balance: " + ((int)(Math.random()*100+100)) + " \n";
167 System.out.println(towrite);
168 file3.write(towrite.getBytes());
169 while (file3.getFilePointer()<(i+1)*Defaults.FILEFRAGMENTSIZE)
170 file3.write(new String(" ").getBytes());
174 /* for (int i=0; i<10; i++)
175 System.out.println((char)f[i]);*/
179 } catch (IOException ex) {
180 Logger.getLogger(benchmark.class.getName()).log(Level.SEVERE, null, ex);
186 public static void init(){
189 m3 = Collections.synchronizedMap(names);
190 m4 = Collections.synchronizedMap(reversenames);
197 m = Collections.synchronizedMap(TransactionalFiles);
198 TransactionalFile tr = new TransactionalFile("/scratch/TransactionalIO/PureIOBenchmarkFiles/randomwords.text", "rw");
199 m.put(String.valueOf(count), tr);
201 TransactionalFile tr2 = new TransactionalFile("/home/navid/input.text", "rw");
202 m.put(String.valueOf(count), tr2);
204 TransactionalFile tr3 = new TransactionalFile("/scratch/TransactionalIO/WordCunterBenchmarkFiles/iliad.text", "rw");
205 m.put(String.valueOf(count), tr3);
207 TransactionalFile tr4 = new TransactionalFile("/scratch/TransactionalIO/WordCunterBenchmarkFiles/counter_benchmark_output.text", "rw");
208 m.put(String.valueOf(count), tr4);
211 TransactionalFile tr5 = new TransactionalFile("/scratch/TransactionalIO/FinancialTransactionBenchmarkFiles/financialtransaction.text", "rw");
212 m.put(String.valueOf(count), tr5);
216 TransactionalFile tr6 = new TransactionalFile("/scratch/TransactionalIO/FinancialTransactionBenchmarkFiles/accountbalance.text", "rw");
217 m.put(String.valueOf(count), tr6);
221 TransactionalFile tr7 = new TransactionalFile("/scratch/TransactionalIO/FinancialTransactionBenchmarkFiles/financialtransactionlog.text", "rw");
222 m.put(String.valueOf(count), tr7);
226 RandomAccessFile tr8 = new RandomAccessFile("/scratch/TransactionalIO/FinancialTransactionBenchmarkFiles/accountbalance.text", "rw");
227 m.put(String.valueOf(count), tr8);
231 RandomAccessFile tr9 = new RandomAccessFile("/scratch/TransactionalIO/FinancialTransactionBenchmarkFiles/financialtransactionlog.text", "rw");
232 m.put(String.valueOf(count), tr9);
237 for (int i = 0; i < 26; i++) {
239 m.put(String.valueOf((char) (index+i)), new TransactionalFile("/scratch/TransactionalIO/PureIOBenchmarkFiles/"
240 + String.valueOf((char) (index+i)) + ".text", "rw"));
242 /* m.put(String.valueOf((char) (index+i)), new RandomAccessFile("/scratch/TransactionalIO/PureIOBenchmarkFiles/"
243 + String.valueOf((char) (index+i)) + ".text", "rw"));
247 m2 = Collections.synchronizedMap(hotwords);
248 m2.put(Integer.valueOf(count), "Polydamas");
250 m2.put(Integer.valueOf(count), "Cebriones");
252 m2.put(Integer.valueOf(count), "Eurybates");
254 m2.put(Integer.valueOf(count), "Menoetius");
256 m2.put(Integer.valueOf(count), "countless");
258 m2.put(Integer.valueOf(count), "huntsman");
260 m2.put(Integer.valueOf(count), "presence");
262 m2.put(Integer.valueOf(count), "pursuit");
264 m2.put(Integer.valueOf(count), "masterfully");
266 m2.put(Integer.valueOf(count), "unweariable");
267 } catch (FileNotFoundException ex) {
268 Logger.getLogger(benchmark.class.getName()).log(Level.SEVERE, null, ex);