Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
38 changes: 38 additions & 0 deletions packages/mediawiki/0008-nginx-stream-access-log.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
diff --git a/base/NginxDaemon.php b/base/NginxDaemon.php
index aa48307..608e8f1 100644
--- a/base/NginxDaemon.php
+++ b/base/NginxDaemon.php
@@ -47,13 +47,26 @@ final class NginxDaemon extends Process {
$page_results = Map {};

// Custom format: '$status $body_bytes_sent $request_time "$request"'
- $log = file_get_contents($this->options->tempDir.'/access.log');
- $entries = explode("\n", trim($log));
+ // Stream the access log one line at a time rather than slurping the whole
+ // file into a single string. On high-throughput hosts (many-core ARM, long
+ // wrk durations) the log can exceed HHVM's ~2GB single-string limit, and
+ // file_get_contents() then aborts the run with
+ // "StringBuffer exceeded 2147483623 bytes of memory".
+ $access_log = $this->options->tempDir.'/access.log';
$entries_by_request = array();
- foreach ($entries as $entry) {
+ $fh = fopen($access_log, 'r');
+ invariant($fh !== false, 'Failed to open nginx access log %s', $access_log);
+ while (($line = fgets($fh)) !== false) {
+ // Strip null bytes that can appear due to nginx log buffer races on
+ // high-throughput ARM systems, then drop the trailing newline.
+ $entry = rtrim(str_replace("\x00", "", $line), "\r\n");
+ if ($entry === '') {
+ continue;
+ }
$request = explode('"', $entry)[1];
$entries_by_request[$request][] = $entry;
}
+ fclose($fh);
$combined_times = Vector {};

foreach ($entries_by_request as $request => $entries) {
17 changes: 0 additions & 17 deletions packages/mediawiki/0008-nginx-strip-null-bytes.diff

This file was deleted.

8 changes: 5 additions & 3 deletions packages/mediawiki/install_oss_performance_mediawiki.sh
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,11 @@ git apply --check "${TEMPLATES_DIR}/0001-oss-performance-scalable-hhvm.diff" \
# templates/oss-performance-mediawiki/0006-oss-performance-reuse-mediawiki-hhvm.diff
git apply --check "${TEMPLATES_DIR}/0006-oss-performance-reuse-mediawiki-hhvm.diff" \
&& git apply "${TEMPLATES_DIR}/0006-oss-performance-reuse-mediawiki-hhvm.diff"
# Strip null bytes from nginx access log to fix UTF-8 errors in metrics on ARM
git apply --check "${TEMPLATES_DIR}/0008-nginx-strip-null-bytes.diff" \
&& git apply "${TEMPLATES_DIR}/0008-nginx-strip-null-bytes.diff"
# Stream the nginx access log line-by-line (and strip null bytes) so metrics
# collection does not overflow HHVM's ~2GB single-string limit on
# high-throughput ARM hosts
git apply --check "${TEMPLATES_DIR}/0008-nginx-stream-access-log.diff" \
&& git apply "${TEMPLATES_DIR}/0008-nginx-stream-access-log.diff"

# apply options for mediawiki mini patch
git apply --check "${TEMPLATES_DIR}/0007-oss-performance-more-warmup-options.diff" \
Expand Down
Loading