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

Init benchmark tests #10

Merged
merged 8 commits into from
May 29, 2018
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
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
91 changes: 91 additions & 0 deletions tests/qps/Logging/LoggingClientCrossTests.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

require dirname(__FILE__).'/../vendor/autoload.php';
require dirname(__FILE__).'/../benchmark.php';
use Google\Cloud\Logging\LoggingClient;

function qps_client_main($arg_warm_up, $arg_benchmark, $payload)
{
// Disable the batch so each request stands for a RPC
$grpcLogger = LoggingClient::psrBatchLogger(
'perf-gRPC',
[
'clientConfig' => [
'transport' => 'grpc'
],
'batchOptions' => ['batchSize' => 1]
]
);

$restLogger = LoggingClient::psrBatchLogger(
'perf-rest',
[
'clientConfig' => [
'transport' => 'rest'
],
'batchOptions' => ['batchSize' => 1]
]
);

$warm_up_time = $arg_warm_up;
$benchmark_time = $arg_benchmark;

$benchmark_count = 0;
$rest_latency_array = array();
$grpc_latency_array = array();

// First latency
$start_time = microtime(true);
$grpcLogger->info("a");
$grpc_first_latency = microtime(true) - $start_time;

$start_time = microtime(true);
$restLogger->info("b");
$rest_first_latency = microtime(true) - $start_time;

// Warm up
$start_time = microtime(true);
echo "Start warmup...". PHP_EOL;
while(1) {
if (microtime(true) - $start_time > $warm_up_time) {
break;
}
$grpcLogger->info('a');
$restLogger->info('a');
}
// Benchmark
echo "Start benchmark...". PHP_EOL;
$start_time = microtime(true);
while(1) {
if (microtime(true) - $start_time > $benchmark_time) {
break;
}
$benchmark_count += 1;

$msg_grpc = generate_string($payload);
$grpc_start_time = microtime(true);
$grpcLogger->info($msg_grpc);
array_push($grpc_latency_array, microtime(true) - $grpc_start_time);

$msg_rest = generate_string($payload);
Copy link
Contributor Author

@ZhouyihaiDing ZhouyihaiDing May 2, 2018

Choose a reason for hiding this comment

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

By generating different msg instead of using the same msg "a" in every iteration, rest becomes slower.

Copy link

Choose a reason for hiding this comment

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

Interesting. I'll verify this too.

Copy link
Contributor Author

@ZhouyihaiDing ZhouyihaiDing May 3, 2018

Choose a reason for hiding this comment

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

I can reproduce it in all 5 GCE machines with 1/2/4/8/16 cores.
By the way, I install the php by apt-get, as well as ext-curl by apt-get install php-curl.

I just set 1k to be the default payload and am going to re-test again. With 30s warmup and 600s benchmark time.

$rest_start_time = microtime(true);
$restLogger->info($msg_rest);
array_push($rest_latency_array, microtime(true) - $rest_start_time);
}

echo "gRPC transport qps: ".($benchmark_count/array_sum($grpc_latency_array)).PHP_EOL;
echo "gRPC latency for first RPC:". $grpc_first_latency. PHP_EOL;
sort($grpc_latency_array);
print_stats("gRPC", $grpc_latency_array);

echo "rest transport qps: ". ($benchmark_count/array_sum($rest_latency_array)). PHP_EOL;
echo "rest latency for first RPC:". $rest_first_latency. PHP_EOL;
sort($rest_latency_array);
print_stats("REST", $rest_latency_array);
}

$arg_warmup = !empty($argv[1]) ? $argv[1] : 20;
$arg_benchmark = !empty($argv[2]) ? $argv[2] : 40;
$payload = !empty($argv[3]) ? $argv[3] : 1;
qps_client_main($arg_warmup, $arg_benchmark, $payload);

22 changes: 22 additions & 0 deletions tests/qps/Logging/logging_grpc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
use Google\Cloud\Logging\Logger;
use Google\Cloud\Logging\LoggingClient;
putenv("GOOGLE_APPLICATION_CREDENTIALS=./grpcwebtesting_key.json");
require_once './vendor/autoload.php';

$start_time = microtime(true);
$grpcLogger = LoggingClient::psrBatchLogger(
'perf-grpc',
[
'clientConfig' => [
'transport' => 'grpc'
],
'batchOptions' => ['batchSize' => 1]
]
);

$grpcLogger->info('s');
$first_latency = microtime(true) - $start_time;
echo "rest latency for first RPC:". $first_latency. PHP_EOL;
file_put_contents('logs_grpc.txt', $first_latency.PHP_EOL , FILE_APPEND | LOCK_EX);

21 changes: 21 additions & 0 deletions tests/qps/Logging/logging_rest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
use Google\Cloud\Logging\Logger;
use Google\Cloud\Logging\LoggingClient;
putenv("GOOGLE_APPLICATION_CREDENTIALS=./grpcwebtesting_key.json");
require_once './vendor/autoload.php';

$start_time = microtime(true);
$restLogger = LoggingClient::psrBatchLogger(
'perf-rest',
[
'clientConfig' => [
'transport' => 'rest'
],
'batchOptions' => ['batchSize' => 1]
]
);

$restLogger->info('e');
$first_latency = microtime(true) - $start_time;
echo "rest latency for first RPC:". $first_latency. PHP_EOL;
file_put_contents('logs_rest.txt', $first_latency.PHP_EOL , FILE_APPEND | LOCK_EX);
24 changes: 24 additions & 0 deletions tests/qps/benchmark.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

function print_stats($name, $stats)
{
echo "stats result for ". $name .PHP_EOL;
echo "Ave latency :". array_sum($stats)/max(count($stats), 1). PHP_EOL;
echo "50% latency :". $stats[count($stats)*0.5]. PHP_EOL;
echo "80% latency :". $stats[count($stats)*0.8]. PHP_EOL;
echo "90% latency :". $stats[count($stats)*0.9]. PHP_EOL;
echo "99% latency :". $stats[min(count($stats)*0.99, count($stats) - 1)]. PHP_EOL;
}

function generate_string($size)
{
$seed = str_split('abcdefghijklmnopqrstuvwxyz'
.'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
.'0123456789!@#$%^&*()');
$str_res = '';
for($i=0; $i<$size; $i++) {
$k = rand(0,71);
$str_res .= $seed[$k];
}
return $str_res;
}
8 changes: 8 additions & 0 deletions tests/qps/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"require": {
"google/cloud": "^0.62.0",
"ext-json": "*",
"ext-protobuf": "*",
"ext-curl": "*"
}
}
8 changes: 8 additions & 0 deletions tests/qps/run_fpm_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

# LoggingClient
for i in {1..100}
do
curl -I localhost/logging_rest.php
curl -I localhost/logging_grpc.php
done
6 changes: 6 additions & 0 deletions tests/qps/run_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

# LoggingClient
php -d extension=grpc.so -d extension=protobuf.so Logging/LoggingClientCrossTests.php 40 80