Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Mac OS X File IO Performance Issue?



Howdy all!

I'm new to the list, so forgive me if this has been gone over before. 
I've written a program that needs to read/write lots of cache files to
disk.  They are around 100k a piece though it can vary quite a bit. 
In response to user action I need to load 2-5 of these cache files and
update the GUI.  On windows and linux the read times for these cache
images average around 250ms.  However on OS X the mean time to load
rises to 450ms with some exceeding 1200ms.

I set out to find what was causing this bottleneck, so I wrote this
small class to test IO performance:

public class RawIOBenchmark {
    long testStart, testEnd;

    public RawIOBenchmark(File fileToTest) throws Exception {
        long result = testStraightFileIO(fileToTest);
        System.out.println("Straight File IO > took = " + result + "
milliseconds.");
    }

    private long testStraightFileIO(File fileToTest) throws Exception {
        byte[] buffer = new byte[new Long(fileToTest.length()).intValue()];
        FileInputStream fis = new FileInputStream(fileToTest);
        testStart = System.currentTimeMillis();
        int bytesRead = 0;
        int read = fis.read(buffer, 0, buffer.length);
        bytesRead += read;
        while(bytesRead < buffer.length && read != -1) {
            read = fis.read(buffer, bytesRead, buffer.length - bytesRead);
            bytesRead += read;
        }
        System.out.println("bytes read:"+bytesRead);
        testEnd = System.currentTimeMillis();
        return (testEnd - testStart);
    }

    public static void main(String[] args) throws Exception {
        System.out.println("args.length = " + args.length);
        if(args.length != 1) {
            System.out.println("Please specify file or directory to test.");
            System.exit(-1);
        }

        File fileToTest = new File(args[0]);
        if(fileToTest.isFile())
            new RawIOBenchmark(fileToTest);
        else if(fileToTest.isDirectory()) {
            File[] files = fileToTest.listFiles();
            for (int i = 0; i < files.length; i++) {
                File file = files[i];
                new RawIOBenchmark(file);
            }
        }

    }

}

I pointed this little test class at a directory filled with 1 - 1.5Meg
jpegs.  About 95 of them.  Here's what I wound up with:

Min: 25ms (Faster then any other platform)
Max: 8935ms (Slower by a factor of 5 then any other platform)
Mean: 2030ms (Slower by half then any other platform)

I've played with memory settings, from 64m to 1024m.  I've turned on
verbose garbage collection.  Nothing seems to explain it.

Am I doing something horribly wrong?  Anyone else run into this?

Thanks in advance,

- Will
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.