Skip to content

Commit ced0af2

Browse files
authored
Merge pull request #185 from nats-io/v2.1.2
V2.1.2
2 parents 061d76b + 98a8928 commit ced0af2

23 files changed

Lines changed: 307 additions & 156 deletions

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ sudo: required
44
jdk:
55
- oraclejdk8
66
- oraclejdk9
7-
- oraclejdk10
87
- openjdk8
98
- openjdk9
109
- openjdk10

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11

22
# Change Log
33

4+
## Version 2.1.2
5+
6+
* [FIXED] #181 - issue with default pending limits on consumers not matching doc
7+
* [FIXED] #179 - added version variable for jars in build.gradle to make it easier to change
8+
* [ADDED] Support for UTF8 subjects
9+
410
## Version 2.1.1
511

612
* [FIXED] Issue with version in Nats.java, also updated deploying.md with checklist

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ Version 2.1 uses a simplified versioning scheme. Any issues will be fixed in the
2020

2121
Previous versions are still available in the repo.
2222

23+
### UTF-8 Subjects
24+
25+
The client protocol spec doesn't explicitly state the encoding on subjects. Some clients use ASCII and some use UTF-8 which matches ASCII for a-Z and 0-9. Until 2.1.2 the 2.0+ version of the Java client used ASCII for performance reasons. As of 2.1.2 you can choose to support UTF-8 subjects via the Options. Keep in mind that there is a small performance penalty for UTF-8 encoding and decoding in benchmarks, but depending on your application this cost may be negligible. Also, keep in mind that not all clients support UTF-8 and test accordingly.
26+
2327
## Installation
2428

2529
The java-nats client is provided in a single jar file, with no external dependencies. See [Building From Source](#building-from-source) for details on building the library.

build.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ plugins {
1313
// Update version here, repeated check-ins not into master will have snapshot on them
1414
def versionMajor = 2
1515
def versionMinor = 1
16-
def versionPatch = 1
16+
def versionPatch = 2
1717
def versionModifier = ""
18+
def jarVersion = "2.1.2"
1819
def branch = System.getenv("TRAVIS_BRANCH");
1920

2021
def getVersionName = { ->
@@ -70,7 +71,7 @@ osgiClasses {
7071
jar {
7172
manifest {
7273
attributes('Implementation-Title': 'Java Nats',
73-
'Implementation-Version': '2.1.1',
74+
'Implementation-Version': jarVersion,
7475
'Implementation-Vendor': 'nats.io')
7576
}
7677
exclude("io/nats/examples/**")
@@ -112,7 +113,7 @@ task examplesJar(type: Jar) {
112113
classifier = 'examples'
113114
manifest {
114115
attributes('Implementation-Title': 'Java Nats Examples',
115-
'Implementation-Version': '2.1.1',
116+
'Implementation-Version': jarVersion,
116117
'Implementation-Vendor': 'nats.io')
117118
}
118119
from(sourceSets.main.output) {

src/examples/java/io/nats/examples/autobench/LatencyBenchmark.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ public void execute(Options connectOptions) throws InterruptedException {
5858
}
5959
try {
6060
Subscription sub = subConnect.subscribe(subject);
61-
subConnect.flush(Duration.ZERO);
61+
subConnect.flush(Duration.ofSeconds(5));
6262
subReady.complete(null);
6363
go.get();
6464

6565
int count = 0;
6666
while(count < this.getMessageCount()) {
67-
Message msg = sub.nextMessage(Duration.ZERO);
67+
Message msg = sub.nextMessage(Duration.ofSeconds(5));
6868

6969
if (msg != null){
7070
measurements.add(System.nanoTime() - start.get());

src/examples/java/io/nats/examples/autobench/NatsAutoBench.java

Lines changed: 89 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -29,33 +29,56 @@
2929
*/
3030
public class NatsAutoBench {
3131
static final String usageString =
32-
"\nUsage: java NatsAutoBench [server]"
33-
+ "\n\nUse tls:// or opentls:// to require tls, via the Default SSLContext\n";
32+
"\nUsage: java NatsAutoBench [serverURL] [help] [utf8] [tiny|small|med]"
33+
+ "\n\nUse tls:// or opentls:// to require tls, via the Default SSLContext\n"
34+
+ "\n\ntiny, small and med reduce the number of messages used for tests, which can help on slower machines\n";
3435

3536
public static void main(String args[]) {
36-
String server;
37-
38-
if (args.length == 1) {
39-
server = args[0];
40-
} else if (args.length == 0) {
41-
server = Options.DEFAULT_URL;
42-
} else {
43-
usage();
44-
return;
37+
String server = Options.DEFAULT_URL;
38+
boolean utf8 = false;
39+
int baseMsgs = 100_000;
40+
int latencyMsgs = 5_000;
41+
42+
if (args.length > 0) {
43+
for (String s : args) {
44+
if (s.equals("utf8")) {
45+
utf8 = true;
46+
}else if (s.equals("med")) {
47+
baseMsgs = 50_000;
48+
latencyMsgs = 2_500;
49+
} else if (s.equals("small")) {
50+
baseMsgs = 5_000;
51+
latencyMsgs = 250;
52+
} else if (s.equals("tiny")) {
53+
baseMsgs = 1_000;
54+
latencyMsgs = 50;
55+
} else if (s.equals("nano")) {
56+
baseMsgs = 10;
57+
latencyMsgs = 5;
58+
} else if (s.equals("help")) {
59+
usage();
60+
return;
61+
} else {
62+
server = s;
63+
}
64+
}
4565
}
4666

47-
if ("help".equals(server)) {
48-
usage();
49-
}
67+
System.out.printf("Connecting to gnatsd at %s\n", server);
5068

5169
try {
52-
Options connectOptions = new Options.Builder().
53-
server(server).
54-
connectionTimeout(Duration.ofMillis(1000)).
55-
noReconnect().
56-
build();
57-
58-
List<AutoBenchmark> tests = buildTestList();
70+
Options.Builder builder = new Options.Builder().
71+
server(server).
72+
connectionTimeout(Duration.ofSeconds(1)).
73+
noReconnect();
74+
75+
if (utf8) {
76+
System.out.printf("Enabling UTF-8 subjects\n");
77+
builder.supportUTF8Subjects();
78+
}
79+
80+
Options connectOptions = builder.build();
81+
List<AutoBenchmark> tests = buildTestList(baseMsgs, latencyMsgs);
5982

6083
System.out.println("Running warmup");
6184
runWarmup(connectOptions);
@@ -72,7 +95,7 @@ public static void main(String args[]) {
7295
// Ask for GC and wait a moment between tests
7396
System.gc();
7497
try {
75-
Thread.sleep(100);
98+
Thread.sleep(500);
7699
} catch (Exception exp) {
77100
// ignore
78101
}
@@ -111,57 +134,56 @@ public static void runWarmup(Options connectOptions) throws Exception {
111134
}
112135
}
113136

114-
public static List<AutoBenchmark> buildTestList() {
137+
public static List<AutoBenchmark> buildTestList(int baseMsgs, int latencyMsgs) {
115138
ArrayList<AutoBenchmark> tests = new ArrayList<>();
116139

117140
/**/
118-
tests.add(new PubBenchmark("PubOnly 0b", 10_000_000, 0));
119-
tests.add(new PubBenchmark("PubOnly 8b", 10_000_000, 8));
120-
tests.add(new PubBenchmark("PubOnly 32b", 10_000_000, 32));
121-
tests.add(new PubBenchmark("PubOnly 256b", 10_000_000, 256));
122-
tests.add(new PubBenchmark("PubOnly 512b", 10_000_000, 512));
123-
tests.add(new PubBenchmark("PubOnly 1k", 1_000_000, 1024));
124-
tests.add(new PubBenchmark("PubOnly 4k", 500_000, 4*1024));
125-
tests.add(new PubBenchmark("PubOnly 8k", 100_000, 8*1024));
126-
127-
tests.add(new PubSubBenchmark("PubSub 0b", 10_000_000, 0));
128-
tests.add(new PubSubBenchmark("PubSub 8b", 10_000_000, 8));
129-
tests.add(new PubSubBenchmark("PubSub 32b", 10_000_000, 32));
130-
tests.add(new PubSubBenchmark("PubSub 256b", 10_000_000, 256));
131-
tests.add(new PubSubBenchmark("PubSub 512b", 5_000_000, 512));
132-
tests.add(new PubSubBenchmark("PubSub 1k", 1_000_000, 1024));
133-
tests.add(new PubSubBenchmark("PubSub 4k", 100_000, 4*1024));
134-
tests.add(new PubSubBenchmark("PubSub 8k", 100_000, 8*1024));
141+
tests.add(new PubBenchmark("PubOnly 0b", 100 * baseMsgs, 0));
142+
tests.add(new PubBenchmark("PubOnly 8b", 100 * baseMsgs, 8));
143+
tests.add(new PubBenchmark("PubOnly 32b", 100 * baseMsgs, 32));
144+
tests.add(new PubBenchmark("PubOnly 256b", 100 * baseMsgs, 256));
145+
tests.add(new PubBenchmark("PubOnly 512b", 100 * baseMsgs, 512));
146+
tests.add(new PubBenchmark("PubOnly 1k", 10 * baseMsgs, 1024));
147+
tests.add(new PubBenchmark("PubOnly 4k", 5 * baseMsgs, 4*1024));
148+
tests.add(new PubBenchmark("PubOnly 8k", baseMsgs, 8*1024));
149+
150+
tests.add(new PubSubBenchmark("PubSub 0b", 100 * baseMsgs, 0));
151+
tests.add(new PubSubBenchmark("PubSub 8b", 100 * baseMsgs, 8));
152+
tests.add(new PubSubBenchmark("PubSub 32b", 100 * baseMsgs, 32));
153+
tests.add(new PubSubBenchmark("PubSub 256b", 100 * baseMsgs, 256));
154+
tests.add(new PubSubBenchmark("PubSub 512b", 50 * baseMsgs, 512));
155+
tests.add(new PubSubBenchmark("PubSub 1k", 10 * baseMsgs, 1024));
156+
tests.add(new PubSubBenchmark("PubSub 4k", baseMsgs, 4*1024));
157+
tests.add(new PubSubBenchmark("PubSub 8k", baseMsgs, 8*1024));
158+
159+
tests.add(new PubDispatchBenchmark("PubDispatch 0b", 100 * baseMsgs, 0));
160+
tests.add(new PubDispatchBenchmark("PubDispatch 8b", 100 * baseMsgs, 8));
161+
tests.add(new PubDispatchBenchmark("PubDispatch 32b", 100 * baseMsgs, 32));
162+
tests.add(new PubDispatchBenchmark("PubDispatch 256b", 100 * baseMsgs, 256));
163+
tests.add(new PubDispatchBenchmark("PubDispatch 512b", 50 * baseMsgs, 512));
164+
tests.add(new PubDispatchBenchmark("PubDispatch 1k", 10 * baseMsgs, 1024));
165+
tests.add(new PubDispatchBenchmark("PubDispatch 4k", baseMsgs, 4*1024));
166+
tests.add(new PubDispatchBenchmark("PubDispatch 8k", baseMsgs, 8*1024));
135167

136-
tests.add(new PubDispatchBenchmark("PubDispatch 0b", 10_000_000, 0));
137-
tests.add(new PubDispatchBenchmark("PubDispatch 8b", 10_000_000, 8));
138-
tests.add(new PubDispatchBenchmark("PubDispatch 32b", 10_000_000, 32));
139-
tests.add(new PubDispatchBenchmark("PubDispatch 256b", 10_000_000, 256));
140-
tests.add(new PubDispatchBenchmark("PubDispatch 512b", 5_000_000, 512));
141-
tests.add(new PubDispatchBenchmark("PubDispatch 1k", 1_000_000, 1024));
142-
tests.add(new PubDispatchBenchmark("PubDispatch 4k", 100_000, 4*1024));
143-
tests.add(new PubDispatchBenchmark("PubDispatch 8k", 100_000, 8*1024));
144-
145168
// Request reply is a 4 message trip, and runs the full loop before sending another message
146169
// so we run fewer because the client cannot batch any socket calls to the server together
147-
tests.add(new ReqReplyBenchmark("ReqReply 0b", 20_000, 0));
148-
tests.add(new ReqReplyBenchmark("ReqReply 8b", 20_000, 8));
149-
tests.add(new ReqReplyBenchmark("ReqReply 32b", 10_000, 32));
150-
tests.add(new ReqReplyBenchmark("ReqReply 256b", 10_000, 256));
151-
tests.add(new ReqReplyBenchmark("ReqReply 512b", 10_000, 512));
152-
tests.add(new ReqReplyBenchmark("ReqReply 1k", 10_000, 1024));
153-
tests.add(new ReqReplyBenchmark("ReqReply 4k", 10_000, 4*1024));
154-
tests.add(new ReqReplyBenchmark("ReqReply 8k", 10_000, 8*1024));
155-
156-
int latencyTests = 5_000;
157-
tests.add(new LatencyBenchmark("Latency 0b", latencyTests, 0));
158-
tests.add(new LatencyBenchmark("Latency 8b", latencyTests, 8));
159-
tests.add(new LatencyBenchmark("Latency 32b", latencyTests, 32));
160-
tests.add(new LatencyBenchmark("Latency 256b", latencyTests, 256));
161-
tests.add(new LatencyBenchmark("Latency 512b", latencyTests, 512));
162-
tests.add(new LatencyBenchmark("Latency 1k", latencyTests, 1024));
163-
tests.add(new LatencyBenchmark("Latency 4k", latencyTests, 4 * 1024));
164-
tests.add(new LatencyBenchmark("Latency 8k", latencyTests, 8 * 1024));
170+
tests.add(new ReqReplyBenchmark("ReqReply 0b", baseMsgs / 5, 0));
171+
tests.add(new ReqReplyBenchmark("ReqReply 8b", baseMsgs / 5, 8));
172+
tests.add(new ReqReplyBenchmark("ReqReply 32b", baseMsgs / 10, 32));
173+
tests.add(new ReqReplyBenchmark("ReqReply 256b", baseMsgs / 10, 256));
174+
tests.add(new ReqReplyBenchmark("ReqReply 512b", baseMsgs / 10, 512));
175+
tests.add(new ReqReplyBenchmark("ReqReply 1k", baseMsgs / 10, 1024));
176+
tests.add(new ReqReplyBenchmark("ReqReply 4k", baseMsgs / 10, 4*1024));
177+
tests.add(new ReqReplyBenchmark("ReqReply 8k", baseMsgs / 10, 8*1024));
178+
179+
tests.add(new LatencyBenchmark("Latency 0b", latencyMsgs, 0));
180+
tests.add(new LatencyBenchmark("Latency 8b", latencyMsgs, 8));
181+
tests.add(new LatencyBenchmark("Latency 32b", latencyMsgs, 32));
182+
tests.add(new LatencyBenchmark("Latency 256b", latencyMsgs, 256));
183+
tests.add(new LatencyBenchmark("Latency 512b", latencyMsgs, 512));
184+
tests.add(new LatencyBenchmark("Latency 1k", latencyMsgs, 1024));
185+
tests.add(new LatencyBenchmark("Latency 4k", latencyMsgs, 4 * 1024));
186+
tests.add(new LatencyBenchmark("Latency 8k", latencyMsgs, 8 * 1024));
165187
/**/
166188

167189
return tests;

src/examples/java/io/nats/examples/autobench/PubBenchmark.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void execute(Options connectOptions) throws InterruptedException {
3737
for(int i = 0; i < this.getMessageCount(); i++) {
3838
nc.publish(subject, payload);
3939
}
40-
try {nc.flush(Duration.ZERO);}catch(Exception e){}
40+
try {nc.flush(Duration.ofSeconds(5));}catch(Exception e){}
4141
this.endTiming();
4242
} finally {
4343
nc.close();

src/examples/java/io/nats/examples/autobench/PubDispatchBenchmark.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void executeWithLimiter(Options connectOptions) throws InterruptedException {
5656
}
5757
});
5858
d.subscribe(subject);
59-
subConnect.flush(Duration.ZERO);
59+
subConnect.flush(Duration.ofSeconds(5));
6060
subReady.complete(null);
6161

6262
// For simplicity the test doesn't have a connection listener so just loop
@@ -103,7 +103,7 @@ void executeWithLimiter(Options connectOptions) throws InterruptedException {
103103
pubConnect.publish(subject, payload);
104104
this.adjustAndSleep(pubConnect);
105105
}
106-
try {pubConnect.flush(Duration.ZERO);}catch(Exception e){}
106+
try {pubConnect.flush(Duration.ofSeconds(5));}catch(Exception e){}
107107

108108
pubDone.complete(null);
109109
} finally {

src/examples/java/io/nats/examples/autobench/PubSubBenchmark.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,16 @@ void executeWithLimiter(Options connectOptions) throws InterruptedException {
4848
}
4949
try {
5050
Subscription sub = subConnect.subscribe(subject);
51-
subConnect.flush(Duration.ZERO);
51+
subConnect.flush(Duration.ofSeconds(5));
5252
subReady.complete(null);
5353

5454
while(count < this.getMessageCount()) {
55-
Message msg = sub.nextMessage(Duration.ZERO);
55+
Message msg = sub.nextMessage(Duration.ofSeconds(5));
5656

5757
if (msg != null){
5858
count++;
59+
} else {
60+
throw new Exception("No messages within timeout.");
5961
}
6062
}
6163

@@ -88,7 +90,7 @@ void executeWithLimiter(Options connectOptions) throws InterruptedException {
8890
pubConnect.publish(subject, payload);
8991
adjustAndSleep(pubConnect);
9092
}
91-
try {pubConnect.flush(Duration.ZERO);}catch(Exception e){}
93+
try {pubConnect.flush(Duration.ofSeconds(5));}catch(Exception e){}
9294

9395
pubDone.complete(null);
9496
} finally {

src/examples/java/io/nats/examples/autobench/ReqReplyBenchmark.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,20 @@ public void execute(Options connectOptions) throws InterruptedException {
4747
}
4848
try {
4949
Subscription sub = replyConnect.subscribe(subject);
50-
replyConnect.flush(Duration.ZERO);
50+
replyConnect.flush(Duration.ofSeconds(5));
5151
replyReady.complete(null);
5252

5353
int count = 0;
5454
while(count < this.getMessageCount()) {
55-
Message msg = sub.nextMessage(Duration.ZERO);
55+
Message msg = sub.nextMessage(Duration.ofSeconds(5));
5656

5757
if (msg != null){
5858
replyConnect.publish(msg.getReplyTo(), payload);
5959
count++;
6060
}
6161
}
6262
replyDone.complete(null);
63-
replyConnect.flush(Duration.ZERO);
63+
replyConnect.flush(Duration.ofSeconds(5));
6464

6565
} catch (Exception exp) {
6666
this.setException(exp);

0 commit comments

Comments
 (0)