Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Http Client benchmark #527

Open
wants to merge 42 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
a81617e
http client canary
TingDaoK Aug 24, 2022
9dbebd5
add mvn exec
TingDaoK Aug 24, 2022
d9ad783
use per sec
TingDaoK Aug 24, 2022
facd3f6
make it more clear
TingDaoK Aug 24, 2022
3806aa6
fix build
TingDaoK Aug 24, 2022
cffc9f1
Merge branch 'main' into http-canary
TingDaoK Aug 25, 2022
6d6c628
add netty client
TingDaoK Aug 29, 2022
fe083a8
let's try to run it from CI for now
TingDaoK Aug 29, 2022
7f8eecb
oh my
TingDaoK Aug 29, 2022
f51b463
install first?
TingDaoK Aug 29, 2022
892c64b
do we change dir succeed?
TingDaoK Aug 29, 2022
ed7d1d7
Revert "do we change dir succeed?"
TingDaoK Aug 29, 2022
c30a8f8
check it out
TingDaoK Aug 29, 2022
1a1be3f
what about this?
TingDaoK Aug 29, 2022
b74df4e
Revert "what about this?"
TingDaoK Aug 29, 2022
4115ede
again
TingDaoK Aug 29, 2022
075fd22
nice
TingDaoK Aug 29, 2022
8205aba
now it should work
TingDaoK Aug 29, 2022
949c7e0
revert the ignore of the other tests
TingDaoK Aug 29, 2022
38aa46c
trivial updates
TingDaoK Aug 30, 2022
88ea9d0
Merge branch 'main' into http-canary
TingDaoK Aug 30, 2022
9c60a0e
override on stream?
TingDaoK Aug 30, 2022
87b79a7
consume the body
TingDaoK Aug 30, 2022
ce3edc9
remove the content length
TingDaoK Aug 30, 2022
de08df7
use 30s gap
TingDaoK Aug 31, 2022
285c6d7
support non-tls uri
TingDaoK Sep 8, 2022
45df768
use local server without body
TingDaoK Sep 8, 2022
f941879
non tls test
TingDaoK Sep 8, 2022
79adafd
Revert "non tls test"
TingDaoK Sep 8, 2022
4fcb93e
back to the server with body
TingDaoK Sep 8, 2022
a269139
send byte[] across jni
TingDaoK Sep 8, 2022
47ed94c
update register type
TingDaoK Sep 8, 2022
57ffd07
disable log
TingDaoK Sep 9, 2022
4e7c9f1
make each connection 40 concurrent streams and 800 batch
TingDaoK Sep 9, 2022
f00e981
make sure the connections and streams are equal
TingDaoK Sep 10, 2022
3e46f98
clean up a bit
TingDaoK Sep 12, 2022
f9813b6
typo
TingDaoK Sep 12, 2022
699d702
use the new branch of http
TingDaoK Sep 12, 2022
db37f9a
update the branch
TingDaoK Sep 13, 2022
623e167
make sure we error out when CRT result is smaller than netty
TingDaoK Sep 13, 2022
b357a9d
Merge branch 'main' into http-canary
TingDaoK Sep 23, 2022
2fe9be5
Merge branch 'main' into http-canary
TingDaoK Sep 26, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .builder/actions/localhost_canary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Builder
import sys
import os


class LocalhostCanary(Builder.Action):

def run(self, env):
env.shell.setenv('AWS_CRT_MEMORY_TRACING', '2')
actions = [
"mvn install -DskipTests",
"cd ./samples/HttpClientCanary && mvn install",
"cd ./samples/HttpClientCanary && mvn exec:exec@netty",
"cd ./samples/HttpClientCanary && mvn exec:exec@crt"
]

return Builder.Script(actions, name='aws-crt-java-test')
55 changes: 55 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,58 @@ jobs:
Start-Process -NoNewWindow python .\non_tls_server.py
python -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder.pyz')"
python builder.pyz localhost-test -p ${{ env.PACKAGE_NAME }} downstream

localhost-canary-linux:
runs-on: ubuntu-20.04 # latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
- name: Configure local host
run: |
python3 -m pip install h2
cd crt/aws-c-http/tests/py_localhost/
python3 server.py &
python3 non_tls_server.py &
- name: Build and test
run: |
python3 -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder.pyz')"
python builder.pyz localhost-canary -p ${{ env.PACKAGE_NAME }} --spec=downstream

localhost-canary-mac:
runs-on: macos-11 # latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
- name: Configure local host
run: |
python3 -m pip install h2
cd crt/aws-c-http/tests/py_localhost/
python3 server.py &
python3 non_tls_server.py &
- name: Build and test
run: |
python3 -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder')"
chmod a+x builder
./builder localhost-canary -p ${{ env.PACKAGE_NAME }} --spec=downstream

localhost-canary-win:
runs-on: windows-2022 # latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
- name: Configure local host
run: |
python -m pip install h2
- name: Build and test
run: |
cd crt/aws-c-http/tests/py_localhost/
Start-Process -NoNewWindow python .\server.py
Start-Process -NoNewWindow python .\non_tls_server.py
python -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder.pyz')"
python builder.pyz localhost-canary -p ${{ env.PACKAGE_NAME }} downstream
72 changes: 72 additions & 0 deletions samples/HttpClientCanary/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.canary</groupId>
<artifactId>canary</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>software.amazon.awssdk.crt</groupId>
<artifactId>aws-crt</artifactId>
<version>1.0.0-SNAPSHOT</version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This version doesn't work for me on an M1. I get the following error

java.io.IOException: Unable to open library in jar for AWS CRT: /osx/x86_64/libaws-crt-jni.dylib
        at software.amazon.awssdk.crt.CRT.extractAndLoadLibrary(CRT.java:190)
        at software.amazon.awssdk.crt.CRT.loadLibraryFromJar(CRT.java:242)
        at software.amazon.awssdk.crt.CRT.<clinit>(CRT.java:34)
        at software.amazon.awssdk.crt.CrtResource.<clinit>(CrtResource.java:104)
        at com.canary.Http2StreamManagerCanary.createStreamManager(Http2StreamManagerCanary.java:51)
        at com.canary.Http2StreamManagerCanary.runCanary(Http2StreamManagerCanary.java:174)
        at com.canary.Http2StreamManagerCanary.main(Http2StreamManagerCanary.java:195)
Exception in thread "main" java.lang.ExceptionInInitializerError
        at software.amazon.awssdk.crt.CrtResource.<clinit>(CrtResource.java:104)
        at com.canary.Http2StreamManagerCanary.createStreamManager(Http2StreamManagerCanary.java:51)
        at com.canary.Http2StreamManagerCanary.runCanary(Http2StreamManagerCanary.java:174)
        at com.canary.Http2StreamManagerCanary.main(Http2StreamManagerCanary.java:195)
Caused by: software.amazon.awssdk.crt.CrtRuntimeException: software.amazon.awssdk.crt.CrtRuntimeException: Unable to unpack AWS CRT library UNKNOWN(-1) UNKNOWN(-1)
        at software.amazon.awssdk.crt.CRT.loadLibraryFromJar(CRT.java:252)
        at software.amazon.awssdk.crt.CRT.<clinit>(CRT.java:34)
        ... 4 more

I changed it to 0.19.3 and it is working now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, you need mvn install on the root directory first.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, that seems like weird...
It's search for x86_64 on your arm machine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What JAVA_HOME you set? Do you have a x86 java on you machine?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My Java Home is /Users/waqarak/Library/Java/JavaVirtualMachines/corretto-11.0.16/Contents/Home. I did run mvn install on the root directory.

</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>netty-nio-client</artifactId>
<version>2.17.261</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.reactivex.rxjava2</groupId>
<artifactId>rxjava</artifactId>
<version>2.2.21</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<!-- Need to use exec not java see:http://mail.openjdk.java.net/pipermail/jmh-dev/2014-July/001192.html, https://stackoverflow.com/questions/15013651/using-maven-execexec-with-arguments -->
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>netty</id>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>com.canary.SDKNettyClientCanary</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>crt</id>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>com.canary.Http2StreamManagerCanary</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
66 changes: 66 additions & 0 deletions samples/HttpClientCanary/src/main/java/com/canary/CanaryUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/

package com.canary;

import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.ArrayList;

public class CanaryUtils {
private static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(10);
private static final AtomicInteger numDataCollected = new AtomicInteger(0);

public static ScheduledExecutorService createDataCollector(int warmupLoops, int loops, long timerSecs,
AtomicInteger opts, AtomicBoolean done,
ArrayList<Double> warmupResults, ArrayList<Double> results) {
ScheduledFuture<?> task = scheduler.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
int numCollected = numDataCollected.incrementAndGet();
int collectedOpts = opts.getAndSet(0);
double result = (double)collectedOpts/(double)timerSecs;
if (numCollected <= warmupLoops) {
System.out.println("warm up: " + result);
warmupResults.add(result);
return;
}
if (numCollected > loops + warmupLoops) {
done.set(true);
return;
}
System.out.println("result: " + result);
results.add(result);
}
}, timerSecs, timerSecs, TimeUnit.SECONDS);
return scheduler;
}

public static double calculateAverage(ArrayList<Double> list) {
return list.stream().mapToDouble(d -> d).average().orElse(0.0);
}

public static double calculateSTD(ArrayList<Double> list) {
double avg = calculateAverage(list);

double variance = 0;
for (int i = 0; i < list.size(); i++) {
variance += Math.pow(list.get(i) - avg, 2);
}
variance /= (list.size()-1);
return Math.sqrt(variance);
}

/* Return avg of the list and print out the avg and std */
public static double printResult(ArrayList<Double> list) {
double avg = calculateAverage(list);
double std = calculateSTD(list);
System.out.println("Result collected has: " + list.size());
System.out.println("avg of all samples: " + avg);
System.out.println("Standard deviation of all samples: " + std);
return avg;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.canary;

import java.nio.ByteBuffer;
import java.util.Optional;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;
import software.amazon.awssdk.http.async.SdkHttpContentPublisher;

public class EmptyPublisher implements SdkHttpContentPublisher {
@Override
public void subscribe(Subscriber<? super ByteBuffer> subscriber) {
subscriber.onSubscribe(new EmptySubscription(subscriber));
}

@Override
public Optional<Long> contentLength() {
return Optional.of(0L);
}

private static class EmptySubscription implements Subscription {
private final Subscriber subscriber;
private volatile boolean done;

EmptySubscription(Subscriber subscriber) {
this.subscriber = subscriber;
}

@Override
public void request(long l) {
if (!done) {
done = true;
if (l <= 0) {
this.subscriber.onError(new IllegalArgumentException("Demand must be positive"));
} else {
this.subscriber.onComplete();
}
}
}

@Override
public void cancel() {
done = true;
}
}
}
Loading