Hi,

On a new drupal installation I am getting hundreds of thousands of memcache warnings telling me stuff like this:
Spent 99.09 ms splitting 4,781,831 byte object into 5 pieces, cid = cache_bootstrap-variables

Now I know what this is, memcache only allows objects upto to 1mb, so the memcache module splits it into pieces. It seems the memcache_log_data_pieces would trigger the conditional to register the shutdown function which is sending the watchdog logs, as it is set to 2 by default. However I have set this to 10, checked with drush vget and php-eval that it is set to 10, and I am still getting the logs. I tried adding in a flag past the conditional to see if it was evaluating to true, and it's either not (which it shouldn't be anyway as it's set to 10), or it's not reaching this function.

if (variable_get('memcache_log_data_pieces', 2) && $piece_count >= variable_get('memcache_log_data_pieces', 2)) {
    if (function_exists('format_size')) {
      $data_size = format_size(strlen($data));
    }
    else {
      $data_size = number_format(strlen($data)) . ' byte';
    }
    register_shutdown_function('watchdog', 'memcache', 'Spent !time ms splitting !bytes object into !pieces pieces, cid = !key', array('!time' => timer_read('memcache_split_data'), '!bytes' => $data_size, '!pieces' => $piece_count, '!key' => dmemcache_key($key, $bin)), WATCHDOG_WARNING);
  }

Is there something I need to do to get it to un register this exit function perhaps? It's clogging up the logs, there's nothing but memcache in there.

Comments

michaelmallett created an issue. See original summary.

Jeremy’s picture

I've verified that this logic works as designed locally. Perhaps you're overwriting the $conf array later in settings.php.

You should have something like this in your settings.php:

$conf['memcache_log_data_pieces'] = 10;

Perhaps try moving this down to the very last line of your settings.php configuration file? If that doesn't work, perhaps you're editing the wrong settings.php file? You could try editing dmemcache.inc directly, changing if (variable_get('memcache_log_data_pieces', 2) to if (variable_get('memcache_log_data_pieces', 10).

Note, it's also a good idea to try and keep the size of your cache tables smaller if possible. Perhaps there's things currently being written to cache_bootstrap-variables that don't need to be there?

michaelmallett’s picture

Thanks for the response. Currently in our local_settings.php (our settings.php is default except for the include of local_settings.php) we have the following:

// Memcache settings
$conf['cache_backends'][] = 'sites/all/modules/contrib/memcache/memcache.inc';
$conf['cache_default_class'] = 'MemCacheDrupal';
$conf['cache_class_cache_form'] = 'DrupalDatabaseCache';

// List all the memcache servers, and then ensure the current one is first.
// Taken from https://groups.drupal.org/node/191998#comment-633648
$memcache_servers = array(
  '10.106.176.11:11211' => 'default',
  '10.106.176.12:11211' => 'default',
);

$conf['memcache_servers'] = array();
// Connect to the local memcache server first.
$key = $_SERVER['SERVER_ADDR'] . ':11211';
if (isset($memcache_servers[$key])) {
  $conf['memcache_servers'] += array(
    $key => $memcache_servers[$key],
  );
}
// Add the rest of the servers into the mix.
$conf['memcache_servers'] += $memcache_servers;
$conf['memcache_log_data_pieces'] = 10;

$conf['lock_inc'] = 'sites/all/modules/contrib/memcache/memcache-lock.inc';

As I mentioned above I have added a flag to see if it even gets to this stage

if (variable_get('memcache_log_data_pieces', 2) && $piece_count >= variable_get('memcache_log_data_pieces', 2)) {
//Check if conditional is hit.    
watchdog('memcache_split_test', variable_get('memcache_log_data_pieces', 2) . ' - ' . $piece_count);
    if (function_exists('format_size')) {
      $data_size = format_size(strlen($data));
    }
    else {
      $data_size = number_format(strlen($data)) . ' byte';
    }
    register_shutdown_function('watchdog', 'memcache', 'Spent !time ms splitting !bytes object into !pieces pieces, cid = !key', array('!time' => timer_read('memcache_split_data'), '!bytes' => $data_size, '!pieces' => $piece_count, '!key' => dmemcache_key($key, $bin)), WATCHDOG_WARNING);
  }

And that watchdog message never gets created, which suggests that this conditional is false - as I would expect (but it obviously is TRUE, because the shutdown function is registered). However, I have tried as you suggested, changing the default value to 10, and that works. But I am reluctant to patch a contrib module for something that should work with the config I have. I can't think where the variable is being overwritten, and both drush php-eval and drush vget return the correct conf setting

When you say there might be things that shouldn't be written to cache_bootstrap-variables, can you point me in the direction of something that I can learn how to check and configure that? Because it seems googling is particularly bad, or there's very little information out there for me to tackle the issue - clearly I'm searching for the wrong thing. I would much rather fix the source than just turn off the logs!

Jeremy’s picture

I'd start by moving the following line to the absolute bottom of your main settings.php:

$conf['memcache_log_data_pieces'] = 10;

If that works, you can start working backwards from there to figure out where things are going wrong. For example, maybe your include is failing, or maybe it's including multiple files and a later one is overwriting things.

Or, if this doesn't solve the problem, then double check that this is the correct settings.php.

BTW: Your watchdog test probably failed because watchdog likely isn't available at that time (which is why we're using a shutdown in the first place).

michaelmallett’s picture

I did consider that possibility, but I always thought watchdog was available from bootstrap.

I tried putting it at the bottom of settings.php, and no joy. The memcache module is picking up the memcache server details fine, and all the other memcache conf settings, so I can't figure out why this is not picking up this one variable.

Jeremy’s picture

Depending on your web server setup, it's also possible you'll need to reload (or restart) your web server to get it to see your new settings.php configuration.

michaelmallett’s picture

I've been restarting apache and php-fpm on every code push. I was thinking that it is possible that the domain access include was interfering with this, but every related issue I find has shown that placing domain access last, AFTER everything else is the solution to any issues. Either way I'm confused I can't see why it would still pick up all the other memcache conf variables in my local_settings include, and have the correct value when outputting to drush vget. I'll have to keep looking into exactly what domain access is doing with the conf array.

Also, can you elaborate on this please?

Note, it's also a good idea to try and keep the size of your cache tables smaller if possible. Perhaps there's things currently being written to cache_bootstrap-variables that don't need to be there?

michaelmallett’s picture

I'm still getting this error, I've gone through and completely disabled domain access and it still ignores/overwrites the variable, and only this variable.

I've tried tweaking the cache bins, which took me a while to find anything useful with regards to. Either way, it hasn't made a difference, there is something very odd going on with this memcache install.
For anyone else looking, there's some good information in this book if you want to check it out
http://shop.oreilly.com/product/0636920012269.do

The mere existence of this module causes errors on other servers, despite it not being enabled. I get a lot of these:

WD memcache: You must enable the PHP memcache (recommended) or memcached extension to use        [error]
memcache.inc.
WD memcache: Failed to connect to memcache server: 127.0.0.1:11211

In drush. The registry has been rebuilt, nothing in the settings pointing to memcache.inc, nothing in 'cache_backends', and caches cleared over and over.

Anonymous’s picture

Getting this same problem, anyone have any updates?

Jeremy’s picture

Status: Active » Fixed

Sorry, I'm unable to duplicate. It seems you have a misconfiguration -- the errors you're reporting suggest you've enabled memcache in settings.php, but haven't installed a required PECL extension.

Status: Fixed » Closed (fixed)

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

Unnikrishnan.K’s picture

Hello,

yes, solved by adding $conf['memcache_log_data_pieces'] = 10; on settings.php on memcache configuration

StephenRobinson’s picture

I got a few of these when testing with PHP7. If you are seeing this often, you probably need to delete your unused variables, a project like https://www.drupal.org/project/variable_clean can help....