Skip to content

Commit 5e258e3

Browse files
committed
Using headers to output benchmark data (solved Content-Length curl issues as described in #38)
1 parent 51c2493 commit 5e258e3

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

benchmarks/_functions.sh

Lines changed: 15 additions & 7 deletions
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 -H 'X-Include-Benchmark-Output-Data: 1' --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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
<?php
2+
// Only output data if specifically requested
3+
$headers = getallheaders();
4+
if (!isset($headers["X-Include-Benchmark-Output-Data"])) {
5+
return;
6+
}
27

8+
// Get benchmark output data
39
$real_usage = null;
4-
// On HHVM, using $real_usage = false ends up always returning 2097152 bytes - https://github.com/facebook/hhvm/issues/2257
510
if (defined('HHVM_VERSION')) {
11+
// On HHVM, using $real_usage = false ends up always returning 2097152 bytes - https://github.com/facebook/hhvm/issues/2257
612
$real_usage = true;
713
}
8-
return sprintf(
9-
"\n%' 8d:%f:%d",
14+
$results = sprintf(
15+
"%' 8d:%f:%d",
1016
memory_get_peak_usage($real_usage), // Using $real_usage due to
1117
microtime(true) - $_SERVER['REQUEST_TIME_FLOAT'],
1218
count(get_included_files()) - 1
1319
);
20+
21+
// Respond benchmark output data in header
22+
header('X-Benchmark-Output-Data: ' . $results);

0 commit comments

Comments
 (0)