diff --git a/core/lib/Drupal/Core/EventSubscriber/ExceptionTestSiteSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/ExceptionTestSiteSubscriber.php
index d8f1a61..6e4f82d 100644
--- a/core/lib/Drupal/Core/EventSubscriber/ExceptionTestSiteSubscriber.php
+++ b/core/lib/Drupal/Core/EventSubscriber/ExceptionTestSiteSubscriber.php
@@ -8,7 +8,9 @@
 namespace Drupal\Core\EventSubscriber;
 
 use Drupal\Core\Utility\Error;
+use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
 use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
+use Symfony\Component\HttpKernel\KernelEvents;
 
 /**
  * Custom handling of errors when in a system-under-test.
@@ -46,7 +48,7 @@ public function on500(GetResponseForExceptionEvent $event) {
 
     // When running inside the testing framework, we relay the errors
     // to the tested site by the way of HTTP headers.
-    if (DRUPAL_TEST_IN_CHILD_SITE && !headers_sent() && (!defined('SIMPLETEST_COLLECT_ERRORS') || SIMPLETEST_COLLECT_ERRORS)) {
+    if ($this->canAddHeaders()) {
       // $number does not use drupal_static as it should not be reset
       // as it uniquely identifies each PHP error.
       static $number = 0;
@@ -64,4 +66,41 @@ public function on500(GetResponseForExceptionEvent $event) {
     }
   }
 
+  /**
+   * Handles response being sent.
+   *
+   * @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
+   *   The event to process.
+   */
+  public function onResponse(FilterResponseEvent $event) {
+    if ($this->canAddHeaders()) {
+      $response = $event->getResponse();
+      $memory_usage = memory_get_peak_usage(TRUE);
+      $response->headers->add([
+        'X-Drupal-Memory-Peak' => round($memory_usage / 1024 / 1024, 2),
+      ]);
+      $event->setResponse($response);
+    }
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function getSubscribedEvents() {
+    $events = parent::getSubscribedEvents();
+    // Add a listener for outputting peak memory usage.
+    $events[KernelEvents::RESPONSE][] = ['onResponse', 100];
+    return $events;
+  }
+
+  /**
+   * Returns if headers should be added.
+   *
+   * @return bool
+   *   TRUE if headers should be added.
+   */
+  protected function canAddHeaders() {
+    return (DRUPAL_TEST_IN_CHILD_SITE && !headers_sent() && (!defined('SIMPLETEST_COLLECT_ERRORS') || SIMPLETEST_COLLECT_ERRORS));
+  }
+
 }
diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php
index 3616888..6639d45 100644
--- a/core/modules/simpletest/src/WebTestBase.php
+++ b/core/modules/simpletest/src/WebTestBase.php
@@ -60,6 +60,20 @@
   protected $url;
 
   /**
+   * Set to TRUE to ignore memory usage on the child site.
+   *
+   * @var bool
+   */
+  protected $ignoreMemoryUsage = FALSE;
+
+  /**
+   * Set to the maximum number of MB of memory usage to allow on the child site.
+   *
+   * @var int
+   */
+  protected $memoryUsageTrigger = 64;
+
+  /**
    * The handle of the current cURL connection.
    *
    * @var resource
@@ -1292,6 +1306,15 @@ protected function curlHeaderCallback($curlHandler, $header) {
       // the header.
       call_user_func_array(array(&$this, 'error'), unserialize(urldecode($matches[1])));
     }
+    if (!$this->ignoreMemoryUsage && preg_match('/^X-Drupal-Memory-Peak: (.*)$/', $header, $matches)) {
+      if ((float) $matches[1] >= $this->memoryUsageTrigger) {
+        $this->fail(SafeMarkup::format('Child site memory usage (@siteMB) exceeded acceptable maximum (@maxMB) on url @url', [
+          '@url' => $this->getUrl(),
+          '@site' => $matches[1],
+          '@max' => $this->memoryUsageTrigger,
+        ]));
+      }
+    }
 
     // Save cookies.
     if (preg_match('/^Set-Cookie: ([^=]+)=(.+)/', $header, $matches)) {
