clebertsuconic commented on a change in pull request #2666: ARTEMIS-2336 Use
zero copy to replicate journal/page/large message file
URL: https://github.com/apache/activemq-artemis/pull/2666#discussion_r283505141
##########
File path:
artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnection.java
##########
@@ -345,21 +351,41 @@ private boolean canWrite(final int requiredCapacity) {
return canWrite;
}
+ private Object getFileObject(FileDelegatedChannelBufferWrapper fileBuffer) {
+ if (channel.pipeline().get(SslHandler.class) == null) {
+ return new DefaultFileRegion(fileBuffer.getFile(),
fileBuffer.getOffset(), fileBuffer.getDataSize());
+ } else {
+ try {
+ RandomAccessFile raf = new RandomAccessFile(fileBuffer.getFile(),
"r");
+ return new ChunkedFile(raf, fileBuffer.getOffset(),
fileBuffer.getDataSize(), 8192);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
@Override
public final void write(ActiveMQBuffer buffer,
final boolean flush,
final boolean batched,
final ChannelFutureListener futureListener) {
- final int readableBytes = buffer.readableBytes();
+ //no need to lock because the Netty's channel is thread-safe
+ //and the order of write is ensured by the order of the write calls
+ final Channel channel = this.channel;
+
+ int readableBytes = buffer.readableBytes();
+ Object fileObject = null;
+ if (buffer instanceof FileDelegatedChannelBufferWrapper) {
+ readableBytes +=
((FileDelegatedChannelBufferWrapper)buffer).getDataSize();
+ fileObject = getFileObject((FileDelegatedChannelBufferWrapper)buffer);
Review comment:
I would rather create a new method to be called from
ReplicationManager.sendLargeFile instead of adding an instanceof here.
That is the caller should decide the semantic here, and a proper method to
be created.
I would really try to avoid breaking encapsulation here. Not much for a
nit-pick, but because this is hot code, meaning everything goes through here. I
would rather create a new method for the optimization than to make everything
else go through this for an exceptional case.
a question I have is: Was this really an issue for you during a production
env? this was using a PooledBuffer, and it was only happening during catch up
or large message transfer.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services