Created
October 26, 2019 03:05
-
-
Save greenlaw110/beb59ec832744b1be970afdccdef23a6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) throws Exception { | |
long ts = $.ms(); | |
final OkHttpClient http = new OkHttpClient.Builder().build(); | |
final AtomicInteger backlog = new AtomicInteger(100000); | |
final AtomicInteger exceptions = new AtomicInteger(0); | |
ExecutorService exec = Executors.newFixedThreadPool(100); | |
for (int i = 0; i < 150; ++i) { | |
exec.submit(new Runnable() { | |
@Override | |
public void run() { | |
while (backlog.decrementAndGet() > 0) { | |
Request request = new Request.Builder().url("http://localhost:8080/x").get().build(); | |
try { | |
Response resp = http.newCall(request).execute(); | |
//resp.close(); | |
} catch (Exception e) { | |
exceptions.incrementAndGet(); | |
} | |
} | |
} | |
}); | |
} | |
exec.shutdown(); | |
if (!exec.awaitTermination(1000, TimeUnit.SECONDS)) { | |
System.out.println("execution service timeout"); | |
} | |
System.out.printf("exceptions: %s\n", exceptions.get()); | |
System.out.printf("It takes %sms to finish\n", $.ms() - ts); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment