-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from ZhouyihaiDing/benchmark
Init benchmark tests
- Loading branch information
Showing
7 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?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(); | ||
for ($i = 0; $i < count($payload); $i++) { | ||
$rest_latency_array[$i] = array(); | ||
$grpc_latency_array[$i] = array(); | ||
} | ||
|
||
// 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; | ||
for ($i = 0; $i < count($payload); $i++) { | ||
$payload_size = $payload[$i]; | ||
$msg_grpc = generate_string($payload_size); | ||
$msg_rest = generate_string($payload_size); | ||
|
||
$grpc_start_time = microtime(true); | ||
$grpcLogger->info($msg_grpc); | ||
array_push($grpc_latency_array[$i], microtime(true) - $grpc_start_time); | ||
|
||
$rest_start_time = microtime(true); | ||
$restLogger->info($msg_rest); | ||
array_push($rest_latency_array[$i], microtime(true) - $rest_start_time); | ||
} | ||
} | ||
|
||
for ($i = 0; $i < count($payload); $i++) { | ||
echo "=====================". PHP_EOL; | ||
echo "payload: ". $payload[$i]. PHP_EOL; | ||
echo "gRPC transport qps: " . ($benchmark_count / array_sum($grpc_latency_array[$i])) . PHP_EOL; | ||
sort($grpc_latency_array[$i]); | ||
print_stats("gRPC", $grpc_latency_array[$i]); | ||
|
||
echo "rest transport qps: " . ($benchmark_count / array_sum($rest_latency_array[$i])) . PHP_EOL; | ||
sort($rest_latency_array[$i]); | ||
print_stats("REST", $rest_latency_array[$i]); | ||
} | ||
} | ||
|
||
$arg_warmup = !empty($argv[1]) ? $argv[1] : 2; | ||
$arg_benchmark = !empty($argv[2]) ? $argv[2] : 40; | ||
$payload = array(); | ||
if(!empty($argv[3])) { | ||
$payload = array_map('intval', explode(',', $argv[3])); | ||
} else { | ||
$payload = array(1, 10, 100, 1024, 10240); | ||
} | ||
qps_client_main($arg_warmup, $arg_benchmark, $payload); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 1024 | ||
|
||
|