Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Java File I/O terribly slow

Java File I/O terribly slow
Thread Tools
D'Espice
Mac Elite
Join Date: Apr 2002
Location: Here and there
Status: Offline
Reply With Quote
Jun 14, 2004, 06:35 PM
 
Hi,

I wrote a Java application for small and medium sized hotels and found out, that it's terribly slow on Macs for some reason. The app loads a reservation table via FileInputStream/ObjectInputStream which contains an ArrayList of String[100000] for each room. For 34 rooms it takes about 3s to load on my Opteron, about 5s on the P4/1.8 GHz at work yet several minutes on a G4/867 running OS X 10.3 with the latest Apple Java MRJ.

I had to create a special Mac Version with only 20,000 entries for each room which however is still unbearably slow. Less than 1s on my Opteron, 1-2s on the P4 yet almost 17s on a G4. I assume that Apple's Java Implementation is just, well, awful. Is there any workaround that will NOT require me to switch to RandomFileAccess or make me decrease the database size to less than 10000 entries per room?

You can check it out for yourselves, download v. 0.62 from http://sourceforge.net/projects/jhotel. That's the version with 100,000 entries per room and completely unusable on Macs. If you want the version with 20,000 entries per room (v 0.62.1) which I do not intend to publish on SF, email/pm me and I'll send it to you via email.
"Life is not a journey to the grave with the intention of arriving safely in one
pretty and well preserved piece, but to skid across the line broadside,
thoroughly used up, worn out, leaking oil, shouting GERONIMO!"
     
Arkham_c
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status: Offline
Reply With Quote
Jun 14, 2004, 08:55 PM
 
How do I run it to test the I/O?

A few observations:

1) All those internal classes -- yuck!
2) Consider an ant build script
3) setNextFocusableComponent(java.awt.Component) in javax.swing.JComponent has been deprecated
4) Have you considered package management? 32 source files in the default package.
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
     
thefamousmred
Junior Member
Join Date: Mar 2002
Status: Offline
Reply With Quote
Jun 14, 2004, 09:52 PM
 
Originally posted by D'Espice:
Hi,

I wrote a Java application for small and medium sized hotels and found out, that it's terribly slow on Macs for some reason. The app loads a reservation table via FileInputStream/ObjectInputStream which contains an ArrayList of String[100000] for each room. For 34 rooms it takes about 3s to load on my Opteron, about 5s on the P4/1.8 GHz at work yet several minutes on a G4/867 running OS X 10.3 with the latest Apple Java MRJ.
This isn't much more than a wild-assed guess, but from looking at your code and the results I'd say it's a buffering problem. You creat ObjectInputStreams with a FileInputStream; any object you read from the OIS will result in one or more calls to the FIS. Since the FIS isn't buffered by default, that will result in a disk access for each read call. Disk access is very slow, and should be avoided whenever possible. My guess is that this performs fine on Windows because Windows systems buffer file access at the OS level, whereas OS X won't necessarily do that.

To fix performance, try wrapping the FileInputStream in a BufferedInputStream, and pass the BIS to the ObjectInputStream constructor:

FileInputStream fis = new FileInputStream("./db/restable.jh");
BufferedInputStreambfis = new BufferedInputStream(fis);
ObjectInputStream ois = new ObjectInputStream(fbs);

The BufferedInputStream will read a chunk of data from the FileInputStream, and use that to service requests from the ObjectInputStream. Once the buffer runs out, the BIS will read another chunk from the FIS. This should dramatically reduce the number of disk reads, speeding up the app. For even more performance you can experiment with different buffer sizes in the BIS constructor.
     
D'Espice  (op)
Mac Elite
Join Date: Apr 2002
Location: Here and there
Status: Offline
Reply With Quote
Jun 15, 2004, 03:38 AM
 
Hmm... that sounds interesting, I'm gonna give that a shot, thanks.

@Arkham_c

I run the test by simply opening the reservation management window. I know that it's deprecated but it's working, I'm gonna take care of that as soon as it stops working
And about those internal classes, how would you do it? I tried to split it up into as many source files as possibe cause IMHO several small files/classes are better than a huge one.
"Life is not a journey to the grave with the intention of arriving safely in one
pretty and well preserved piece, but to skid across the line broadside,
thoroughly used up, worn out, leaking oil, shouting GERONIMO!"
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 07:31 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,