• Post Reply Bookmark Topic Watch Topic
  • New Topic

Memory mapped file - slow performance when writing

 
Sol Mayer-Orn
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I need to create a file holding about 2 GB of data.
I'm using Sun's JDK 5 on Windows XP.

I've tried 2 approaches:
- Standard BufferedOutputStream
- Memory mapped file (MappedByteBuffer)

To my surprise, the MappedByteBuffer approach seems to be twice(!) as slow... could anyone please tell if I'm doing anything wrong ?
Here's my (slow) code, using MappedByteBuffer:



Some notes:
1. I start off with an empty file (creating it from scratch)

2. The required file size is known in advance (exactly 2000000000).

3. I'm aware the 'System.gc' at the end is problematic, but I can live with it for now - my question focuses on performance, not no cleanup.

Thanks
 
Vlado Zajac
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The force() method may be the cause (if you don't use force with FileOutputStream/FileChannel and have enough memory).

I wouldn't use mapped file for sequentional I/O.

What is someBytes?
[ September 20, 2006: Message edited by: Vlado Zajac ]
 
Joe Ess
Bartender
Posts: 9362
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BufferedWriter has an 8k buffer, so it's going to perform 244,141 write operations. Compare that to the 20,000,000 write operations you've hard coded in your code above. Perhaps increasing the size of someBytes will help?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!