@@ -48,6 +48,7 @@ public class Http2StreamManagerCanary {
4848 private int maxStreams = 100 ;
4949 private int maxConnections = 50 ;
5050 private int batchNum ;
51+ private String nettyResultPath ;
5152
5253 private Http2StreamManager createStreamManager (URI uri , int numConnections ) {
5354
@@ -65,7 +66,7 @@ private Http2StreamManager createStreamManager(URI uri, int numConnections) {
6566 .withSocketOptions (sockOpts )
6667 .withUri (uri )
6768 .withMaxConnections (numConnections );
68- if (useTls ) {
69+ if (useTls ) {
6970 connectionManagerOptions .withTlsContext (tlsContext );
7071 } else {
7172 options .withPriorKnowledge (true );
@@ -165,7 +166,7 @@ public void onResponseComplete(HttpStreamBase stream, int errorCode) {
165166
166167 opts .incrementAndGet ();
167168 int requestCompletedNum = requestCompleted .incrementAndGet ();
168- if (requestCompletedNum == concurrentNum ) {
169+ if (requestCompletedNum == concurrentNum ) {
169170 requestCompleteFuture .complete (null );
170171 }
171172 }
@@ -180,34 +181,53 @@ private void runCanary(int warmupLoops, int loops, long timerSecs) throws Except
180181 ArrayList <Double > warmupResults = new ArrayList <>();
181182 ArrayList <Double > results = new ArrayList <>();
182183 AtomicInteger streamFailed = new AtomicInteger (0 );
183- // Log.initLoggingToFile(Log.LogLevel.Error, "errorlog.txt");
184184
185- System .out .println ("batchNum: " + this .batchNum );
186- System .out .println ("maxStreams: " + this .maxStreams );
187- System .out .println ("maxConnections: " + this .maxConnections );
185+ System .out .println ("batchNum: " + this .batchNum );
186+ System .out .println ("maxStreams: " + this .maxStreams );
187+ System .out .println ("maxConnections: " + this .maxConnections );
188188 try (Http2StreamManager streamManager = createStreamManager (uri , this .maxConnections )) {
189189 AtomicInteger opts = new AtomicInteger (0 );
190190 AtomicBoolean done = new AtomicBoolean (false );
191- ScheduledExecutorService scheduler = createDataCollector (warmupLoops , loops , timerSecs , opts , done , warmupResults , results );
191+ ScheduledExecutorService scheduler = createDataCollector (warmupLoops , loops , timerSecs , opts , done ,
192+ warmupResults , results );
192193 concurrentRequests (streamManager , batchNum , streamFailed , opts , done );
193194 scheduler .shutdown ();
194195 }
195196 System .out .println ("Failed request num: " + streamFailed .get ());
196197 System .out .println ("////////////// warmup results //////////////" );
197198 printResult (warmupResults );
198199 System .out .println ("////////////// real results //////////////" );
199- printResult (results );
200+ double avg_result = printResult (results );
201+ BufferedReader reader = new BufferedReader (new FileReader (nettyResultPath ));
202+ StringBuilder stringBuilder = new StringBuilder ();
203+ String line = null ;
204+ while ((line = reader .readLine ()) != null ) {
205+ stringBuilder .append (line );
206+ }
207+ reader .close ();
208+ stringBuilder .deleteCharAt (stringBuilder .length () - 1 );
209+ String content = stringBuilder .toString ();
210+ double netty_result = Double .parseDouble (content );
211+ if (avg_result < netty_result ) {
212+ System .out .println ("CRT result is smaller than netty. CRT: " + avg_result + " Netty: " + netty_result );
213+ System .exit (-1 );
214+ }
215+
200216 CrtResource .logNativeResources ();
201217 CrtResource .waitForNoResources ();
218+
202219 }
203220
204221 public static void main (String [] args ) throws Exception {
205222 System .out .println ("Current JVM version - " + System .getProperty ("java.version" ));
206- /* TODO: make all those number configurable */
223+
207224 Http2StreamManagerCanary canary = new Http2StreamManagerCanary ();
208- canary .uri = new URI ("https://localhost:8443/echo" );
209- canary .maxConnections = 8 ;
210- canary .maxStreams = 20 ;
225+
226+ canary .uri = new URI (System .getProperty ("aws.crt.http.canary.uri" , "https://localhost:8443/echo" ));
227+ canary .maxConnections = Integer .parseInt (System .getProperty ("aws.crt.http.canary.maxConnections" , "8" ));
228+ canary .maxStreams = Integer .parseInt (System .getProperty ("aws.crt.http.canary.maxStreams" , "20" ));
229+ canary .nettyResultPath = System .getProperty ("aws.crt.http.canary.nettyResultPath" , "netty_result.txt" );
230+
211231 canary .batchNum = canary .maxStreams * canary .maxConnections ;
212232 canary .runCanary (5 , 5 , 30 );
213233 }
0 commit comments