|
52 | 52 | */ |
53 | 53 |
|
54 | 54 | public class ConnectionFactory { |
| 55 | + public static final int DEFAULT_SOCKET_BUFFER_SIZE = 10 * 1024; |
| 56 | + |
55 | 57 | private final ConnectionParameters _params; |
56 | 58 |
|
57 | 59 | /** |
@@ -167,15 +169,26 @@ protected FrameHandler createFrameHandler(Address addr) |
167 | 169 | * to connect to an AMQP server before they connect. |
168 | 170 | * |
169 | 171 | * 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. |
171 | 174 | * However it may be overridden freely and there is no requirement to retain |
172 | 175 | * this behaviour. |
173 | 176 | * |
174 | 177 | * @param socket The socket that is to be used for the Connection |
175 | 178 | */ |
176 | 179 | 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 |
178 | 181 | 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); |
179 | 192 | } |
180 | 193 |
|
181 | 194 | private Connection newConnection(Address[] addrs, |
|
0 commit comments