nio rules of thumb

R

Roedy Green

I was souping up the nio entry in the Java glossary.

I wondered if people had rules of thumb about when direct buffers or
memory mapping might give better performance.

I would have though memory mapping would only apply to random access,
but Sun hints otherwise.

I would guess direct buffers are for when you do a lot of skipping?
 
S

Stefan Schulz

I wondered if people had rules of thumb about when direct buffers or
memory mapping might give better performance.

My "rule of thumb" would be: "If in doubt, don't do it." Whenever i used
memory mapping, it proved to be no large gain in performance, sometimes on
the contrary, actually.
 
T

Thomas Hawtin

Roedy said:
I was souping up the nio entry in the Java glossary.

I wondered if people had rules of thumb about when direct buffers or
memory mapping might give better performance.

I would have though memory mapping would only apply to random access,
but Sun hints otherwise.

It reduces memory when multiple processes use the same file. As I
understand it, Solaris/Linux versions of Sun's JRE used to memory map
jars. In the latest builds of Mustang that is no longer true, reducing
memory consumption and improving performance. Because you cannot cache
parts of a page independently, you may well (perhaps probably) end up
throwing away huge quantities of physical memory, which is a bad thing.
I would guess direct buffers are for when you do a lot of skipping?

Direct allocated buffers are dangerous things. There is no way unmap
them. You are at the mercy of the garbage collector, which doesn't take
into consideration the direct buffer memory. However, bulk operating
systems operations on them should be faster.

So only use them if *both* it is performance critical and you will not
be reallocating buffers.

Tom Hawtin
 
R

Roedy Green

Direct allocated buffers are dangerous things. There is no way unmap
them. You are at the mercy of the garbage collector, which doesn't take
into consideration the direct buffer memory. However, bulk operating
systems operations on them should be faster.

thanks Thomas. I have added your wisdom to the entry at
http://mindprod.com/jgloss/nio.html
 
T

Thomas Hawtin

There is something else worth noting about NIO buffers that isn't often
mentioned. Read and writing individual bytes goes through a lot of
indirection, even though what you are trying to achieve is very simple.
For Sun's HotSpot you need to make sure that the method with your inner
loop is very small. If it isn't then the access code wont be inlined and
it will run very slowly.

Cameron Purdy did some IOless NIO benchmarks:

http://www.jroller.com/page/cpurdy/20040406

Tom Hawtin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

rules of thumb for cross os code 2
Using NIO 2
nio classes 1
benefits of NIO 2
java nio, memory mapping limits 5
NIO SelectionKey.interestOps() blocking 0
Twelve rules of Ruby 30
many files and NIO 3

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top