summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--same-android/AndroidManifest.xml1
-rw-r--r--same-android/src/main/java/com/orbekk/same/android/MainActivity.java4
-rw-r--r--same-android/src/main/java/com/orbekk/same/android/benchmark/ExampleHttpServerActivity.java30
-rw-r--r--same/src/main/java/com/orbekk/same/benchmark/HttpClientBenchmark.java82
-rw-r--r--same/src/main/java/com/orbekk/same/benchmark/HttpExampleServer.java29
-rw-r--r--same/src/main/java/com/orbekk/same/benchmark/HttpExampleService.java5
6 files changed, 150 insertions, 1 deletions
diff --git a/same-android/AndroidManifest.xml b/same-android/AndroidManifest.xml
index 9fdeebd..d51c4e2 100644
--- a/same-android/AndroidManifest.xml
+++ b/same-android/AndroidManifest.xml
@@ -24,6 +24,7 @@
<activity android:name=".GraphicsActivity"/>
<activity android:name="com.orbekk.same.android.benchmark.RepeatedSetVariableActivity"/>
<activity android:name="com.orbekk.same.android.benchmark.ExampleProtobufServerActivity"/>
+ <activity android:name="com.orbekk.same.android.benchmark.ExampleHttpServerActivity"/>
<service android:name=".SameService" android:process="com.orbekk.same.android.SameService"/>
</application>
diff --git a/same-android/src/main/java/com/orbekk/same/android/MainActivity.java b/same-android/src/main/java/com/orbekk/same/android/MainActivity.java
index 4714b37..17b0ff0 100644
--- a/same-android/src/main/java/com/orbekk/same/android/MainActivity.java
+++ b/same-android/src/main/java/com/orbekk/same/android/MainActivity.java
@@ -16,7 +16,7 @@ import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
-import com.orbekk.same.android.R;
+import com.orbekk.same.android.benchmark.ExampleHttpServerActivity;
import com.orbekk.same.android.benchmark.ExampleProtobufServerActivity;
import com.orbekk.same.android.benchmark.RepeatedSetVariableActivity;
@@ -33,6 +33,8 @@ public class MainActivity extends Activity {
activities.put("Benchmark", RepeatedSetVariableActivity.class);
activities.put("ExampleProtobufServer (temp)",
ExampleProtobufServerActivity.class);
+ activities.put("ExampleHttpServer (temp)",
+ ExampleHttpServerActivity.class);
}
public final static List<String> activityList =
diff --git a/same-android/src/main/java/com/orbekk/same/android/benchmark/ExampleHttpServerActivity.java b/same-android/src/main/java/com/orbekk/same/android/benchmark/ExampleHttpServerActivity.java
new file mode 100644
index 0000000..695988d
--- /dev/null
+++ b/same-android/src/main/java/com/orbekk/same/android/benchmark/ExampleHttpServerActivity.java
@@ -0,0 +1,30 @@
+package com.orbekk.same.android.benchmark;
+
+import android.app.Activity;
+
+import com.orbekk.same.benchmark.ExampleServer;
+import com.orbekk.same.benchmark.HttpExampleServer;
+
+public class ExampleHttpServerActivity extends Activity {
+ public final HttpExampleServer server = new HttpExampleServer();
+
+ @Override public void onResume() {
+ super.onResume();
+ try {
+ server.runServer(12000);
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override public void onStop() {
+ super.onStop();
+ try {
+ server.stopServer();
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ }
+ }
+}
diff --git a/same/src/main/java/com/orbekk/same/benchmark/HttpClientBenchmark.java b/same/src/main/java/com/orbekk/same/benchmark/HttpClientBenchmark.java
new file mode 100644
index 0000000..fc315c4
--- /dev/null
+++ b/same/src/main/java/com/orbekk/same/benchmark/HttpClientBenchmark.java
@@ -0,0 +1,82 @@
+package com.orbekk.same.benchmark;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.concurrent.CountDownLatch;
+
+import com.google.protobuf.RpcCallback;
+import com.googlecode.jsonrpc4j.ProxyUtil;
+import com.orbekk.net.MyJsonRpcHttpClient;
+import com.orbekk.protobuf.Rpc;
+import com.orbekk.protobuf.RpcChannel;
+import com.orbekk.same.benchmark.Example.Data;
+
+public class HttpClientBenchmark {
+ private final HttpExampleService service;
+ private final int warmupIterations;
+ private final int iterations;
+
+ public static void benchmark(String url, int warmupIterations,
+ int iterations) throws InterruptedException {
+ MyJsonRpcHttpClient client;
+ try {
+ client = new MyJsonRpcHttpClient(
+ new URL(url), 2000, 2000);
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ }
+ HttpExampleService service = ProxyUtil.createProxy(
+ HttpClientBenchmark.class.getClassLoader(),
+ HttpExampleService.class,
+ client);
+ HttpClientBenchmark benchmark = new HttpClientBenchmark(
+ service, warmupIterations, iterations);
+ benchmark.benchmark();
+ }
+
+ public HttpClientBenchmark(HttpExampleService service,
+ int warmupIterations, int iterations) {
+ this.service = service;
+ this.warmupIterations = warmupIterations;
+ this.iterations = iterations;
+ }
+
+ private void runBenchmark(int iterations) throws InterruptedException {
+ final CountDownLatch finished =
+ new CountDownLatch(iterations);
+
+ for (int i = 0; i < iterations; i++) {
+ service.methodA("", iterations, 0);
+ finished.countDown();
+ }
+
+ finished.await();
+ }
+
+ public void benchmark() throws InterruptedException {
+ long warmupStart = System.currentTimeMillis();
+ runBenchmark(warmupIterations);
+ long warmupFinished = System.currentTimeMillis();
+ System.out.println("Warmup: " + warmupIterations + " in " +
+ (warmupFinished - warmupStart) + "ms. ");
+ long start = System.currentTimeMillis();
+ runBenchmark(iterations);
+ long finished = System.currentTimeMillis();
+ System.out.println("Benchmark: " + iterations+ " in " +
+ (finished - start) + "ms. ");
+ }
+
+ public static void main(String[] args) {
+ if (args.length < 1) {
+ System.err.println("Usage: ClientBenchmark <url>");
+ System.exit(1);
+ }
+ String url = args[0];
+ try {
+ benchmark(url, 1000, 10000);
+ } catch (InterruptedException e) {
+ System.out.println("Benchmark failed.");
+ }
+ }
+}
diff --git a/same/src/main/java/com/orbekk/same/benchmark/HttpExampleServer.java b/same/src/main/java/com/orbekk/same/benchmark/HttpExampleServer.java
new file mode 100644
index 0000000..f694680
--- /dev/null
+++ b/same/src/main/java/com/orbekk/same/benchmark/HttpExampleServer.java
@@ -0,0 +1,29 @@
+package com.orbekk.same.benchmark;
+
+import java.util.logging.Logger;
+
+import com.orbekk.same.http.JettyServerBuilder;
+import com.orbekk.same.http.JettyServerContainer;
+
+public class HttpExampleServer {
+ private final static Logger logger =
+ Logger.getLogger(HttpExampleServer.class.getName());
+ private volatile JettyServerContainer server;
+
+ class ServiceImpl implements HttpExampleService {
+ @Override public String methodA(String message, int arg1, int arg2) {
+ return message + arg1 + arg2;
+ }
+ }
+
+ public void runServer(int port) throws Exception {
+ server = new JettyServerBuilder(port)
+ .withService(new ServiceImpl(), HttpExampleService.class)
+ .build();
+ server.start();
+ }
+
+ public void stopServer() throws Exception {
+ server.stop();
+ }
+}
diff --git a/same/src/main/java/com/orbekk/same/benchmark/HttpExampleService.java b/same/src/main/java/com/orbekk/same/benchmark/HttpExampleService.java
new file mode 100644
index 0000000..ee8cbf5
--- /dev/null
+++ b/same/src/main/java/com/orbekk/same/benchmark/HttpExampleService.java
@@ -0,0 +1,5 @@
+package com.orbekk.same.benchmark;
+
+public interface HttpExampleService {
+ String methodA(String message, int arg1, int arg2);
+}