Solving performance problems with Memcache Mutex extension for eZ Publish - Part II: Technical details

von Ivo Lukač -

Here is just a short technical explanation of the topic in the last blog post. That post described how we solved a performance issue on one eZ Publish based web site by developing an eZ Publish extension which overrides eZMutex to use memcache instead of file locking. The extension is published and shared with the community on projects.ez.no.

eZMutex is used by standard file handler (eZFSFileHandler). In some future post we will try also to compare this solution with a next generation file handler (eZFS2FileHanlder) included as optional module in current stable eZ Publish version.

Technical details

Default eZMutex has 3 main functions: test(), lock() and unclock(). Function test() returns bool value if the mutex exist or not. In the file based version it does 1 or 2 flock() calls:

if ( flock( $fp, LOCK_EX | LOCK_NB ) ) {
    flock( $fp, LOCK_UN );
    return false;
}
return true;

In the memcache version we only call 1 memcache action:

return memcache_get($this->mc,$this->KeyName);

Function lock() makes an exclusive lock on mutex resource. In the file based version it does 1 flock() call, 1 file_exists() call, 2 create_file() calls and 2 rename_file() calls:

if ( flock( $fp, LOCK_EX ) ) {
    $this->clearMeta();
    $this->setMeta( 'timestamp', time() );
    return true;
}
return false;

In the memcache version there, all in all, 4 memcache calls:

if ( memcache_add($this->mc,$this->KeyName,"1",false, $time) ) {
  $this->clearMeta();
  $this->setMeta( 'timestamp', time() );
  return true;
}
return false;

Function unlock() releases lock on mutex resource. In the file based version functions does 1 fclose() and 2 file_delete() calls.

if ( $fp = $this->fp() ) {
  fclose( $fp );
  @unlink( $this->MetaFileName );
  @unlink( $this->FileName );
  $GLOBALS['eZMutex_FP_' . $this->FileName] = false;
}
return false;

In there memcache version there are 2 memcache calls:

memcache_delete($this->mc,$this->MetaKeyName, 0);
memcache_delete($this->mc,$this->KeyName, 0);
return true;

To summarize the comparison on a test-lock-unlock cycle: we replaced 10-11 file system interactions with 7 memcache interactions and in practice that gives huge performance gains.

Comments

Diese Seite verwendet Cookies. Einige dieser Cookies sind unverzichtbar, während andere uns helfen, deine Erfahrung zu verbessern, indem sie uns Einblicke in die Nutzung der Website geben.

Ausführlichere Informationen über die von uns verwendeten Cookies findest du in unserer Datenschutzrichtlinie.

Einstellungen anpassen
  • Notwendige Cookies ermöglichen die Kernfunktionen. Die Website kann ohne diese Cookies nicht richtig funktionieren und kann nur deaktiviert werden, indem du deine Browsereinstellungen änderst.