Skip to content

Commit

Permalink
Migrate gRPC and HTTP JSON benchmarks into a single activity, now cal…
Browse files Browse the repository at this point in the history
…led RpcBenchmarksActivity. Started writeup
  • Loading branch information
david-cao committed Jul 14, 2016
1 parent 87d2bda commit ed31969
Show file tree
Hide file tree
Showing 18 changed files with 654 additions and 118 deletions.
39 changes: 39 additions & 0 deletions benchmark_results/CodedOutputStream.html
@@ -0,0 +1,39 @@
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script>
google.charts.load('current', {
'packages': ['corechart']
});
google.charts.setOnLoadCallback(drawChart);

function drawChart() {
var data = google.visualization.arrayToDataTable([
['Mbps', 'Message Size in bytes'],
[2.616953255, 25],
[4.277304791, 565],
[4.872934462, 700],
[5.925880617, 40996],
[6.273317282, 138086]
]);

var options = {
title: 'Results of Serializing to CodedOutputStream',
hAxis: {
title: 'Mbps',
minValue: 0,
maxValue: 5
},
vAxis: {
title: 'Message Size in bytes',
minValue: 0,
maxValue: 160000
},
legend: 'none'
};

var chart = new google.visualization.ScatterChart(document.getElementById('chart_div'));

chart.draw(data, options);
}

</script>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
Binary file added benchmark_results/latencies.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion gRPCBenchmarks/app/src/main/AndroidManifest.xml
Expand Up @@ -31,7 +31,8 @@
android:name=".JsonBenchmarkActivity"
android:label="@string/jsonBenchmarksName">
</activity>
<activity android:name=".RpcBenchmarksActivity">
<activity android:name=".RpcBenchmarksActivity"
android:label="@string/rpcBenchmarksName">
</activity>
</application>

Expand Down
Expand Up @@ -13,13 +13,13 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_home);
}

public void showRpcBenchmarks(View v) {
Intent intent = new Intent(this, RpcBenchmarksActivity.class);
public void showProtobufBenchmarks(View v) {
Intent intent = new Intent(this, ProtobufBenchmarksActivity.class);
startActivity(intent);
}

public void showJsonBenchmarks(View v) {
Intent intent = new Intent(this, JsonBenchmarkActivity.class);
public void showRpcBenchmarks(View v) {
Intent intent = new Intent(this, RpcBenchmarksActivity.class);
startActivity(intent);
}
}
Expand Up @@ -157,6 +157,7 @@ public void execute() throws JSONException, IOException {
gis.read(inputData);
gis.close();
bis.close();
String s = new String(inputData);
new JSONObject(new String(inputData));
}
});
Expand Down
Expand Up @@ -143,20 +143,18 @@ public void startBenchmark(CardView cv, Benchmark b) {
}
}

//BEGIN OnItemSelectedListener
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
// An item was selected. You can retrieve the selected item using
System.out.println("picked " + pos);
selected = pos;
// prevent gzip for small request, strange bug where GZIP fails to decompress correctly
if (selected == 0) {
mCheckBox.setChecked(false);
}
}

public void onNothingSelected(AdapterView<?> parent) {
// Another interface callback
}
public void onNothingSelected(AdapterView<?> parent) {}

private class BenchmarkAsyncTask extends AsyncTask<Integer, Integer, BenchmarkResult> {

CardView cv;
Benchmark b;

Expand All @@ -167,6 +165,11 @@ private class BenchmarkAsyncTask extends AsyncTask<Integer, Integer, BenchmarkRe

@Override
protected void onPreExecute() {
// prevent gzip for small request, strange bug where GZIP fails to decompress correctly
if (selected == 0) {
mCheckBox.setChecked(false);
}

useGzip = mCheckBox.isChecked();
tasksRunning++;
mBenchmarkButton.setEnabled(false);
Expand All @@ -182,7 +185,6 @@ protected BenchmarkResult doInBackground(Integer... inputs) {
MessageLite message;
String jsonString;
if (sharedMessage != null) {
System.out.println("Using shared message");
message = sharedMessage;
jsonString = sharedJson;
} else {
Expand Down
Expand Up @@ -36,26 +36,27 @@ public RpcBenchmark(String title, String description, int methodNumber) {
this.methodNumber = methodNumber;
}

public RpcBenchmarkResult run(String urlString, String numConnections) throws Exception {
public RpcBenchmarkResult run(boolean useOkHttp, String urlString, String numConnections,
String payloadString, String gzip) throws Exception {
switch (methodNumber) {
// TODO: Allow for customization!
case 0:
String addr = "--address=" + urlString + ":50052";
String[] args = {addr, "--channels=1", "--outstanding_rpcs=" + numConnections,
"--client_payload=100", "--server_payload=100"};
String address = "--address=" + urlString + ":50052";
String[] args = {address, "--channels=1", "--outstanding_rpcs=" + numConnections,
"--client_payload=1000", "--server_payload=1000"};
ClientConfiguration.Builder configBuilder = ClientConfiguration.newBuilder(
ADDRESS, CHANNELS, OUTSTANDING_RPCS, CLIENT_PAYLOAD, SERVER_PAYLOAD,
TLS, TESTCA, USE_DEFAULT_CIPHERS, TRANSPORT, DURATION, WARMUP_DURATION,
DIRECTEXECUTOR, SAVE_HISTOGRAM, STREAMING_RPCS);
ClientConfiguration config;
config = configBuilder.build(args);
ClientConfiguration config = configBuilder.build(args);
AsyncClient client = new AsyncClient(config);
return client.run();
case 1:
int outstandingConnections = Integer.parseInt(numConnections);
int payloadSize = Integer.parseInt(payloadString);
boolean useGzip = Boolean.parseBoolean(gzip);
AsyncJsonClient jsonClient = new AsyncJsonClient(new URL("http://" + urlString +
":4567/postPayload"), outstandingConnections);
return jsonClient.run();
":4567/postPayload"), outstandingConnections, payloadSize, useGzip);
return useOkHttp ? jsonClient.runOkHttp(): jsonClient.run();
default:
throw new IllegalArgumentException("Invalid method number/tag was" +
" used for RpcBenchmark!");
Expand Down
@@ -1,7 +1,5 @@
package io.grpc.grpcbenchmarks;

import java.util.concurrent.TimeUnit;

/**
* Created by davidcao on 6/20/16.
*/
Expand Down Expand Up @@ -51,17 +49,17 @@ public String toString() {
.append("99.9%ile Latency (in micros): ").append(latency999).append('\n')
.append("Maximum Latency (in micros): ").append(latencyMax).append('\n')
.append("50%ile speed (in Mbps): ")
.append((float)serializedSize/latency50 * 1000000000L / 1024 / 1024).append('\n')
.append((float)serializedSize/latency50 * 1000000L / 1024 / 1024).append('\n')
.append("90%ile speed (in Mbps): ")
.append((float)serializedSize/latency90 * 1000000000L / 1024 / 1024).append('\n')
.append((float)serializedSize/latency90 * 1000000L / 1024 / 1024).append('\n')
.append("95%ile speed (in Mbps): ")
.append((float)serializedSize/latency95 * 1000000000L / 1024 / 1024).append('\n')
.append((float)serializedSize/latency95 * 1000000L / 1024 / 1024).append('\n')
.append("99%ile speed (in Mbps): ")
.append((float)serializedSize/latency99 * 1000000000L / 1024 / 1024).append('\n')
.append((float)serializedSize/latency99 * 1000000L / 1024 / 1024).append('\n')
.append("99.9%ile speed (in Mbps): ")
.append((float)serializedSize/latency999 * 1000000000L / 1024 / 1024).append('\n')
.append((float)serializedSize/latency999 * 1000000L / 1024 / 1024).append('\n')
.append("Slowest speed (in Mbps): ")
.append((float)serializedSize/latencyMax * 1000000000L / 1024 / 1024).append('\n')
.append((float)serializedSize/latencyMax * 1000000L / 1024 / 1024).append('\n')
.append("QPS: ").append(qps).append('\n')
.append("Size of request: ").append(serializedSize).append('\n');
return values.toString();
Expand Down
Expand Up @@ -10,6 +10,7 @@
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
Expand All @@ -30,6 +31,9 @@ public class RpcBenchmarksActivity extends AppCompatActivity {
private EditText mConnectionsEditText;
private Button mPingButton;
private TextView mPingTextView;
private CheckBox mGzip;
private CheckBox mOkHttp;
private EditText mPayloadEditText;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -41,9 +45,19 @@ protected void onCreate(Bundle savedInstanceState) {
mConnectionsEditText = (EditText) findViewById(R.id.connections_edit_text);
mPingButton = (Button) findViewById(R.id.ping_button);
mPingTextView = (TextView) findViewById(R.id.ping_text_view);
mGzip = (CheckBox) findViewById(R.id.gzip_json_checkbox);
mOkHttp = (CheckBox) findViewById(R.id.okhttp_json_checkbox);
mPayloadEditText = (EditText) findViewById(R.id.payload_edit_text);

// set up benchmark cards
initializeBenchmarks();
}

private void initializeBenchmarks() {
benchmarks = new ArrayList<>();
benchmarks.add(new RpcBenchmark("gRPC benchmarks", "", 0));
benchmarks.add(new RpcBenchmark("HTTP JSON benchmarks", "", 1));

LayoutInflater inflater = LayoutInflater.from(getApplicationContext());
LinearLayout l = (LinearLayout) findViewById(R.id.rpc_benchmark_cardlayoutlinear);
cardViews = new ArrayList<>();
Expand All @@ -65,28 +79,28 @@ public void onClick(View v) {
startBenchmark(cv, b);
}
});

cardViews.add(cv);
l.addView(cv);
}
}

private void initializeBenchmarks() {
benchmarks = new ArrayList<>();
benchmarks.add(new RpcBenchmark("gRPC benchmarks", "", 0));
benchmarks.add(new RpcBenchmark("HTTP JSON benchmarks", "", 1));
}

public void startBenchmark(CardView cv, RpcBenchmark b) {
String host = mHostEditText.getText().toString();
String numConnections = mConnectionsEditText.getText().toString();
// String port = mPortEditText.getText().toString();
// String addr = host + ":" + port;
String payloadSize = mPayloadEditText.getText().toString();
String useGzip = Boolean.toString(mGzip.isChecked());
String useOkHttp = Boolean.toString(mOkHttp.isChecked());

if (payloadSize == null || payloadSize.length() == 0) {
payloadSize = "100";
}

BenchmarkAsyncTask task = new BenchmarkAsyncTask(cv, b);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
task.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, host, numConnections);
task.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, host, numConnections,
payloadSize, useGzip, useOkHttp);
} else {
task.execute(host, numConnections);
task.execute(host, numConnections, payloadSize, useGzip, useOkHttp);
}
}

Expand Down Expand Up @@ -164,7 +178,8 @@ protected void onPreExecute() {
@Override
protected RpcBenchmarkResult doInBackground(String... args) {
try {
RpcBenchmarkResult res = b.run(args[0], args[1]);
boolean useOkHttp = Boolean.parseBoolean(args[4]);
RpcBenchmarkResult res = b.run(useOkHttp, args[0], args[1], args[2], args[3]);
return res;
} catch (Exception e) {
System.out.println("Exception while running benchmarks: " + e);
Expand Down

0 comments on commit ed31969

Please sign in to comment.