Skip to content

Commit f2804ab

Browse files
author
Simon MacMullen
committed
Allow fractional message rates (useful for testing massive fanout).
1 parent d70ad19 commit f2804ab

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static void main(String[] args) {
4949
String exchangeName = strArg(cmd, 'e', exchangeType);
5050
String queueName = strArg(cmd, 'u', "");
5151
int samplingInterval = intArg(cmd, 'i', 1);
52-
int rateLimit = intArg(cmd, 'r', 0);
52+
float rateLimit = floatArg(cmd, 'r', 0.0f);
5353
int producerCount = intArg(cmd, 'x', 1);
5454
int consumerCount = intArg(cmd, 'y', 1);
5555
int producerTxSize = intArg(cmd, 'm', 0);
@@ -161,6 +161,10 @@ private static int intArg(CommandLine cmd, char opt, int def) {
161161
return Integer.parseInt(cmd.getOptionValue(opt, Integer.toString(def)));
162162
}
163163

164+
private static float floatArg(CommandLine cmd, char opt, float def) {
165+
return Float.parseFloat(cmd.getOptionValue(opt, Float.toString(def)));
166+
}
167+
164168
private static List<?> lstArg(CommandLine cmd, char opt) {
165169
String[] vals = cmd.getOptionValues('f');
166170
if (vals == null) {

test/src/com/rabbitmq/examples/perf/MulticastParams.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class MulticastParams {
3232
private int minMsgSize = 0;
3333

3434
private int timeLimit = 0;
35-
private int rateLimit = 0;
35+
private float rateLimit = 0;
3636
private int producerMsgCount = 0;
3737
private int consumerMsgCount = 0;
3838

@@ -59,7 +59,7 @@ public void setQueueName(String queueName) {
5959
this.queueName = queueName;
6060
}
6161

62-
public void setRateLimit(int rateLimit) {
62+
public void setRateLimit(float rateLimit) {
6363
this.rateLimit = rateLimit;
6464
}
6565

test/src/com/rabbitmq/examples/perf/Producer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class Producer implements Runnable, ReturnListener,
4141
private boolean immediate;
4242
private boolean persistent;
4343
private int txSize;
44-
private int rateLimit;
44+
private float rateLimit;
4545
private int msgLimit;
4646
private long timeLimit;
4747

@@ -59,7 +59,7 @@ public class Producer implements Runnable, ReturnListener,
5959

6060
public Producer(Channel channel, String exchangeName, String id,
6161
List<?> flags, int txSize,
62-
int rateLimit, int msgLimit, int minMsgSize, int timeLimit,
62+
float rateLimit, int msgLimit, int minMsgSize, int timeLimit,
6363
long confirm, Stats stats)
6464
throws IOException {
6565

@@ -172,8 +172,8 @@ private void delay(long now)
172172
//10 ms have elapsed, we have sent 200 messages
173173
//the 200 msgs we have actually sent should have taken us
174174
//200 * 1000 / 5000 = 40 ms. So we pause for 40ms - 10ms
175-
long pause = rateLimit == 0 ?
176-
0 : (msgCount * 1000L / rateLimit - elapsed);
175+
long pause = (long) (rateLimit == 0.0f ?
176+
0.0f : (msgCount * 1000.0 / rateLimit - elapsed));
177177
if (pause > 0) {
178178
Thread.sleep(pause);
179179
}

0 commit comments

Comments
 (0)