Skip to content

Commit

Permalink
mc bench changes (#553)
Browse files Browse the repository at this point in the history
  • Loading branch information
scottf committed Oct 28, 2021
1 parent bb8595c commit fa93ff7
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 18 deletions.
16 changes: 7 additions & 9 deletions src/examples/java/io/nats/examples/autobench/AutoBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@ public abstract class AutoBenchmark {
private final long messageSize;
private final long messageCount;
private final AtomicLong start;
private final Object[] customs;
private long runtimeNanos;
private Exception exception;

public AutoBenchmark(String name, long messageCount, long messageSize, Object... customs) {
public AutoBenchmark(String name, long messageCount, long messageSize) {
this.name = name;
this.messageCount = messageCount;
this.messageSize = messageSize;
this.customs = customs;
this.start = new AtomicLong();
}

Expand All @@ -45,11 +43,15 @@ public String getName() {
}

public String getSubject() {
return String.valueOf(getName().hashCode()%10000);
return generate("sub");
}

public String getStream() {
return String.valueOf(("stream" + getName()).hashCode()%10000);
return generate("stream");
}

private String generate(String prefix) {
return prefix + Long.toHexString(getName().hashCode()) + "-" + Long.toHexString(getMessageCount()) + "x" + Long.toHexString(getMessageSize());
}

public long getMessageSize() {
Expand All @@ -60,10 +62,6 @@ public long getMessageCount() {
return this.messageCount;
}

public Object[] getCustoms() {
return customs;
}

public byte[] createPayload() {
return new byte[(int)this.messageSize];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,19 @@

public class JsPubAsyncRoundsBenchmark extends AutoBenchmark {

private final boolean file;
private final long roundSize;

public JsPubAsyncRoundsBenchmark(String name, long messageCount, long messageSize, boolean file, long roundSize) {
super(name, messageCount, messageSize, file, roundSize);
super(name, messageCount, messageSize);
this.file = file;
this.roundSize = roundSize;
}

public void execute(Options connectOptions) throws InterruptedException {
byte[] payload = createPayload();
String subject = getSubject();
String stream = getStream();
boolean file = (boolean) getCustoms()[0];
long roundSize = (long) getCustoms()[1];

try {
Connection nc = Nats.connect(connectOptions);
Expand Down
12 changes: 8 additions & 4 deletions src/examples/java/io/nats/examples/autobench/JsPubBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,21 @@ public static String getSubject(long messageCount, long messageSize) {
return SAVED_SUBJECTS.get(getKey(messageCount, messageSize));
}

private final boolean file;
private final boolean sync;
private final boolean saveForSub;

public JsPubBenchmark(String name, long messageCount, long messageSize, boolean file, boolean sync, boolean saveForSub) {
super(name, messageCount, messageSize, file, sync, saveForSub);
super(name, messageCount, messageSize);
this.file = file;
this.sync = sync;
this.saveForSub = saveForSub;
}

public void execute(Options connectOptions) throws InterruptedException {
byte[] payload = createPayload();
String subject = getSubject();
String stream = getStream();
boolean file = (boolean) getCustoms()[0];
boolean sync = (boolean) getCustoms()[1];
boolean saveForSub = (boolean) getCustoms()[2];
if (saveForSub) {
String key = getKey(getMessageCount(), getMessageSize());
SAVED_STREAMS.put(key, stream);
Expand Down
2 changes: 1 addition & 1 deletion src/examples/java/io/nats/examples/jsmulti/Arguments.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public Arguments(String[] args) {
messageCount = asNumber(args, ++x, -1, "total messages");
break;
case "-ps":
payloadSize = asNumber(args, ++x, 8192, "payload size");
payloadSize = asNumber(args, ++x, 65536, "payload size");
break;
case "-bs":
batchSize = asNumber(args, ++x, 256, "batch size");
Expand Down
2 changes: 1 addition & 1 deletion src/examples/java/io/nats/examples/jsmulti/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ time spent in jitter is excluded from timings

### Publish Only Optional Arguments

`-ps` payload size (number) for publishing, defaults to 128, maximum 8192"
`-ps` payload size (number) for publishing, defaults to 128, maximum 65536"

`-rs` round size (number) for pubAsync, default to 100, maximum 1000.
Publishing asynchronously uses the "sawtooth" pattern. This means we publish a round of messages, collecting all the futures that receive the PublishAck
Expand Down

0 comments on commit fa93ff7

Please sign in to comment.