Skip to content

Commit eb5ecbf

Browse files
committed
Using headers to output benchmark data (solved Content-Length curl issues as described in #38)
1 parent 9907bbf commit eb5ecbf

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

benchmarks/_functions.sh

+15-7
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ benchmark ()
44
url="$2"
55
ab_log="$output_dir/$fw.ab.log"
66
output="$output_dir/$fw.output"
7+
benchmark_data="$output_dir/$fw.benchmark_data"
78

89
echo "ab -c 10 -t 3 $url"
910
ab -c 10 -t 3 "$url" > "$ab_log"
10-
curl "$url" > "$output"
11+
curl --dump-header "$benchmark_data" "$url" > "$output"
1112

1213
rps=`grep "Requests per second:" "$ab_log" | cut -f 7 -d " "`
13-
memory=`tail -1 "$output" | cut -f 1 -d ':'`
14-
time=`tail -1 "$output" | cut -f 2 -d ':'`
15-
file=`tail -1 "$output" | cut -f 3 -d ':'`
14+
memory=`grep "X-Benchmark-Output-Data:" "$benchmark_data" | cut -f 2 -d ':' | cut -f 2 -d ' '`
15+
time=`grep "X-Benchmark-Output-Data:" "$benchmark_data" | cut -f 3 -d ':'`
16+
file=`grep "X-Benchmark-Output-Data:" "$benchmark_data" | cut -f 4 -d ':'`
1617
echo "$fw: $rps: $memory: $time: $file" >> "$results_file"
1718

1819
echo "$fw" >> "$check_file"
@@ -35,9 +36,16 @@ benchmark ()
3536
tmp=`cat "$output"`
3637
error="$error$tmp"
3738
fi
38-
x=`grep ':' "$output" || true`
39-
if [ "$x" = "" ]; then
40-
tmp=`cat "$output"`
39+
if [ "$memory" = "" ]; then
40+
tmp=`cat "$benchmark_data"`
41+
error="$error$tmp"
42+
fi
43+
if [ "$time" = "" ]; then
44+
tmp=`cat "$benchmark_data"`
45+
error="$error$tmp"
46+
fi
47+
if [ "$file" = "" ]; then
48+
tmp=`cat "$benchmark_data"`
4149
error="$error$tmp"
4250
fi
4351
if [ "$error" != "" ]; then

libs/output_data.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
<?php
22

3+
// Get benchmark output data
34
$real_usage = null;
4-
// On HHVM, using $real_usage = false ends up always returning 2097152 bytes - https://github.com/facebook/hhvm/issues/2257
55
if (defined('HHVM_VERSION')) {
6+
// On HHVM, using $real_usage = false ends up always returning 2097152 bytes - https://github.com/facebook/hhvm/issues/2257
67
$real_usage = true;
78
}
8-
return sprintf(
9-
"\n%' 8d:%f:%d",
9+
$results = sprintf(
10+
"%' 8d:%f:%d",
1011
memory_get_peak_usage($real_usage), // Using $real_usage due to
1112
microtime(true) - $_SERVER['REQUEST_TIME_FLOAT'],
1213
count(get_included_files()) - 1
1314
);
15+
16+
// Respond benchmark output data in header
17+
header('X-Benchmark-Output-Data: ' . $results);

0 commit comments

Comments
 (0)