-
Notifications
You must be signed in to change notification settings - Fork 865
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How is the API zero copy? #18
Comments
I was expecting something like this: // Just allocate a buffer flyweight object without having it point to real memory. // This tries to reserve lengthOfMyData bytes on the underlying logbuffer. |
The statement is that the data is copy-free in the processing the log buffers. This is very unusual in a message transport. However it is funny that you mention because this week I'm working on an additional API that will allow the claiming of a range in the log buffer so it can be written directly into. This will not really matter when going off box but should make a difference in the IPC case on box. The API will look something like:
|
Awesome! |
I've pushed a commit that offers this functionality. 8ed70c4 Works like the following:
|
What will happen to the state of the
|
It is a good point and something people have to be carefully about. The issue with such a lambda is that is it likely to be capturing and thus will allocate and have an impact on latency. |
You can work around the capturing, by allowing arguments to be floated through. The Disruptor's EventSink interface does this. See the description about using Java 8, it has a couple of notes around capturing Lambdas. |
In your example |
Not in the second example, where a method reference is used. |
OK I see what you are doing. This can work for a single argument which might be sufficient for many cases. Could be an option consider. |
I supported up to three and varargs (although varargs will potentially allocate). In the multi-producer case, failing to call commit/publish will leave the Disruptor (and similarly the LogBuffer - I think) in an invalid and unrepairable state. The most common case of this occurring is when the caller fails to do their exception handling correctly (commit must be in a finally block). With the Disruptor I recommend the publishEvent call as the default approach only only use next()/publish() if some advanced use case is required. I would suggest something similar for Aeron. |
Varargs definitely allocates. Its also probably worse than a capturing lambda as well, because it needs to initialise the array of arguments. I think really the only people who should be using this API are advanced users of the IPC case who are being bottlenecked by the additional copying cost of the current API. Do we want to caveat that in the javadoc for this class? |
This is even more advanced that the Disruptor as you get direct access to the underlying buffer. Definitely an advanced feature only. |
From the wiki:
private static final UnsafeBuffer BUFFER = new UnsafeBuffer(ByteBuffer.allocateDirect(256));
...
final String message = "Hello World!";
BUFFER.putBytes(0, message.getBytes());
final boolean result = publication.offer(BUFFER, 0, message.getBytes().length);
Here one is allocating a buffer, and then the publication is presumably appending the bytes to the log buffer. From the StrangeLoop presentation it seemed like one would move the tail of the log buffer with a LOCK XADD and scribble their data straight onto the log buffer.
The text was updated successfully, but these errors were encountered: