[ 
https://issues.apache.org/jira/browse/CASSANDRA-8670?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14382646#comment-14382646
 ] 

Benedict commented on CASSANDRA-8670:
-------------------------------------

bq. By assert you mean an assert that compiles out or a precondition?

I don't mind, really. It's just for clarity

bq. I guess I don't get when this optimization will help. I could see it 
hurting. You could stream through the buffer not returning to the beginning on 
a regular basis and end up issuing smaller then desired reads.

It was more a suggestion for clarity - at least, in my opinion. Assuming we 
typically fill the buffer, it isn't really a problem, and if we don't we 
usually have room to fill after it (although if we were to try to fill an 
almost full buffer it would be a problem; but so is repeatedly shuffling a 
buffer that is regularly very underfilled). But perhaps some more comments 
explaining the behaviour of (and reasoning behind) each branch is a better 
solution, along with the assertions to make clear this is not a costly or 
common operation.

bq. DataInputStream for a socket returns 0

DataInputStream isn't buffered. BufferedInputStream, and the API spec in 
InputStream#available suggest we should return number of bytes we have buffered

bq. We also use it copy things into our buffer while preserving the original 
position.

In this scenario it is likely cheaper to simply restore the position once done, 
and this approach also means we can likely typically avoid ever allocating a 
hollow buffer. There is also no (typical) risk of exception, so no reason to 
use the hollow buffer, since we can guarantee we will be able to restore its 
position.

bq. I am not sure what you mean by hollow buffer larger then our buffer

I meant parameter provided buffer

There are also some formatting issues I forgot to mention (braces on the wrong 
line, and lots of extra linebreaks between methods)

> Large columns + NIO memory pooling causes excessive direct memory usage
> -----------------------------------------------------------------------
>
>                 Key: CASSANDRA-8670
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-8670
>             Project: Cassandra
>          Issue Type: Bug
>          Components: Core
>            Reporter: Ariel Weisberg
>            Assignee: Ariel Weisberg
>             Fix For: 3.0
>
>         Attachments: largecolumn_test.py
>
>
> If you provide a large byte array to NIO and ask it to populate the byte 
> array from a socket it will allocate a thread local byte buffer that is the 
> size of the requested read no matter how large it is. Old IO wraps new IO for 
> sockets (but not files) so old IO is effected as well.
> Even If you are using Buffered{Input | Output}Stream you can end up passing a 
> large byte array to NIO. The byte array read method will pass the array to 
> NIO directly if it is larger than the internal buffer.  
> Passing large cells between nodes as part of intra-cluster messaging can 
> cause the NIO pooled buffers to quickly reach a high watermark and stay 
> there. This ends up costing 2x the largest cell size because there is a 
> buffer for input and output since they are different threads. This is further 
> multiplied by the number of nodes in the cluster - 1 since each has a 
> dedicated thread pair with separate thread locals.
> Anecdotally it appears that the cost is doubled beyond that although it isn't 
> clear why. Possibly the control connections or possibly there is some way in 
> which multiple 
> Need a workload in CI that tests the advertised limits of cells on a cluster. 
> It would be reasonable to ratchet down the max direct memory for the test to 
> trigger failures if a memory pooling issue is introduced. I don't think we 
> need to test concurrently pulling in a lot of them, but it should at least 
> work serially.
> The obvious fix to address this issue would be to read in smaller chunks when 
> dealing with large values. I think small should still be relatively large (4 
> megabytes) so that code that is reading from a disk can amortize the cost of 
> a seek. It can be hard to tell what the underlying thing being read from is 
> going to be in some of the contexts where we might choose to implement 
> switching to reading chunks.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to