Suresh Thalamati wrote: > > It would be great if some one can run this test on other platforms and > post the results to the list.
I have added display of percentual difference to make it easier to look at. Results vary a lot, so dont take it for absolute. Heres what I got on my Linux (FC3, Celeron 800, 512MB, 2 IDE DISK RAID1 ext3 fs) [EMAIL PROTECTED] ~]# java -cp . allignWritePerfTest2 kuk.bin 128 (Buffer-Size(K) | Alligned Write(msec) |NonAlligned Write(msec)) | gain % 512 | 21.0390625 | 27.2265625 | 29.409580393613084% 512 | 20.4921875 | 26.609375 | 29.85131528783836% 512 | 20.40625 | 28.46875 | 39.50995405819296% 512 avg ~ 33% 256 | 10.1328125 | 18.3359375 | 80.95605242868157% 256 | 10.234375 | 20.375 | 99.08396946564886% 256 | 10.0546875 | 19.3046875 | 91.996891996892% 256 avg ~ 50% 128 | 5.3515625 | 12.96875 | 142.33576642335765% 128 | 5.1640625 | 13.6640625 | 164.59909228441757% 128 | 5.28125 | 13.125 | 148.5207100591716% 128 avg ~151% 64 | 2.578125 | 10.515625 | 307.8787878787879% 64 | 2.53125 | 10.625 | 319.75308641975306% 64 | 2.5703125 | 10.375 | 303.64741641337383% 64 avg ~310% 32 | 1.453125 | 2.1796875 | 50.0% 32 | 1.3828125 | 1.8828125 | 36.15819209039549% 32 | 1.4609375 | 1.8984375 | 29.946524064171115% 32 avg ~ 38% 16 | 1.1796875 | 3.015625 | 155.6291390728477% 16 | 1.1328125 | 2.8515625 | 151.72413793103448% 16 | 1.109375 | 2.8671875 | 158.45070422535213% 16 avg ~155% 12 | 1.1328125 | 2.8125 | 148.27586206896552% 12 | 0.921875 | 2.421875 | 162.71186440677968% 12 | 0.8046875 | 2.40625 | 199.02912621359224% 12 avg ~169% 10 | 2.171875 | 2.4453125 | 12.589928057553962% 10 | 2.1796875 | 2.1484375 | -1.4336917562723954% 10 | 2.0625 | 2.4296875 | 17.803030303030297% 10 avg ~ 9% 8 | 0.5078125 | 2.125 | 318.46153846153845% 8 | 0.859375 | 1.8515625 | 115.45454545454547% 8 | 0.4921875 | 2.3828125 | 384.12698412698415% 8 avg ~272% 6 | 1.6796875 | 2.6640625 | 58.6046511627907% 6 | 2.8203125 | 2.859375 | 1.3850415512465304% 6 | 1.28125 | 2.0703125 | 61.585365853658544% 6 avg ~ 40% 4 | 0.984375 | 1.6171875 | 64.28571428571428% 4 | 1.015625 | 2.0859375 | 105.38461538461539% 4 | 0.84375 | 1.515625 | 79.62962962962962% 4 avg ~ 82% 2 | 0.671875 | 0.7109375 | 5.813953488372093% 2 | 1.0078125 | 0.6328125 | -37.2093023255814% 2 | 0.6640625 | 0.7890625 | 18.82352941176471% 2 avg ~ -4% 1 | 0.4921875 | 0.3046875 | -38.095238095238095% 1 | 0.25 | 0.296875 | 18.75% 1 | 0.25 | 0.3046875 | 21.875% 1 avg ~ -1% Ordered by speed gain: 64 avg ~310% 8 avg ~272% 12 avg ~169% 16 avg ~155% 128 avg ~151% 4 avg ~ 82% 256 avg ~ 50% 6 avg ~ 40% 32 avg ~ 38% 512 avg ~ 33% 10 avg ~ 9% 1 avg ~ -1% 2 avg ~ -4% Here it looks like: 1) its a lot faster for some reason (you got slow disk ;)) 2) we can get actual slowdown for buffer sizes not multiple of 4k 3) we get slowdown for buffers < 4k 3) we get speedup for sizes > 4k which are multiples of 4k (Linux uses 4k for everything) 4) best gain on 64k, 8k (about 4 times faster) Jan
import java.io.*;
/** Tests the performance of alligned writes versus non-alligned writes with
* various buffer sizes. Perfoms writes on each buffer size N times and prints
the
* amount of time it takes to write single buffer on average in alligned Write
Vs
* Non-Alligned on a preallocated file.
* To run : java allignWritePerfTest <file Name> <No Of Writes>
*/
public class allignWritePerfTest2 {
public static void main(String[] args)
{
if(args.length < 2)
{
System.out.println("java allignWritePefTest <file Name>
<No Of Writes>");
return;
}
String filepath = args[0];
int nWrites = (Integer.valueOf(args[1])).intValue();
int bufferSizes[] = {512, 256 , 128 , 64, 32, 16 , 12 , 10 , 8
, 6, 4, 2, 1};
System.out.println("(Buffer-Size(K) " + "| Alligned Write(msec)
" + "|NonAlligned Write(msec)) | gain %");
System.out.println();
for(int k = 0 ; k < bufferSizes.length; k++)
{
int bufferSize = bufferSizes[k] * 1024 ;
byte[] dataBuffer = new byte[bufferSize];
for(int i =0 ; i < bufferSize ; i++)
dataBuffer[i] = (byte) i;
// perform alligned writes
double allignedWriteTime =
measureWriteTime(filepath,dataBuffer, nWrites,true);
// non alligned writes
double NonAllignedWriteTime =
measureWriteTime(filepath, dataBuffer, nWrites, false);
System.out.println(bufferSizes[k] +" | " +
allignedWriteTime +
" | " +
NonAllignedWriteTime +" | "+
((100.0*NonAllignedWriteTime/allignedWriteTime)-100.0)+"%");
}
}
// returns the amount of time taken to write the given buffer
private static double measureWriteTime(String filepath, byte
dataBuffer[],
int nWrites, boolean alligned)
{
double writeTime = -1;
File fl = new File(filepath);
try{
//delete the file
if(fl.exists())
{
if(!fl.delete())
{
System.out.println("Error: File Could
Not Be Deleted:" + filepath);
return -1;
}
}
//create a new File
if(!fl.createNewFile())
{
System.out.println("New File Creation Error:" +
filepath);
return -1;
}
//preallocate the file and fill it up with zeros
preAllocate(filepath, dataBuffer.length, nWrites);
writeTime = doWrites(filepath, dataBuffer, nWrites,
alligned);
}catch(IOException ioe)
{
ioe.printStackTrace();
}
fl=null; //release the file handle
return writeTime;
}
//mesure the time taken to write a given buffer
private static double doWrites(String filename, byte[] buffer,
int nWrites,
boolean aligned)
throws IOException
{
RandomAccessFile frs = new RandomAccessFile(filename, "rws");
//in case of non alligned writes, seek to random
//position in the first sector, it will make the
//write request non-alligned on sector boundaries.
if(!aligned)
frs.seek(24);
double before = (double)System.currentTimeMillis();
for(int i = 0 ; i < nWrites ; i++)
frs.write(buffer);
double after = (double)System.currentTimeMillis();
frs.close();
double timetakeForWrite = (after - before)/nWrites;
return timetakeForWrite;
}
//preallocate the file by filling it up with zeros.
private static void preAllocate(String filename, int bufferSize, int
nWrites)
throws IOException
{
byte[] buffer = new byte[bufferSize];
RandomAccessFile frs = new RandomAccessFile(filename, "rw");
FileDescriptor fd = frs.getFD();
for(int i = 0; i < nWrites ; i++)
{
frs.write(buffer);
}
fd.sync();
frs.close();
}
}
signature.asc
Description: OpenPGP digital signature
