sun.nio.ch.Util: Don't cache an unlimited amount of memory

Alan Bateman Alan.Bateman at oracle.com
Wed Dec 30 14:53:23 UTC 2015


On 29/12/2015 15:59, Evan Jones wrote:
> :
>
> My (simple) proposal will have a performance impact for applications 
> that do large I/O with heap ByteBuffers. However, I would argue those 
> apps are already slow because of the copy, and probably won't notice :).
>
> Would you be interested in a more sophisticated solution that would 
> allow huge cached buffers to eventually expire? For example, if the 
> "recent" usage of the cache has been much smaller than the allocated 
> buffers, free the buffers and re-allocate? For the problematic 
> application that I found, *any* policy for when to expire would 
> effectively solve this problem, since the "peak" usage is 
> significantly worse than the "average" usage.
A more sophisticated solution makes it harder to explain when examining 
the memory usage so something simple might not be too bad. I would 
suggest go ahead and propose something here, it sounds like you might 
already have -Djdk.nio.maxCachedBufferSize=1m like solution already.

>
> My final suggestion: I would be happy to attempt to revise the javadoc 
> about direct buffers to make it clearer that using heap buffers for 
> I/O will cause copies, and will also cause the JDK to cache native 
> memory. At least then we could argue that this behaviour is "as 
> designed." :)
An @implNote for SocketChannel and FileChannel (mostly these two) might 
be helpful.

-Alan


More information about the nio-dev mailing list