jpayne@68
|
1 package fun;
|
jpayne@68
|
2
|
jpayne@68
|
3 import java.io.File;
|
jpayne@68
|
4 import java.io.IOException;
|
jpayne@68
|
5 import java.io.InputStream;
|
jpayne@68
|
6 import java.io.PrintStream;
|
jpayne@68
|
7 import java.util.ArrayList;
|
jpayne@68
|
8 import java.util.Arrays;
|
jpayne@68
|
9 import java.util.Locale;
|
jpayne@68
|
10 import java.util.Random;
|
jpayne@68
|
11
|
jpayne@68
|
12 import fileIO.ByteFile;
|
jpayne@68
|
13 import fileIO.ByteStreamWriter;
|
jpayne@68
|
14 import fileIO.FileFormat;
|
jpayne@68
|
15 import fileIO.QuickFile;
|
jpayne@68
|
16 import fileIO.ReadWrite;
|
jpayne@68
|
17 import fileIO.TextFile;
|
jpayne@68
|
18 import shared.Parse;
|
jpayne@68
|
19 import shared.Parser;
|
jpayne@68
|
20 import shared.PreParser;
|
jpayne@68
|
21 import shared.Shared;
|
jpayne@68
|
22 import shared.Timer;
|
jpayne@68
|
23 import shared.Tools;
|
jpayne@68
|
24 import stream.FastaReadInputStream;
|
jpayne@68
|
25 import structures.ByteBuilder;
|
jpayne@68
|
26
|
jpayne@68
|
27 /**
|
jpayne@68
|
28 * @author Brian Bushnell
|
jpayne@68
|
29 * @date December 6, 2017
|
jpayne@68
|
30 *
|
jpayne@68
|
31 */
|
jpayne@68
|
32 public class DiskBench {
|
jpayne@68
|
33
|
jpayne@68
|
34 public static void main(String[] args){
|
jpayne@68
|
35 //Start a timer immediately upon code entrance.
|
jpayne@68
|
36 Timer t=new Timer();
|
jpayne@68
|
37
|
jpayne@68
|
38 //Create an instance of this class
|
jpayne@68
|
39 DiskBench x=new DiskBench(args);
|
jpayne@68
|
40
|
jpayne@68
|
41 //Run the object
|
jpayne@68
|
42 x.process(t);
|
jpayne@68
|
43
|
jpayne@68
|
44 //Close the print stream if it was redirected
|
jpayne@68
|
45 Shared.closeStream(x.outstream);
|
jpayne@68
|
46 }
|
jpayne@68
|
47
|
jpayne@68
|
48 public DiskBench(String[] args){
|
jpayne@68
|
49
|
jpayne@68
|
50 {//Preparse block for help, config files, and outstream
|
jpayne@68
|
51 PreParser pp=new PreParser(args, getClass(), false);
|
jpayne@68
|
52 args=pp.args;
|
jpayne@68
|
53 outstream=pp.outstream;
|
jpayne@68
|
54 }
|
jpayne@68
|
55
|
jpayne@68
|
56 ReadWrite.USE_PIGZ=ReadWrite.USE_UNPIGZ=true;
|
jpayne@68
|
57 ReadWrite.MAX_ZIP_THREADS=Shared.threads();
|
jpayne@68
|
58
|
jpayne@68
|
59 Parser parser=new Parser();
|
jpayne@68
|
60 parser.overwrite=true;
|
jpayne@68
|
61 for(int i=0; i<args.length; i++){
|
jpayne@68
|
62 String arg=args[i];
|
jpayne@68
|
63 String[] split=arg.split("=");
|
jpayne@68
|
64 String a=split[0].toLowerCase();
|
jpayne@68
|
65 String b=split.length>1 ? split[1] : null;
|
jpayne@68
|
66
|
jpayne@68
|
67 if(a.equals("path")){
|
jpayne@68
|
68 path=b;
|
jpayne@68
|
69 if(path==null){path="";}
|
jpayne@68
|
70 else if(!path.endsWith("/")){path=path+"/";}
|
jpayne@68
|
71 }else if(a.equals("lines")){
|
jpayne@68
|
72 maxLines=Long.parseLong(b);
|
jpayne@68
|
73 if(maxLines<0){maxLines=Long.MAX_VALUE;}
|
jpayne@68
|
74 }else if(a.equals("data") || a.equals("size")){
|
jpayne@68
|
75 data=Parse.parseKMG(b);
|
jpayne@68
|
76 }else if(a.equals("passes")){
|
jpayne@68
|
77 passes=Integer.parseInt(b);
|
jpayne@68
|
78 }else if(a.equals("verbose")){
|
jpayne@68
|
79 verbose=Parse.parseBoolean(b);
|
jpayne@68
|
80 }else if(a.equals("gzip")){
|
jpayne@68
|
81 verbose=Parse.parseBoolean(b);
|
jpayne@68
|
82 }else if(a.equals("mode")){
|
jpayne@68
|
83 assert(b!=null) : "Bad parameter: "+arg;
|
jpayne@68
|
84 if(Tools.isDigit(b.charAt(0))){mode=Integer.parseInt(b);}
|
jpayne@68
|
85 else if("read".equalsIgnoreCase(b) || "r".equalsIgnoreCase(b)){mode=READ;}
|
jpayne@68
|
86 else if("write".equalsIgnoreCase(b) || "w".equalsIgnoreCase(b)){mode=WRITE;}
|
jpayne@68
|
87 else if("readwrite".equalsIgnoreCase(b) || "rw".equalsIgnoreCase(b)){mode=READWRITE;}
|
jpayne@68
|
88 else{assert(false) : "Bad mode: "+arg;}
|
jpayne@68
|
89 }else if(a.equals("read") || a.equals("r")){
|
jpayne@68
|
90 mode=READ;
|
jpayne@68
|
91 }else if(a.equals("write") || a.equals("w")){
|
jpayne@68
|
92 mode=WRITE;
|
jpayne@68
|
93 }else if(a.equals("readwrite") || a.equals("rw")){
|
jpayne@68
|
94 mode=READWRITE;
|
jpayne@68
|
95 }else if(a.equals("printtid")){
|
jpayne@68
|
96 printTid=Parse.parseBoolean(b);
|
jpayne@68
|
97 }else if(a.equals("processbis")){
|
jpayne@68
|
98 processBis=Parse.parseBoolean(b);
|
jpayne@68
|
99 }else if(a.equals("preread")){
|
jpayne@68
|
100 preRead=Parse.parseBoolean(b);
|
jpayne@68
|
101 }
|
jpayne@68
|
102
|
jpayne@68
|
103 else if(a.equals("method")){
|
jpayne@68
|
104 assert(b!=null) : "Bad parameter: "+arg;
|
jpayne@68
|
105 if(Tools.isDigit(b.charAt(0))){method=Integer.parseInt(b);}
|
jpayne@68
|
106 else if("BYTEFILE".equalsIgnoreCase(b) || "bf".equalsIgnoreCase(b)){method=BYTEFILE;}
|
jpayne@68
|
107 else if("TEXTFILE".equalsIgnoreCase(b) || "tf".equalsIgnoreCase(b)){method=TEXTFILE;}
|
jpayne@68
|
108 else if("QUICKFILE".equalsIgnoreCase(b) || "qf".equalsIgnoreCase(b)){method=QUICKFILE;}
|
jpayne@68
|
109 else if("BUFFEREDINPUTSTREAM".equalsIgnoreCase(b) || "bis".equalsIgnoreCase(b)){method=BUFFEREDINPUTSTREAM;}
|
jpayne@68
|
110 else if("FILEINPUTSTREAM".equalsIgnoreCase(b) || "fis".equalsIgnoreCase(b)){method=FILEINPUTSTREAM;}
|
jpayne@68
|
111 else if("BUFFEREDINPUTSTREAM2".equalsIgnoreCase(b) || "bis2".equalsIgnoreCase(b)){method=BUFFEREDINPUTSTREAM2;}
|
jpayne@68
|
112 else if("FILEINPUTSTREAM2".equalsIgnoreCase(b) || "fis2".equalsIgnoreCase(b)){method=FILEINPUTSTREAM2;}
|
jpayne@68
|
113 else{assert(false) : "Bad mode: "+arg;}
|
jpayne@68
|
114 }
|
jpayne@68
|
115 else if("BYTEFILE".equalsIgnoreCase(a) || "bf".equalsIgnoreCase(a)){method=BYTEFILE;}
|
jpayne@68
|
116 else if("TEXTFILE".equalsIgnoreCase(a) || "tf".equalsIgnoreCase(a)){method=TEXTFILE;}
|
jpayne@68
|
117 else if("QUICKFILE".equalsIgnoreCase(a) || "qf".equalsIgnoreCase(a)){method=QUICKFILE;}
|
jpayne@68
|
118 else if("BUFFEREDINPUTSTREAM".equalsIgnoreCase(a) || "bis".equalsIgnoreCase(a)){method=BUFFEREDINPUTSTREAM;}
|
jpayne@68
|
119 else if("FILEINPUTSTREAM".equalsIgnoreCase(a) || "fis".equalsIgnoreCase(a)){method=FILEINPUTSTREAM;}
|
jpayne@68
|
120 else if("BUFFEREDINPUTSTREAM2".equalsIgnoreCase(a) || "bis2".equalsIgnoreCase(a)){method=BUFFEREDINPUTSTREAM2;}
|
jpayne@68
|
121 else if("FILEINPUTSTREAM2".equalsIgnoreCase(a) || "fis2".equalsIgnoreCase(a)){method=FILEINPUTSTREAM2;}
|
jpayne@68
|
122 else if("buffer".equalsIgnoreCase(a) || "bufferlen".equalsIgnoreCase(a)){
|
jpayne@68
|
123 bufferlen=(int)Parse.parseKMGBinary(b);
|
jpayne@68
|
124 }
|
jpayne@68
|
125
|
jpayne@68
|
126 else if(parser.parse(arg, a, b)){
|
jpayne@68
|
127 //do nothing
|
jpayne@68
|
128 }else{
|
jpayne@68
|
129 outstream.println("Unknown parameter "+args[i]);
|
jpayne@68
|
130 assert(false) : "Unknown parameter "+args[i];
|
jpayne@68
|
131 // throw new RuntimeException("Unknown parameter "+args[i]);
|
jpayne@68
|
132 }
|
jpayne@68
|
133 }
|
jpayne@68
|
134
|
jpayne@68
|
135 {//Process parser fields
|
jpayne@68
|
136 overwrite=parser.overwrite;
|
jpayne@68
|
137 threads=Shared.threads();
|
jpayne@68
|
138 }
|
jpayne@68
|
139
|
jpayne@68
|
140 assert(FastaReadInputStream.settingsOK());
|
jpayne@68
|
141
|
jpayne@68
|
142 if(!ByteFile.FORCE_MODE_BF2){
|
jpayne@68
|
143 ByteFile.FORCE_MODE_BF2=false;
|
jpayne@68
|
144 ByteFile.FORCE_MODE_BF1=true;
|
jpayne@68
|
145 }
|
jpayne@68
|
146
|
jpayne@68
|
147 File pfile=new File(path);
|
jpayne@68
|
148 if(!pfile.exists()){pfile.mkdirs();}
|
jpayne@68
|
149 }
|
jpayne@68
|
150
|
jpayne@68
|
151 class WriteThread extends Thread{
|
jpayne@68
|
152
|
jpayne@68
|
153 public WriteThread(String fname_, long size_){
|
jpayne@68
|
154 fname=fname_;
|
jpayne@68
|
155 size=size_;
|
jpayne@68
|
156 }
|
jpayne@68
|
157
|
jpayne@68
|
158 @Override
|
jpayne@68
|
159 public void run(){
|
jpayne@68
|
160 t=new Timer();
|
jpayne@68
|
161 written=writeRandomData(fname, size, t, overwrite);
|
jpayne@68
|
162 }
|
jpayne@68
|
163
|
jpayne@68
|
164 String fname;
|
jpayne@68
|
165 long size;
|
jpayne@68
|
166 long written=0;
|
jpayne@68
|
167 Timer t;
|
jpayne@68
|
168
|
jpayne@68
|
169 }
|
jpayne@68
|
170
|
jpayne@68
|
171 public static long writeRandomData(final String fname, final long size, final Timer t, final boolean overwrite){
|
jpayne@68
|
172 if(t!=null){t.start();}
|
jpayne@68
|
173 long written=0;
|
jpayne@68
|
174 final Random randy=Shared.threadLocalRandom();
|
jpayne@68
|
175 FileFormat ffout=FileFormat.testOutput(fname, FileFormat.TEXT, null, true, overwrite, false, false);
|
jpayne@68
|
176 ByteStreamWriter bsw=new ByteStreamWriter(ffout);
|
jpayne@68
|
177 bsw.start();
|
jpayne@68
|
178 final ByteBuilder bb=new ByteBuilder(66000);
|
jpayne@68
|
179 final int shift=6;
|
jpayne@68
|
180 final int shiftsPerRand=32/shift;
|
jpayne@68
|
181 assert(shiftsPerRand>0);
|
jpayne@68
|
182 final long limit=size-20-shiftsPerRand*1000;
|
jpayne@68
|
183 while(written<limit){
|
jpayne@68
|
184 for(int i=0; i<1000; i+=shiftsPerRand){
|
jpayne@68
|
185 int x=randy.nextInt();
|
jpayne@68
|
186 for(int j=0; j<shiftsPerRand; j++){
|
jpayne@68
|
187 byte b=(byte)(33+x&63);
|
jpayne@68
|
188 bb.append(b);
|
jpayne@68
|
189 x>>=shift;
|
jpayne@68
|
190 }
|
jpayne@68
|
191 }
|
jpayne@68
|
192 // for(int i=0; i<1000; i+=shiftsPerRand){
|
jpayne@68
|
193 // long x=randy.nextLong();
|
jpayne@68
|
194 // for(int j=0; j<shiftsPerRand; j++){
|
jpayne@68
|
195 // byte b=(byte)(33+x&63);
|
jpayne@68
|
196 // bb.append(b);
|
jpayne@68
|
197 // x>>=shift;
|
jpayne@68
|
198 // }
|
jpayne@68
|
199 // }
|
jpayne@68
|
200 bb.nl();
|
jpayne@68
|
201 written+=bb.length;
|
jpayne@68
|
202 bsw.print(bb);
|
jpayne@68
|
203 bb.clear();
|
jpayne@68
|
204 }
|
jpayne@68
|
205 while(written<size-1){
|
jpayne@68
|
206 bb.append((byte)(33+(randy.nextInt()&63)));
|
jpayne@68
|
207 written++;
|
jpayne@68
|
208 }
|
jpayne@68
|
209 bb.nl();
|
jpayne@68
|
210 written+=bb.length;
|
jpayne@68
|
211 bsw.print(bb);
|
jpayne@68
|
212 bb.clear();
|
jpayne@68
|
213 bsw.poisonAndWait();
|
jpayne@68
|
214 File f=new File(fname);
|
jpayne@68
|
215 long diskSize=(f.length());
|
jpayne@68
|
216 if(t!=null){t.stop();}
|
jpayne@68
|
217 return diskSize;
|
jpayne@68
|
218 }
|
jpayne@68
|
219
|
jpayne@68
|
220 class ReadThread extends Thread{
|
jpayne@68
|
221
|
jpayne@68
|
222 public ReadThread(String fname_, int tid_){
|
jpayne@68
|
223 fname=fname_;
|
jpayne@68
|
224 tid=tid_;
|
jpayne@68
|
225 }
|
jpayne@68
|
226
|
jpayne@68
|
227 @Override
|
jpayne@68
|
228 public void run(){
|
jpayne@68
|
229 t=new Timer();
|
jpayne@68
|
230 FileFormat ffin=FileFormat.testInput(fname, FileFormat.TEXT, null, false, false, false);
|
jpayne@68
|
231
|
jpayne@68
|
232 if(method==BYTEFILE){
|
jpayne@68
|
233 runBf(ffin);
|
jpayne@68
|
234 }else if(method==QUICKFILE){
|
jpayne@68
|
235 runQf(ffin);
|
jpayne@68
|
236 }else if(method==TEXTFILE){
|
jpayne@68
|
237 runTf(ffin);
|
jpayne@68
|
238 }else if(method==BUFFEREDINPUTSTREAM){
|
jpayne@68
|
239 runBis(ffin, true);
|
jpayne@68
|
240 }else if(method==FILEINPUTSTREAM){
|
jpayne@68
|
241 runBis(ffin, false);
|
jpayne@68
|
242 }else if(method==BUFFEREDINPUTSTREAM2){
|
jpayne@68
|
243 runBis2(ffin, true);
|
jpayne@68
|
244 }else if(method==FILEINPUTSTREAM2){
|
jpayne@68
|
245 runBis2(ffin, false);
|
jpayne@68
|
246 }
|
jpayne@68
|
247 if(printTid){System.err.print(tid+",");}
|
jpayne@68
|
248 t.stop();
|
jpayne@68
|
249 }
|
jpayne@68
|
250
|
jpayne@68
|
251 private void runBf(FileFormat ffin){
|
jpayne@68
|
252 ByteFile bf=ByteFile.makeByteFile(ffin);
|
jpayne@68
|
253 for(byte[] line=bf.nextLine(); line!=null; line=bf.nextLine()){
|
jpayne@68
|
254 read+=line.length+1;
|
jpayne@68
|
255 }
|
jpayne@68
|
256 }
|
jpayne@68
|
257
|
jpayne@68
|
258 private void runQf(FileFormat ffin){
|
jpayne@68
|
259 QuickFile qf=new QuickFile(ffin);
|
jpayne@68
|
260 for(byte[] line=qf.nextLine(); line!=null; line=qf.nextLine()){
|
jpayne@68
|
261 read+=line.length+1;
|
jpayne@68
|
262 }
|
jpayne@68
|
263 }
|
jpayne@68
|
264
|
jpayne@68
|
265 private void runTf(FileFormat ffin){
|
jpayne@68
|
266 TextFile tf=new TextFile(ffin);
|
jpayne@68
|
267 for(String line=tf.nextLine(); line!=null; line=tf.nextLine()){
|
jpayne@68
|
268 read+=line.length()+1;
|
jpayne@68
|
269 }
|
jpayne@68
|
270 }
|
jpayne@68
|
271
|
jpayne@68
|
272 private void runBis(FileFormat ffin, boolean bufferedStream){
|
jpayne@68
|
273
|
jpayne@68
|
274 final byte[] buffer=new byte[bufferlen];
|
jpayne@68
|
275 InputStream is=ReadWrite.getInputStream(ffin.name(), bufferedStream, false);
|
jpayne@68
|
276
|
jpayne@68
|
277 for(int r=1; r>0; ){
|
jpayne@68
|
278 r=0;
|
jpayne@68
|
279 try {
|
jpayne@68
|
280 r=is.read(buffer);
|
jpayne@68
|
281 if(r>0){read+=r;}
|
jpayne@68
|
282
|
jpayne@68
|
283 if(processBis){
|
jpayne@68
|
284 int last=0;
|
jpayne@68
|
285 for(int i=1; i<r; i++){
|
jpayne@68
|
286 byte b=buffer[i];
|
jpayne@68
|
287 if(b=='\n'){
|
jpayne@68
|
288 cache=Arrays.copyOfRange(buffer, last, i);
|
jpayne@68
|
289 last=i+1;
|
jpayne@68
|
290 }
|
jpayne@68
|
291 }
|
jpayne@68
|
292 }
|
jpayne@68
|
293
|
jpayne@68
|
294 } catch (IOException e) {
|
jpayne@68
|
295 e.printStackTrace();
|
jpayne@68
|
296 }
|
jpayne@68
|
297 }
|
jpayne@68
|
298
|
jpayne@68
|
299 try {
|
jpayne@68
|
300 is.close();
|
jpayne@68
|
301 } catch (IOException e) {
|
jpayne@68
|
302 // TODO Auto-generated catch block
|
jpayne@68
|
303 e.printStackTrace();
|
jpayne@68
|
304 }
|
jpayne@68
|
305 }
|
jpayne@68
|
306
|
jpayne@68
|
307 private void runBis2(FileFormat ffin, boolean bufferedStream){
|
jpayne@68
|
308
|
jpayne@68
|
309 final byte[] buffer=new byte[bufferlen];
|
jpayne@68
|
310 InputStream is=ReadWrite.getInputStream(ffin.name(), bufferedStream, false);
|
jpayne@68
|
311
|
jpayne@68
|
312 list=new ArrayList<byte[]>(800);
|
jpayne@68
|
313 for(int r=1; r>0; ){
|
jpayne@68
|
314 r=0;
|
jpayne@68
|
315 try {
|
jpayne@68
|
316 r=is.read(buffer);
|
jpayne@68
|
317 if(r>0){read+=r;}
|
jpayne@68
|
318
|
jpayne@68
|
319 if(processBis){
|
jpayne@68
|
320 int last=0;
|
jpayne@68
|
321 for(int i=1; i<r; i++){
|
jpayne@68
|
322 byte b=buffer[i];
|
jpayne@68
|
323 if(b=='\n'){
|
jpayne@68
|
324 byte[] line=Arrays.copyOfRange(buffer, last, i);
|
jpayne@68
|
325 list.add(line);
|
jpayne@68
|
326 if(list.size()>=800){
|
jpayne@68
|
327 list=new ArrayList<byte[]>(800);
|
jpayne@68
|
328 }
|
jpayne@68
|
329 last=i+1;
|
jpayne@68
|
330 }
|
jpayne@68
|
331 }
|
jpayne@68
|
332 }
|
jpayne@68
|
333
|
jpayne@68
|
334 } catch (IOException e) {
|
jpayne@68
|
335 e.printStackTrace();
|
jpayne@68
|
336 }
|
jpayne@68
|
337 }
|
jpayne@68
|
338
|
jpayne@68
|
339 try {
|
jpayne@68
|
340 is.close();
|
jpayne@68
|
341 } catch (IOException e) {
|
jpayne@68
|
342 // TODO Auto-generated catch block
|
jpayne@68
|
343 e.printStackTrace();
|
jpayne@68
|
344 }
|
jpayne@68
|
345 }
|
jpayne@68
|
346
|
jpayne@68
|
347 byte[] cache;
|
jpayne@68
|
348 ArrayList<byte[]> list;
|
jpayne@68
|
349 String fname;
|
jpayne@68
|
350 long read=0;
|
jpayne@68
|
351 long lines=0;
|
jpayne@68
|
352 Timer t;
|
jpayne@68
|
353 final int tid;
|
jpayne@68
|
354
|
jpayne@68
|
355 }
|
jpayne@68
|
356
|
jpayne@68
|
357 String[] makeFnames(int pass){
|
jpayne@68
|
358 String[] fnames=new String[threads];
|
jpayne@68
|
359 Random randy=new Random();
|
jpayne@68
|
360 for(int i=0; i<threads; i++){
|
jpayne@68
|
361 fnames[i]=path+pass+"_"+i+"_"+(System.nanoTime()&0xFFFF)+"_"+randy.nextInt(4096);
|
jpayne@68
|
362 }
|
jpayne@68
|
363 return fnames;
|
jpayne@68
|
364 }
|
jpayne@68
|
365
|
jpayne@68
|
366 Timer readWrite(String[] fnamesW, String[] fnamesR){
|
jpayne@68
|
367 Timer t=new Timer();
|
jpayne@68
|
368
|
jpayne@68
|
369 WriteThread[] wta=new WriteThread[threads];
|
jpayne@68
|
370 long size=data/threads;
|
jpayne@68
|
371 for(int i=0; i<threads; i++){
|
jpayne@68
|
372 wta[i]=new WriteThread(fnamesW[i], size);
|
jpayne@68
|
373 }
|
jpayne@68
|
374 for(int i=0; i<threads; i++){
|
jpayne@68
|
375 wta[i].start();
|
jpayne@68
|
376 }
|
jpayne@68
|
377
|
jpayne@68
|
378 ReadThread[] rta=new ReadThread[threads];
|
jpayne@68
|
379 for(int i=0; i<threads; i++){
|
jpayne@68
|
380 rta[i]=new ReadThread(fnamesR[i], i);
|
jpayne@68
|
381 }
|
jpayne@68
|
382 for(int i=0; i<threads; i++){
|
jpayne@68
|
383 rta[i].start();
|
jpayne@68
|
384 }
|
jpayne@68
|
385
|
jpayne@68
|
386 for(int i=0; i<threads; i++){
|
jpayne@68
|
387 while(wta[i].getState()!=Thread.State.TERMINATED){
|
jpayne@68
|
388 try {
|
jpayne@68
|
389 wta[i].join();
|
jpayne@68
|
390 } catch (InterruptedException e) {
|
jpayne@68
|
391 // TODO Auto-generated catch block
|
jpayne@68
|
392 e.printStackTrace();
|
jpayne@68
|
393 }
|
jpayne@68
|
394 }
|
jpayne@68
|
395 }
|
jpayne@68
|
396
|
jpayne@68
|
397 for(int i=0; i<threads; i++){
|
jpayne@68
|
398 while(rta[i].getState()!=Thread.State.TERMINATED){
|
jpayne@68
|
399 try {
|
jpayne@68
|
400 rta[i].join();
|
jpayne@68
|
401 } catch (InterruptedException e) {
|
jpayne@68
|
402 // TODO Auto-generated catch block
|
jpayne@68
|
403 e.printStackTrace();
|
jpayne@68
|
404 }
|
jpayne@68
|
405 }
|
jpayne@68
|
406 }
|
jpayne@68
|
407
|
jpayne@68
|
408 t.stop();
|
jpayne@68
|
409 return t;
|
jpayne@68
|
410 }
|
jpayne@68
|
411
|
jpayne@68
|
412 Timer write(String[] fnames){
|
jpayne@68
|
413 Timer t=new Timer();
|
jpayne@68
|
414 WriteThread[] wta=new WriteThread[threads];
|
jpayne@68
|
415 long size=data/threads;
|
jpayne@68
|
416 for(int i=0; i<threads; i++){
|
jpayne@68
|
417 wta[i]=new WriteThread(fnames[i], size);
|
jpayne@68
|
418 }
|
jpayne@68
|
419 for(int i=0; i<threads; i++){
|
jpayne@68
|
420 wta[i].start();
|
jpayne@68
|
421 }
|
jpayne@68
|
422 for(int i=0; i<threads; i++){
|
jpayne@68
|
423 while(wta[i].getState()!=Thread.State.TERMINATED){
|
jpayne@68
|
424 try {
|
jpayne@68
|
425 wta[i].join();
|
jpayne@68
|
426 } catch (InterruptedException e) {
|
jpayne@68
|
427 // TODO Auto-generated catch block
|
jpayne@68
|
428 e.printStackTrace();
|
jpayne@68
|
429 }
|
jpayne@68
|
430 }
|
jpayne@68
|
431 }
|
jpayne@68
|
432 t.stop();
|
jpayne@68
|
433 return t;
|
jpayne@68
|
434 }
|
jpayne@68
|
435
|
jpayne@68
|
436 Timer read(String[] fnames){
|
jpayne@68
|
437
|
jpayne@68
|
438 Timer t=new Timer();
|
jpayne@68
|
439
|
jpayne@68
|
440 if(preRead){
|
jpayne@68
|
441 ReadThread rt=new ReadThread(fnames[0], 0);
|
jpayne@68
|
442 rt.start();
|
jpayne@68
|
443 while(rt.getState()!=Thread.State.TERMINATED){
|
jpayne@68
|
444 try {
|
jpayne@68
|
445 rt.join();
|
jpayne@68
|
446 } catch (InterruptedException e) {
|
jpayne@68
|
447 // TODO Auto-generated catch block
|
jpayne@68
|
448 e.printStackTrace();
|
jpayne@68
|
449 }
|
jpayne@68
|
450 }
|
jpayne@68
|
451 }
|
jpayne@68
|
452
|
jpayne@68
|
453 ReadThread[] rta=new ReadThread[threads];
|
jpayne@68
|
454 for(int i=0; i<threads; i++){
|
jpayne@68
|
455 rta[i]=new ReadThread(fnames[i], i);
|
jpayne@68
|
456 }
|
jpayne@68
|
457 for(int i=0; i<threads; i++){
|
jpayne@68
|
458 rta[i].start();
|
jpayne@68
|
459 }
|
jpayne@68
|
460 for(int i=0; i<threads; i++){
|
jpayne@68
|
461 while(rta[i].getState()!=Thread.State.TERMINATED){
|
jpayne@68
|
462 try {
|
jpayne@68
|
463 rta[i].join();
|
jpayne@68
|
464 } catch (InterruptedException e) {
|
jpayne@68
|
465 // TODO Auto-generated catch block
|
jpayne@68
|
466 e.printStackTrace();
|
jpayne@68
|
467 }
|
jpayne@68
|
468 }
|
jpayne@68
|
469 linesInternal+=(rta[i].list==null ? 0 : rta[i].list.size());
|
jpayne@68
|
470 }
|
jpayne@68
|
471 t.stop();
|
jpayne@68
|
472 return t;
|
jpayne@68
|
473 }
|
jpayne@68
|
474
|
jpayne@68
|
475 void delete(String[] fnames){
|
jpayne@68
|
476 for(String s : fnames){
|
jpayne@68
|
477 File f=new File(s);
|
jpayne@68
|
478 if(f.exists()){
|
jpayne@68
|
479 f.delete();
|
jpayne@68
|
480 }
|
jpayne@68
|
481 }
|
jpayne@68
|
482 }
|
jpayne@68
|
483
|
jpayne@68
|
484 void process(Timer t0){
|
jpayne@68
|
485
|
jpayne@68
|
486 t0.start();
|
jpayne@68
|
487 String[] fnamesW=makeFnames(0);
|
jpayne@68
|
488
|
jpayne@68
|
489 Timer t=write(fnamesW);
|
jpayne@68
|
490 String[] fnamesR=fnamesW;
|
jpayne@68
|
491 fnamesW=null;
|
jpayne@68
|
492
|
jpayne@68
|
493 final long initialWriteElapsed=t.elapsed;
|
jpayne@68
|
494
|
jpayne@68
|
495 System.err.println("Initial write: \t"+t.toString()+" \t"+String.format(Locale.ROOT, "%.3f MB/s", (1000.0*data)/t.elapsed));
|
jpayne@68
|
496
|
jpayne@68
|
497 for(int pass=0; pass<passes; pass++){
|
jpayne@68
|
498 if(mode==READWRITE){
|
jpayne@68
|
499 fnamesW=makeFnames(pass);
|
jpayne@68
|
500 t=readWrite(fnamesW, fnamesR);
|
jpayne@68
|
501 delete(fnamesR);
|
jpayne@68
|
502 fnamesR=fnamesW;
|
jpayne@68
|
503 fnamesW=null;
|
jpayne@68
|
504 }else if(mode==READ){
|
jpayne@68
|
505 t=read(fnamesR);
|
jpayne@68
|
506 }else{
|
jpayne@68
|
507 delete(fnamesR);
|
jpayne@68
|
508 fnamesW=makeFnames(pass);
|
jpayne@68
|
509 t=write(fnamesW);
|
jpayne@68
|
510 fnamesR=fnamesW;
|
jpayne@68
|
511 fnamesW=null;
|
jpayne@68
|
512 }
|
jpayne@68
|
513 System.err.println("Pass "+pass+": \t"+t.toString()+" \t"+String.format(Locale.ROOT, "%.3f MB/s", (1000.0*data)/t.elapsed));
|
jpayne@68
|
514 }
|
jpayne@68
|
515 delete(fnamesR);
|
jpayne@68
|
516
|
jpayne@68
|
517 t0.stop();
|
jpayne@68
|
518 System.err.println("Overall: \t"+t0.toString()+" \t"+String.format(Locale.ROOT, "%.3f MB/s", (1000.0*(data*passes))/(t0.elapsed-initialWriteElapsed)));
|
jpayne@68
|
519
|
jpayne@68
|
520 if(errorState){
|
jpayne@68
|
521 throw new RuntimeException(getClass().getName()+" terminated in an error state; the output may be corrupt.");
|
jpayne@68
|
522 }
|
jpayne@68
|
523 }
|
jpayne@68
|
524
|
jpayne@68
|
525 /*--------------------------------------------------------------*/
|
jpayne@68
|
526
|
jpayne@68
|
527
|
jpayne@68
|
528 /*--------------------------------------------------------------*/
|
jpayne@68
|
529
|
jpayne@68
|
530 private String path="";
|
jpayne@68
|
531
|
jpayne@68
|
532 /*--------------------------------------------------------------*/
|
jpayne@68
|
533
|
jpayne@68
|
534 private int bufferlen=4096;
|
jpayne@68
|
535 private long data=8000000000L;
|
jpayne@68
|
536 private int passes=2;
|
jpayne@68
|
537
|
jpayne@68
|
538 public int linesInternal;
|
jpayne@68
|
539
|
jpayne@68
|
540 private int threads;
|
jpayne@68
|
541
|
jpayne@68
|
542 private long maxLines=Long.MAX_VALUE;
|
jpayne@68
|
543
|
jpayne@68
|
544 int mode=READWRITE;
|
jpayne@68
|
545 static final int READWRITE=1, READ=2, WRITE=3;
|
jpayne@68
|
546
|
jpayne@68
|
547 boolean printTid=false;
|
jpayne@68
|
548 boolean processBis=false;
|
jpayne@68
|
549 boolean preRead=false;
|
jpayne@68
|
550
|
jpayne@68
|
551 int method=BYTEFILE;
|
jpayne@68
|
552 static final int BYTEFILE=1;
|
jpayne@68
|
553 static final int TEXTFILE=2;
|
jpayne@68
|
554 static final int BUFFEREDINPUTSTREAM=3;
|
jpayne@68
|
555 static final int FILEINPUTSTREAM=4;
|
jpayne@68
|
556 static final int BUFFEREDINPUTSTREAM2=5;
|
jpayne@68
|
557 static final int FILEINPUTSTREAM2=6;
|
jpayne@68
|
558 static final int QUICKFILE=7;
|
jpayne@68
|
559
|
jpayne@68
|
560 /*--------------------------------------------------------------*/
|
jpayne@68
|
561
|
jpayne@68
|
562 /*--------------------------------------------------------------*/
|
jpayne@68
|
563
|
jpayne@68
|
564 private PrintStream outstream=System.err;
|
jpayne@68
|
565 public static boolean verbose=false;
|
jpayne@68
|
566 public boolean errorState=false;
|
jpayne@68
|
567 private boolean overwrite=true;
|
jpayne@68
|
568
|
jpayne@68
|
569 }
|