From 3c950e49c4247840e88057074c3c5ecb1484706c Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Thu, 21 Jun 2012 19:04:49 -0400 Subject: [PATCH] INT-2635 Set Buffer Size for Piped Streams Backport to 2.1.x Improve performance. For NIO sockets, a pair of PipedInput/OutputStreams are used to transfer data from the reading thread to the assembling thread. The stream used the default buffer size (1024) which was inefficient for large messages. This change uses the underlying socket's receiveBufferSize attribute to set the size of the piped stream, allowing for more efficient data transfer. --- .../integration/ip/tcp/connection/TcpNioConnection.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioConnection.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioConnection.java index fe1b94ac6e..aadb3d0711 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioConnection.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioConnection.java @@ -74,7 +74,11 @@ public class TcpNioConnection extends AbstractTcpConnection { public TcpNioConnection(SocketChannel socketChannel, boolean server, boolean lookupHost) throws Exception { super(socketChannel.socket(), server, lookupHost); this.socketChannel = socketChannel; - this.pipedInputStream = new PipedInputStream(); + int receiveBufferSize = socketChannel.socket().getReceiveBufferSize(); + if (receiveBufferSize <= 0) { + receiveBufferSize = this.maxMessageSize; + } + this.pipedInputStream = new PipedInputStream(receiveBufferSize); this.pipedOutputStream = new PipedOutputStream(this.pipedInputStream); this.channelOutputStream = new ChannelOutputStream(); }