Skip to content

Commit f3915e7

Browse files
author
David R. MacIver
committed
increase the default socket buffer size to a minimum value
1 parent 108ef52 commit f3915e7

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/com/rabbitmq/client/ConnectionFactory.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
*/
5353

5454
public class ConnectionFactory {
55+
public static final int DEFAULT_SOCKET_BUFFER_SIZE = 10 * 1024;
56+
5557
private final ConnectionParameters _params;
5658

5759
/**
@@ -167,15 +169,26 @@ protected FrameHandler createFrameHandler(Address addr)
167169
* to connect to an AMQP server before they connect.
168170
*
169171
* The default behaviour of this method is to disable Nagle's algorithm to get
170-
* more consistently low latency.
172+
* more consistently low latency and set the buffer size to a reasonable figure
173+
* that seems to work well as a performance / size trade of.
171174
* However it may be overridden freely and there is no requirement to retain
172175
* this behaviour.
173176
*
174177
* @param socket The socket that is to be used for the Connection
175178
*/
176179
protected void configureSocket(Socket socket) throws IOException{
177-
//disable Nagle's algorithm, for more consistently low latency
180+
// disable Nagle's algorithm, for more consistently low latency
178181
socket.setTcpNoDelay(true);
182+
183+
// disabling Nagle's algorithm seems to come at a significant performance cost
184+
// at small buffer sizes. Empirically, buffer sizes of 10K seem to be enough to
185+
// equalise the throughput for local traffic. This needs more investigation at to
186+
// how it behaves over a network.
187+
188+
if(socket.getSendBufferSize() < DEFAULT_SOCKET_BUFFER_SIZE)
189+
socket.setSendBufferSize(DEFAULT_SOCKET_BUFFER_SIZE);
190+
if(socket.getReceiveBufferSize() < DEFAULT_SOCKET_BUFFER_SIZE)
191+
socket.setReceiveBufferSize(DEFAULT_SOCKET_BUFFER_SIZE);
179192
}
180193

181194
private Connection newConnection(Address[] addrs,

0 commit comments

Comments
 (0)