Skip to content

Instantly share code, notes, and snippets.

@rpgreen
Last active December 10, 2018 19:33
Show Gist options
  • Save rpgreen/c08c255f2c546387b5b5 to your computer and use it in GitHub Desktop.
Save rpgreen/c08c255f2c546387b5b5 to your computer and use it in GitHub Desktop.

Revisions

  1. rpgreen revised this gist Feb 10, 2016. 1 changed file with 2 additions and 4 deletions.
    6 changes: 2 additions & 4 deletions Latency.java
    Original file line number Diff line number Diff line change
    @@ -9,12 +9,10 @@ public void testPerf() throws IOException {

    for (int i = 0; i < numRequests; i++) {

    final Stopwatch sw = Stopwatch.createStarted();
    long start = System.currentTimeMillis();
    final CloseableHttpResponse resp = client.execute(request);
    resp.close();
    sw.stop();

    long millis = sw.elapsed(TimeUnit.MILLISECONDS);
    long millis = System.currentTimeMillis() - start;

    if (millis > 800) {
    LOG.warn(String.format("Request took %dms" + ", request ID: %s, CF request ID: %s", millis,
  2. rpgreen revised this gist Feb 10, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Latency.java
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    @Test
    public void testPerf() throws IOException {
    final HttpGet request = new HttpGet("https://[API-ID]].execute-api.[REGION].amazonaws.com/[STAGE]/[PATH]");
    final HttpGet request = new HttpGet("https://[API-ID].execute-api.[REGION].amazonaws.com/[STAGE]/[PATH]");
    final int numRequests = 10000;
    final int[] histogram = new int[100];
    final List<Integer> latencies = new ArrayList<>();
  3. rpgreen revised this gist Feb 10, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Latency.java
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    @Test
    public void testPerf() throws IOException {
    final HttpGet request = new HttpGet("https://11ro68yamg.execute-api.us-east-1.amazonaws.com/prod/lambda");
    final HttpGet request = new HttpGet("https://[API-ID]].execute-api.[REGION].amazonaws.com/[STAGE]/[PATH]");
    final int numRequests = 10000;
    final int[] histogram = new int[100];
    final List<Integer> latencies = new ArrayList<>();
  4. rpgreen revised this gist Feb 10, 2016. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion Latency.java
    Original file line number Diff line number Diff line change
    @@ -36,4 +36,5 @@ public void testPerf() throws IOException {
    LOG.info(String.format("Distribution: "));
    for (int i = 0; i < histogram.length; i++) {
    LOG.info(i*100 + "ms - " + (i+1)*100 + "ms: " + histogram[i]);
    }
    }
    }
  5. rpgreen revised this gist Feb 10, 2016. 1 changed file with 30 additions and 30 deletions.
    60 changes: 30 additions & 30 deletions Latency.java
    Original file line number Diff line number Diff line change
    @@ -1,39 +1,39 @@
    @Test
    public void testPerf() throws IOException {
    final HttpGet request = new HttpGet("https://11ro68yamg.execute-api.us-east-1.amazonaws.com/prod/lambda");
    final int numRequests = 10000;
    final int[] histogram = new int[100];
    final List<Integer> latencies = new ArrayList<>();
    @Test
    public void testPerf() throws IOException {
    final HttpGet request = new HttpGet("https://11ro68yamg.execute-api.us-east-1.amazonaws.com/prod/lambda");
    final int numRequests = 10000;
    final int[] histogram = new int[100];
    final List<Integer> latencies = new ArrayList<>();

    final CloseableHttpClient client = HttpClients.createDefault();
    final CloseableHttpClient client = HttpClients.createDefault();

    for (int i = 0; i < numRequests; i++) {
    for (int i = 0; i < numRequests; i++) {

    final Stopwatch sw = Stopwatch.createStarted();
    final CloseableHttpResponse resp = client.execute(request);
    resp.close();
    sw.stop();
    final Stopwatch sw = Stopwatch.createStarted();
    final CloseableHttpResponse resp = client.execute(request);
    resp.close();
    sw.stop();

    long millis = sw.elapsed(TimeUnit.MILLISECONDS);
    long millis = sw.elapsed(TimeUnit.MILLISECONDS);

    if (millis > 800) {
    LOG.warn(String.format("Request took %dms" + ", request ID: %s, CF request ID: %s", millis,
    resp.getFirstHeader("X-Amzn-Requestid"), resp.getFirstHeader("X-Amz-Cf-Id")));
    }

    histogram[((int) (millis / 100))]++;
    latencies.add((int) millis);
    if (millis > 800) {
    LOG.warn(String.format("Request took %dms" + ", request ID: %s, CF request ID: %s", millis,
    resp.getFirstHeader("X-Amzn-Requestid"), resp.getFirstHeader("X-Amz-Cf-Id")));
    }

    Collections.sort(latencies);
    histogram[((int) (millis / 100))]++;
    latencies.add((int) millis);
    }

    Collections.sort(latencies);

    final int p50 = latencies.get((50 * (numRequests) / 100) - 1);
    final int p90 = latencies.get((90 * (numRequests) / 100) - 1);
    final int p99 = latencies.get((99 * (numRequests) / 100) - 1);
    final int p100 = latencies.get((100 * (numRequests) / 100) - 1);
    final int p50 = latencies.get((50 * (numRequests) / 100) - 1);
    final int p90 = latencies.get((90 * (numRequests) / 100) - 1);
    final int p99 = latencies.get((99 * (numRequests) / 100) - 1);
    final int p100 = latencies.get((100 * (numRequests) / 100) - 1);

    LOG.info(String.format("Num requests: %d P50: %dms P90: %dms P99: %dms P100: %dms", numRequests, p50, p90, p99, p100));
    LOG.info(String.format("Distribution: "));
    for (int i = 0; i < histogram.length; i++) {
    LOG.info(i*100 + "ms - " + (i+1)*100 + "ms: " + histogram[i]);
    }
    LOG.info(String.format("Num requests: %d P50: %dms P90: %dms P99: %dms P100: %dms", numRequests, p50, p90, p99, p100));
    LOG.info(String.format("Distribution: "));
    for (int i = 0; i < histogram.length; i++) {
    LOG.info(i*100 + "ms - " + (i+1)*100 + "ms: " + histogram[i]);
    }
  6. rpgreen revised this gist Feb 10, 2016. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions Latency.java
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    @Test
    public void testPerf() throws IOException {
    final HttpGet request = new HttpGet("https://11ro68yamg.execute-api.us-east-1.amazonaws.com/prod/lambda");
    final int numRequests = 10000;
    final int[] histogram = new int[100];
  7. rpgreen revised this gist Feb 10, 2016. 1 changed file with 6 additions and 15 deletions.
    21 changes: 6 additions & 15 deletions Latency.java
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,5 @@
    @Test
    public void testPerf() throws IOException {

    final HttpGet request = new HttpGet("https://11ro68yamg.execute-api.us-east-1.amazonaws.com/prod/lambda");

    final int numRequests = 10000;
    long totalLatency = 0;
    final int[] histogram = new int[100];
    final List<Integer> latencies = new ArrayList<>();

    @@ -18,7 +13,6 @@ public void testPerf() throws IOException {
    sw.stop();

    long millis = sw.elapsed(TimeUnit.MILLISECONDS);
    totalLatency += millis;

    if (millis > 800) {
    LOG.warn(String.format("Request took %dms" + ", request ID: %s, CF request ID: %s", millis,
    @@ -31,16 +25,13 @@ public void testPerf() throws IOException {

    Collections.sort(latencies);

    final Integer p50 = latencies.get((50 * (numRequests) / 100) - 1);
    final Integer p90 = latencies.get((90 * (numRequests) / 100) - 1);
    final Integer p99 = latencies.get((99 * (numRequests) / 100) - 1);
    final Integer p100 = latencies.get((100 * (numRequests) / 100) - 1);

    LOG.info(String.format("Num requests: %d Avg latency: %fms", numRequests, totalLatency / (double) numRequests));
    LOG.info(String.format("P50: %dms P90: %dms P99: %dms P100: %dms", p50, p90, p99, p100));
    final int p50 = latencies.get((50 * (numRequests) / 100) - 1);
    final int p90 = latencies.get((90 * (numRequests) / 100) - 1);
    final int p99 = latencies.get((99 * (numRequests) / 100) - 1);
    final int p100 = latencies.get((100 * (numRequests) / 100) - 1);

    LOG.info(String.format("Num requests: %d P50: %dms P90: %dms P99: %dms P100: %dms", numRequests, p50, p90, p99, p100));
    LOG.info(String.format("Distribution: "));
    for (int i = 0; i < histogram.length; i++) {
    LOG.info(i*100 + "ms - " + (i+1)*100 + "ms: " + histogram[i]);
    }
    }
    }
  8. rpgreen revised this gist Feb 10, 2016. No changes.
  9. rpgreen revised this gist Feb 10, 2016. 1 changed file with 9 additions and 8 deletions.
    17 changes: 9 additions & 8 deletions Latency.java
    Original file line number Diff line number Diff line change
    @@ -1,27 +1,28 @@
    @Test
    public void testPerf() throws IOException {

    // final HttpGet request = new HttpGet("http://petstore-demo-endpoint.execute-api.com/petstore/pets");
    // final HttpGet request = new HttpGet("http://11ro68yamg.execute-api.us-east-1.amazonaws.com/petstore/pets"); //cf->petstore
    final HttpGet request = new HttpGet("https://11ro68yamg.execute-api.us-east-1.amazonaws.com/prod");
    final int numRequests = 10000;
    final HttpGet request = new HttpGet("https://11ro68yamg.execute-api.us-east-1.amazonaws.com/prod/lambda");

    final int numRequests = 10000;
    long totalLatency = 0;
    final int[] histogram = new int[100];
    final List<Integer> latencies = new ArrayList<>();

    for (int i = 0; i < numRequests; i++) {
    final CloseableHttpClient client = HttpClients.createDefault();

    final CloseableHttpClient client = HttpClients.createDefault();
    for (int i = 0; i < numRequests; i++) {

    final Stopwatch sw = Stopwatch.createStarted();
    final CloseableHttpResponse resp = client.execute(request);
    resp.close();
    sw.stop();

    long millis = sw.elapsed(TimeUnit.MILLISECONDS);
    totalLatency += millis;

    if (millis > 600) {
    LOG.warn(String.format("Request took %dms" + ", request ID: %s", millis, resp.getFirstHeader("X-Amzn-Requestid")));
    if (millis > 800) {
    LOG.warn(String.format("Request took %dms" + ", request ID: %s, CF request ID: %s", millis,
    resp.getFirstHeader("X-Amzn-Requestid"), resp.getFirstHeader("X-Amz-Cf-Id")));
    }

    histogram[((int) (millis / 100))]++;
  10. rpgreen created this gist Jan 26, 2016.
    45 changes: 45 additions & 0 deletions Latency.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    public void testPerf() throws IOException {

    // final HttpGet request = new HttpGet("http://petstore-demo-endpoint.execute-api.com/petstore/pets");
    // final HttpGet request = new HttpGet("http://11ro68yamg.execute-api.us-east-1.amazonaws.com/petstore/pets"); //cf->petstore
    final HttpGet request = new HttpGet("https://11ro68yamg.execute-api.us-east-1.amazonaws.com/prod");
    final int numRequests = 10000;

    long totalLatency = 0;
    final int[] histogram = new int[100];
    final List<Integer> latencies = new ArrayList<>();

    for (int i = 0; i < numRequests; i++) {

    final CloseableHttpClient client = HttpClients.createDefault();

    final Stopwatch sw = Stopwatch.createStarted();
    final CloseableHttpResponse resp = client.execute(request);
    sw.stop();

    long millis = sw.elapsed(TimeUnit.MILLISECONDS);
    totalLatency += millis;

    if (millis > 600) {
    LOG.warn(String.format("Request took %dms" + ", request ID: %s", millis, resp.getFirstHeader("X-Amzn-Requestid")));
    }

    histogram[((int) (millis / 100))]++;
    latencies.add((int) millis);
    }

    Collections.sort(latencies);

    final Integer p50 = latencies.get((50 * (numRequests) / 100) - 1);
    final Integer p90 = latencies.get((90 * (numRequests) / 100) - 1);
    final Integer p99 = latencies.get((99 * (numRequests) / 100) - 1);
    final Integer p100 = latencies.get((100 * (numRequests) / 100) - 1);

    LOG.info(String.format("Num requests: %d Avg latency: %fms", numRequests, totalLatency / (double) numRequests));
    LOG.info(String.format("P50: %dms P90: %dms P99: %dms P100: %dms", p50, p90, p99, p100));

    LOG.info(String.format("Distribution: "));
    for (int i = 0; i < histogram.length; i++) {
    LOG.info(i*100 + "ms - " + (i+1)*100 + "ms: " + histogram[i]);
    }
    }