8000 Add test ID to PerfTest · ThinkLib/rabbitmq-java-client@f0173cb · GitHub
[go: up one dir, main page]

Skip to content

Commit f0173cb

Browse files
committed
Add test ID to PerfTest
Backport of rabbitmq#184 and rabbitmq#188
1 parent ace7126 commit f0173cb

File tree

2 files changed

+48
-34
lines changed

2 files changed

+48
-34
lines changed

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

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636

3737
public class PerfTest {
38-
38+
3939
public static void main(String[] args) {
4040
Options options = getOptions();
4141
CommandLineParser parser = new GnuParser();
@@ -47,7 +47,7 @@ public static void main(String[] args) {
4747
System.exit(0);
4848
}
4949
String testID = new SimpleDateFormat("HHmmss-SSS").format(Calendar.
50-
getInstance().getTime());
50+
getInstance().getTime());
5151
testID = strArg(cmd, 'd', "test-"+testID);
5252
String exchangeType = strArg(cmd, 't', "direct");
5353
String exchangeName = strArg(cmd, 'e', exchangeType);
@@ -79,1 10000 2 +79,12 @@ public static void main(String[] args) {
7979

8080
//setup
8181
PrintlnStats stats = new PrintlnStats(testID,
82-
1000L * samplingInterval,
83-
producerCount > 0,
84-
consumerCount > 0,
85-
(flags.contains("mandatory") ||
86-
flags.contains("immediate")),
87-
confirm != -1);
82+
1000L * samplingInterval,
83+
producerCount > 0,
84+
consumerCount > 0,
85+
(flags.contains("mandatory") ||
86+
flags.contains("immediate")),
87+
confirm != -1);
8888

8989
ConnectionFactory factory = new ConnectionFactory();
9090
factory.setShutdownTimeout(0); // So we still shut down even with slow consumers
@@ -118,7 +118,7 @@ public static void main(String[] args) {
118118
p.setProducerRateLimit(producerRateLimit);
119119
p.setTimeLimit( timeLimit);
120120

121-
MulticastSet set = new MulticastSet(stats, factory, p);
121+
MulticastSet set = new MulticastSet(stats, factory, p, testID);
122122
set.run(true);
123123

124124
stats.printFinal();
@@ -141,7 +141,7 @@ private static void usage(Options options) {
141141
private static Options getOptions() {
142142
Options options = new Options();
143143
options.addOption(new Option("?", "help", false,"show usage"));
144-
options.addOption(new Option("d", "id", true, "Test ID"));
144+
options.addOption(new Option("d", "id", true, "test ID"));
145145
options.addOption(new Option("h", "uri", true, "connection URI"));
146146
options.addOption(new Option("t", "type", true, "exchange type"));
147147
options.addOption(new Option("e", "exchange", true, "exchange name"));
@@ -198,12 +198,12 @@ private static class PrintlnStats extends Stats {
198198
private final boolean recvStatsEnabled;
199199
private final boolean returnStatsEnabled;
200200
private final boolean confirmStatsEnabled;
201-
201+
202202
private final String testID;
203203

204204
public PrintlnStats(String testID, long interval,
205-
boolean sendStatsEnabled, boolean recvStatsEnabled,
206-
boolean returnStatsEnabled, boolean confirmStatsEnabled) {
205+
boolean sendStatsEnabled, boolean recvStatsEnabled,
206+
boolean returnStatsEnabled, boolean confirmStatsEnabled) {
207207
super(interval);
208208
this.sendStatsEnabled = sendStatsEnabled;
209209
this.recvStatsEnabled = recvStatsEnabled;
@@ -215,27 +215,27 @@ public PrintlnStats(String testID, long interval,
215215
@Override
216216
protected void report(long now) {
217217
String output = "id: " + testID + ", ";
218-
218+
219219
output += "time: " + String.format("%.3f", (now - startTime)/1000.0) + "s";
220220
output +=
221-
getRate("sent", sendCountInterval, sendStatsEnabled, elapsedInterval) +
221+
getRate("sent", sendCountInterval, sendStatsEnabled, elapsedInterval) +
222222
getRate("returned", returnCountInterval, sendStatsEnabled && returnStatsEnabled, elapsedInterval) +
223223
getRate("confirmed", confirmCountInterval, sendStatsEnabled && confirmStatsEnabled, elapsedInterval) +
224224
getRate("nacked", nackCountInterval, sendStatsEnabled && confirmStatsEnabled, elapsedInterval) +
225225
getRate("received", recvCountInterval, recvStatsEnabled, elapsedInterval);
226226

227227
output += (latencyCountInterval > 0 ?
228-
", min/avg/max latency: " +
229-
minLatency/1000L + "/" +
230-
cumulativeLatencyInterval / (1000L * latencyCountInterval) + "/" +
231-
maxLatency/1000L + " microseconds" :
232-
"");
228+
", min/avg/max latency: " +
229+
minLatency/1000L + "/" +
230+
cumulativeLatencyInterval / (1000L * latencyCountInterval) + "/" +
231+
maxLatency/1000L + " microseconds" :
232+
"");
233233

234234
System.out.println(output);
235235
}
236236

237237
private String getRate(String descr, long count, boolean display,
238-
long elapsed) {
238+
long elapsed) {
239239
if (display)
240240
return ", " + descr + ": " + formatRate(1000.0 * count / elapsed) + " msg/s";
241241
else
@@ -245,15 +245,15 @@ private String getRate(String descr, long count, boolean display,
245245
public void printFinal() {
246246
long now = System.currentTimeMillis();
247247

248-
System.out.println("sending rate avg: " +
249-
formatRate(sendCountTotal * 1000.0 / (now - startTime)) +
250-
" msg/s");
248+
System.out.println("id: " + testID + ", sending rate avg: " +
249+
formatRate(sendCountTotal * 1000.0 / (now - startTime)) +
250+
" msg/s");
251251

252252
long elapsed = now - startTime;
253253
if (elapsed > 0) {
254-
System.out.println("recving rate avg: " +
255-
formatRate(recvCountTotal * 1000.0 / elapsed) +
256-
" msg/s");
254+
System.out.println("id: " + testID + ", recving rate avg: " +
255+
formatRate(recvCountTotal * 1000.0 / elapsed) +
256+
" msg/s");
257257
}
258258
}
259259

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

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,35 @@
1515

1616
package com.rabbitmq.examples.perf;
1717

18-
import com.rabbitmq.client.Channel;
19-
import com.rabbitmq.client.Connection;
20-
import com.rabbitmq.client.ConnectionFactory;
21-
2218
import java.io.IOException;
2319
import java.util.UUID;
2420
import java.util.concurrent.TimeoutException;
2521

22+
import com.rabbitmq.client.Connection;
23+
import com.rabbitmq.client.ConnectionFactory;
24+
2625
public class MulticastSet {
2726
private final String id;
2827
private final Stats stats;
2928
private final ConnectionFactory factory;
3029
private final MulticastParams params;
30+
private final String testID;
31+
32+
public MulticastSet(Stats stats, ConnectionFactory factory,
33+
MulticastParams params) {
34+
if (params.getRoutingKey() == null) {
35+
this.id = UUID.randomUUID().toString();
36+
} else {
37+
this.id = params.getRoutingKey();
38+
}
39+
this.stats = stats;
40+
this.factory = factory;
41+
this.params = params;
42+
this.testID = "perftest";
43+
}
3144

3245
public MulticastSet(Stats stats, ConnectionFactory factory,
33-
MulticastParams params) {
46+
MulticastParams params, String testID) {
3447
if (params.getRoutingKey() == null) {
3548
this.id = UUID.randomUUID().toString();
3649
} else {
@@ -39,6 +52,7 @@ public MulticastSet(Stats stats, ConnectionFactory factory,
3952
this.stats = stats;
4053
this.factory = factory;
4154
this.params = params;
55+
this.testID = testID;
4256
}
4357

4458
public void run() throws IOException, InterruptedException, TimeoutException {
@@ -50,7 +64,7 @@ public void run(boolean announceStartup) throws IOException, InterruptedExceptio
5064
Connection[] consumerConnections = new Connection[consumerThreads.length];
5165
for (int i = 0; i < consumerConnections.length; i++) {
5266
if (announceStartup) {
53-
System.out.println("starting consumer #" + i);
67+
System.out.println("id: " + testID + ", starting consumer #" + i);
5468
}
5569
Connection conn = factory.newConnection();
5670
consumerConnections[i] = conn;
@@ -68,7 +82,7 @@ public void run(boolean announceStartup) throws IOException, InterruptedExceptio
6882
Connection[] producerConnections = new Connection[producerThreads.length];
6983
for (int i = 0; i < producerThreads.length; i++) {
7084
if (announceStartup) {
71-
System.out.println("starting producer #" + i);
85+
System.out.println("id: " + testID + ", starting producer #" + i);
7286
}
7387
Connection conn = factory.newConnection();
7488
producerConnections[i] = conn;

0 commit comments

Comments
 (0)
0