Skip to content

Commit c57c0ee

Browse files
author
David R. MacIver
committed
change BrokerPerformanceTest to use consume rather than get
1 parent 27f35c4 commit c57c0ee

File tree

2 files changed

+10
-36
lines changed

2 files changed

+10
-36
lines changed

src/com/rabbitmq/client/ConnectionFactory.java

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,6 @@
5252
*/
5353

5454
public class ConnectionFactory {
55-
// We explicitly set some minimum buffer sizes for consistent reasonable behaviour
56-
// These will only be applied if that platform's default is not larger than this.
57-
58-
// Due to our disabling of Nagle's algorithm, small buffers can very easily result in us
59-
// sending a very large number of buffer sized packets. When we write messages faster than
60-
// we can send them across the network, this quickly becomes a performance bottleneck.
61-
// Empirically, the throughput for with and without Nagle's seems to equalise around a
62-
// send buffer size of 8-10k for local messages. We need to do more benchmarking to verify
63-
// whether there's a better choice of default number for typical ethernet setups.
64-
public static final int DEFAULT_SOCKET_SEND_BUFFER_SIZE = 10 * 1024;
65-
66-
public static final int DEFAULT_SOCKET_RECEIVE_BUFFER_SIZE = 50 * 1024;
67-
6855
private final ConnectionParameters _params;
6956

7057
/**
@@ -180,8 +167,7 @@ protected FrameHandler createFrameHandler(Address addr)
180167
* to connect to an AMQP server before they connect.
181168
*
182169
* The default behaviour of this method is to disable Nagle's algorithm to get
183-
* more consistently low latency and set the buffer size to a reasonable figure
184-
* that seems to work well as a performance / size trade of.
170+
* more consistently low latency.
185171
* However it may be overridden freely and there is no requirement to retain
186172
* this behaviour.
187173
*
@@ -190,16 +176,6 @@ protected FrameHandler createFrameHandler(Address addr)
190176
protected void configureSocket(Socket socket) throws IOException{
191177
// disable Nagle's algorithm, for more consistently low latency
192178
socket.setTcpNoDelay(true);
193-
194-
// disabling Nagle's algorithm seems to come at a significant performance cost
195-
// at small buffer sizes. Empirically, buffer sizes of 10K seem to be enough to
196-
// equalise the throughput for local traffic. This needs more investigation at to
197-
// how it behaves over a network.
198-
199-
if(socket.getSendBufferSize() < DEFAULT_SOCKET_SEND_BUFFER_SIZE)
200-
socket.setSendBufferSize(DEFAULT_SOCKET_SEND_BUFFER_SIZE);
201-
if(socket.getReceiveBufferSize() < DEFAULT_SOCKET_RECEIVE_BUFFER_SIZE)
202-
socket.setReceiveBufferSize(DEFAULT_SOCKET_RECEIVE_BUFFER_SIZE);
203179
}
204180

205181
private Connection newConnection(Address[] addrs,

test/src/com/rabbitmq/examples/BufferPerformanceMetrics.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,13 @@
55
import com.rabbitmq.client.Channel;
66
import com.rabbitmq.client.GetResponse;
77
import com.rabbitmq.client.MessageProperties;
8-
import java.util.Arrays;
8+
import com.rabbitmq.client.Consumer;
9+
import com.rabbitmq.client.QueueingConsumer;
10+
911
import java.net.Socket;
1012
import java.io.IOException;
1113
import java.util.Random;
1214

13-
import org.apache.commons.cli.CommandLine;
14-
import org.apache.commons.cli.CommandLineParser;
15-
import org.apache.commons.cli.GnuParser;
16-
import org.apache.commons.cli.HelpFormatter;
17-
import org.apache.commons.cli.Option;
18-
import org.apache.commons.cli.Options;
19-
import org.apache.commons.cli.ParseException;
2015

2116
/**
2217
* Class to explore how performance of sending and receiving messages varies with the buffer size and
@@ -67,14 +62,17 @@ public static void main(String[] args) throws Exception{
6762

6863
start = System.nanoTime();
6964
for(int i = 0; i < MESSAGE_COUNT; i++){
70-
channel.basicPublish(EXCHANGE, QUEUE, MessageProperties.BASIC, MESSAGE);
65+
channel.basicPublish(EXCHANGE, ROUTING_KEY, MessageProperties.BASIC, MESSAGE);
7166
}
7267
long publishTime = System.nanoTime() - start;
7368

7469
start = System.nanoTime();
70+
71+
QueueingConsumer consumer = new QueueingConsumer(channel);
72+
channel.basicConsume(QUEUE, true, consumer);
73+
7574
for(int i = 0; i < MESSAGE_COUNT; i++){
76-
GetResponse response = channel.basicGet(QUEUE, true);
77-
assert(Arrays.equals(MESSAGE, response.getBody()));
75+
consumer.nextDelivery();
7876
}
7977
long getTime = System.nanoTime() - start;
8078

0 commit comments

Comments
 (0)