dcsimg
Memory mapped file - slow performance when writing
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Wednesday, September 20, 2006 06:52 AM

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 ? // Assume that destination file ("myFile.dat") is *empty* . int BUF_SIZE = 1000000000; // 1 GB FileChannel fileChannel =new RandomAccessFile("myFile.dat", "rw").getChannel(); fileChannel.close(); MappedByteBuffer mappedBuf=fileChannel.map(MapMode.READ_   More>>

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 ?


			
// Assume that destination file ("myFile.dat") is *empty* .

int BUF_SIZE = 1000000000; // 1 GB
FileChannel fileChannel =new RandomAccessFile("myFile.dat", "rw").getChannel();
fileChannel.close();
MappedByteBuffer mappedBuf=fileChannel.map(MapMode.READ_WRITE, 0, BUF_SIZE);

for(int i=0; i <20000000; i++)
mappedBuf.put( someBytes);

mappedBuf.force();
mappedBuf=null;
System.gc(); // unsafe workaround for lack of 'unmap' method.



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 !    <<Less

Re: Memory mapped file - slow performance when writing

Posted By:   Christopher_Koenigsberg  
Posted On:   Monday, October 9, 2006 02:50 PM

Have you tried with different buffer sizes?
About | Sitemap | Contact