Hi,

We are using Tome module on a very large website. When we export the static version we quickly reach a point where the database just won't response anymore and make all fail during static export:

SQLSTATE[HY000]: General error: 2006 MySQL server has gone away: CREATE TABLE {cache_config} (
  `cid` VARCHAR(255) BINARY CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL DEFAULT '' COMMENT 'Primary Key: Unique cach
  e ID.',
  `data` LONGBLOB NULL DEFAULT NULL COMMENT 'A collection of data to cache.',
  `expire` INT NOT NULL DEFAULT 0 COMMENT 'A Unix timestamp indicating when the cache entry should expire, or -1 for never.',
  `created` DECIMAL(14, 3) NOT NULL DEFAULT 0 COMMENT 'A timestamp with millisecond precision indicating when the cache entry
  was created.',
  `serialized` SMALLINT NOT NULL DEFAULT 0 COMMENT 'A flag to indicate whether content is serialized (1) or not (0).',
  `tags` LONGTEXT NULL DEFAULT NULL COMMENT 'Space-separated list of cache tags for this entry.',
  `checksum` VARCHAR(255) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL COMMENT 'The tag invalidation checksum when th
  is entry was saved.',
  PRIMARY KEY (`cid`),
  INDEX `expire` (`expire`),
  INDEX `created` (`created`)
  ) ENGINE = InnoDB DEFAULT CHARACTER SET utf8mb4 COMMENT 'Storage for the cache API.'; Array
  (
  )

Did you already face similar issues when exporting something like more than 500 pages at a time? Because we target more that 20000 pages. The whole rebuild might be needed when updating the menu for example.

We will be happy to help you fixing performance issues.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jlatorre created an issue. See original summary.

samuel.mortenson’s picture

@jlatorre Thanks for the issue! This is a common problem with Tome, and from what I can tell is just Drupal/MySQL not being able to handle so many concurrent requests. I've been doing some light performance testing and profiling with Tome commands and, so far, Drupal is always the bottleneck.

In the short term, I would recommend tweaking the --process-count and --path-count options to find a combination that doesn't overload your site. A lower process count and higher path count would mean less concurrent MySQL queries, which may help you here.

In the longer term, I think some paths forward here are:

1. Continue to profile and audit Tome performance to see if there's something we can improve - I'd love any help here, and would welcome any tweaks to improve performance.
2. Write a patch to retry failed tome:static-export-path invocations at least one time, and maybe make the retry count configurable.

jlatorre’s picture

Thanks for the reply, we are gathering information about this and will work on it!

jlatorre’s picture

Here is a first try, what would you recommend based on what I'v done?

jlatorre’s picture

FileSize
5.5 KB

re-uploaded it because of indent fail... and added phpDoc missing

samuel.mortenson’s picture

Status: Active » Needs work

Thanks for the patch @jlatorre! This is basically how I would have implemented adding a configurable "retry-count" option to the static command. Do you think this change is going to be enough to get around your "MySQL server has gone away" issues?

Here's some review of your patch:

  1. +++ b/modules/tome_base/src/ProcessTrait.php
    @@ -16,21 +16,44 @@ trait ProcessTrait {
    +  protected function runCommands(array $commands, $concurrency, $retry_count, $callback = NULL) {
    

    There are other commands that use this trait in tome_sync, they will also need updated so that they continue to function.

  2. +++ b/modules/tome_base/src/ProcessTrait.php
    @@ -16,21 +16,44 @@ trait ProcessTrait {
    +    $filter_callback = function (Process $current_process) use (&$collected_errors, $callback, $retry_count) {
    +      $current_process->stop();
           $is_running = $current_process->isRunning();
    

    Why stop the current process here?

  3. +++ b/modules/tome_base/src/ProcessTrait.php
    @@ -16,21 +16,44 @@ trait ProcessTrait {
    +          if (!$current_process->isSuccessful() && $retry == $retry_count) {
    

    Can we use strict equality here, i.e. ===?

  4. +++ b/modules/tome_base/src/ProcessTrait.php
    @@ -16,21 +16,44 @@ trait ProcessTrait {
    +            $errors[] = "Error when running \"{$command}\" No more retry..." . PHP_EOL;
    +            $retry++;
    

    Thinking through the logic here, if the retry count was set to 2, I think this loop would only retry one time.

    Loop 1 - $retry 0, command is executed for the first time.
    Loop 2 - $retry 1, command is retried one time.
    Loop 3 - $retry 2, command is not retried again and this error is shown.

  5. +++ b/modules/tome_base/src/ProcessTrait.php
    @@ -45,16 +68,16 @@ trait ProcessTrait {
    -        $process = new Process($command, isset($_SERVER['PWD']) ? $_SERVER['PWD'] : NULL);
    +        $process = new Process($command);
    ...
    -      usleep(50000);
    

    This lines shouldn't be changed - guessing the patch was just made against an older release of Tome.

  6. +++ b/modules/tome_base/src/ProcessTrait.php
    @@ -45,16 +68,16 @@ trait ProcessTrait {
    +
    

    This newline can be removed.

  7. +++ b/modules/tome_static/src/Commands/StaticCommand.php
    @@ -31,6 +31,10 @@ class StaticCommand extends CommandBase {
    +  /**
    +   * The default number of retry per failed process.
    +   */
    

    Add a newline above this block comment.

jlatorre’s picture

Thanks for the review! This helps a lot! Did a few modification on the patch.

I'm not sure this will end all "MySQL has gone away" errors but at least this could could lead to less missing path (temporary error when accessing a path for example).

+++ b/modules/tome_base/src/ProcessTrait.php
@@ -16,21 +16,44 @@ trait ProcessTrait {
+            $errors[] = "Error when running \"{$command}\" No more retry..." . PHP_EOL;
+            $retry++;
Thinking through the logic here, if the retry count was set to 2, I think this loop would only retry one time.

Loop 1 - $retry 0, command is executed for the first time.
Loop 2 - $retry 1, command is retried one time.
Loop 3 - $retry 2, command is not retried again and this error is shown.

About this part, I'm not sure about it but according to me you only trigger the while loop only after the command has been run once. So this would make sense.

This would make me think :

Loop 1 - $retry 0, command has already been executed for the first time -> start the process again $retry = 1
Loop 2 - $retry 1, command has failed a second time -> start the process again, $retry = 2
Loop 3 - $retry 2, command is not retried again and this error is shown.

jlatorre’s picture

samuel.mortenson’s picture

For the retry count - users will expect that if the retry-count option is set to "2", a failing command will be executed three times. One for the first execution, and then two retries. Does that make more sense?

jlatorre’s picture

Just changed retry begin count by -1 instead of 0. I think this effectively make more sense if retry means how many tries after a fail you want.

jlatorre’s picture

Status: Needs work » Needs review
samuel.mortenson’s picture

This is looking good, thanks again @jlatorre. I'll tweak some things on commit but this should get into the next release.

samuel.mortenson’s picture

+++ b/modules/tome_base/src/ProcessTrait.php
@@ -16,21 +16,43 @@ trait ProcessTrait {
+        while ($retry <= $retry_count && !$current_process->isSuccessful()) {

After testing this a bit, I found that Drush can have error output but still return 0, which means you have to check the error output as well.

Also, this while loop is blocking - meaning that retries of different processes can never happen in parallel.

Here's a new patch which moves all the retry checking to another callback before the normal process filter callback, and fixes some errors I found when testing #10.

samuel.mortenson’s picture

Title: MySQL has Gone away when exporting static website » Retry failed tome:static-export-path commands

  • samuel.mortenson authored e9261b5 on 8.x-1.x
    Issue #3020504 by jlatorre, samuel.mortenson: Retry failed tome:static-...
samuel.mortenson’s picture

Status: Needs review » Fixed

This is in now - thanks for the help!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.