2929 */
3030public class NatsAutoBench {
3131 static final String usageString =
32- "\n Usage: java NatsAutoBench [server]"
33- + "\n \n Use tls:// or opentls:// to require tls, via the Default SSLContext\n " ;
32+ "\n Usage: java NatsAutoBench [serverURL] [help] [utf8] [tiny|small|med]"
33+ + "\n \n Use tls:// or opentls:// to require tls, via the Default SSLContext\n "
34+ + "\n \n tiny, 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 ;
0 commit comments