From 0b37fe466a68665e0f9edffc52e4f2727dd890b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20S=CC=8Ckoda?= Date: Sun, 18 Nov 2012 14:46:31 +0100 Subject: [PATCH] MDL-36682 remove old unused shared memory caching support --- admin/settings/server.php | 23 ----- lang/en/admin.php | 12 --- lib/db/upgrade.php | 13 +++ lib/eaccelerator.class.php | 189 ------------------------------------- lib/memcached.class.php | 160 ------------------------------- lib/moodlelib.php | 11 +-- lib/setup.php | 43 --------- lib/setuplib.php | 35 ------- version.php | 2 +- 9 files changed, 15 insertions(+), 473 deletions(-) delete mode 100644 lib/eaccelerator.class.php delete mode 100644 lib/memcached.class.php diff --git a/admin/settings/server.php b/admin/settings/server.php index 4e773cd704c30..3ba7201614219 100644 --- a/admin/settings/server.php +++ b/admin/settings/server.php @@ -193,29 +193,6 @@ $temp->add(new admin_setting_configtext('curltimeoutkbitrate', new lang_string('curltimeoutkbitrate', 'admin'), new lang_string('curltimeoutkbitrate_help', 'admin'), 56, PARAM_INT)); -/* //TODO: we need to fix code instead of relying on slow rcache, enable this once we have some code that is actually using it -$temp->add(new admin_setting_special_selectsetup('cachetype', new lang_string('cachetype', 'admin'), - new lang_string('configcachetype', 'admin'), '', - array( '' => new lang_string('none'), - 'internal' => 'internal', - 'memcached' => 'memcached', - 'eaccelerator' => 'eaccelerator'))); -// NOTE: $CFG->rcache is forced to bool in lib/setup.php -$temp->add(new admin_setting_special_selectsetup('rcache', new lang_string('rcache', 'admin'), - new lang_string('configrcache', 'admin'), 0, - array( '0' => new lang_string('no'), - '1' => new lang_string('yes')))); -$temp->add(new admin_setting_configtext('rcachettl', new lang_string('rcachettl', 'admin'), - new lang_string('configrcachettl', 'admin'), 10)); -$temp->add(new admin_setting_configtext('intcachemax', new lang_string('intcachemax', 'admin'), - new lang_string('configintcachemax', 'admin'), 10)); -$temp->add(new admin_setting_configtext('memcachedhosts', new lang_string('memcachedhosts', 'admin'), - new lang_string('configmemcachedhosts', 'admin'), '')); -$temp->add(new admin_setting_configselect('memcachedpconn', new lang_string('memcachedpconn', 'admin'), - new lang_string('configmemcachedpconn', 'admin'), 0, - array( '0' => new lang_string('no'), - '1' => new lang_string('yes')))); -*/ $ADMIN->add('server', $temp); diff --git a/lang/en/admin.php b/lang/en/admin.php index dbf755f111de3..42835f0f580b3 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -90,7 +90,6 @@ $string['cachejs'] = 'Cache Javascript'; $string['cachejs_help'] = 'Javascript caching and compression greatly improves page loading performance. it is strongly recommended for production sites. Developers will probably want to disable this feature.'; $string['cachetext'] = 'Text cache lifetime'; -$string['cachetype'] = 'Cache type'; $string['calendarexportsalt'] = 'Calendar export salt'; $string['calendarsettings'] = 'Calendar'; $string['calendar_weekend'] = 'Weekend days'; @@ -143,7 +142,6 @@ $string['configautologinguests'] = 'Should visitors be logged in as guests automatically when entering courses with guest access?'; $string['configbloglevel'] = 'This setting allows you to restrict the level to which user blogs can be viewed on this site. Note that they specify the maximum context of the VIEWER not the poster or the types of blog posts. Blogs can also be disabled completely if you don\'t want them at all.'; $string['configcachetext'] = 'For larger sites or sites that use text filters, this setting can really speed things up. Copies of texts will be retained in their processed form for the time specified here. Setting this too small may actually slow things down slightly, but setting it too large may mean texts take too long to refresh (with new links, for example).'; -$string['configcachetype'] = 'Select a type of cache for Moodle to use. This will only configure the cache, remember to enable rcache so that the cache is used for something. Use only if you need to reduce the load on the database system -- otherwise Moodle will actually run slower. Medium-traffic sites may see benefits using \'internal\'. A single webserver with eAccelerator or Turckmmcache installed with the shared memory options enabled should try \'eaccelerator\'. If you have a multiple-server setup, and you have one or more memcached daemons running and the PHP-memcached extension, select \'memcached\' and configure the memached options below.
Note: make sure you test performance under load and tune accordingly -- the caches can make your site slower. In high-traffic situations, eAccelerator and memcached can yield the most benefits, but have the higher costs in CPU usage on the webserver.'; $string['configcalendarexportsalt'] = 'This random text is used for improving of security of authentication tokens used for exporting of calendars. Please note that all current tokens are invalidated if you change this hash salt.'; $string['configclamactlikevirus'] = 'Treat files like viruses'; $string['configclamdonothing'] = 'Treat files as OK'; @@ -229,7 +227,6 @@ $string['configgradeexport'] = 'Choose which gradebook export formats are your primary methods for exporting grades. Chosen plugins will then set and use a "last exported" field for every grade. For example, this might result in exported records being identified as being "new" or "updated". If you are not sure about this then leave everything unchecked.'; $string['confighiddenuserfields'] = 'Select which user information fields you wish to hide from other users other than course teachers/admins. This will increase student privacy. Hold CTRL key to select multiple fields.'; $string['configidnumber'] = 'This option specifies whether (a) Users are not be asked for an ID number at all, (b) Users are asked for an ID number but can leave it blank or (c) Users are asked for an ID Number and cannot leave it blank. If given the User\'s ID number is displayed in their Profile.'; -$string['configintcachemax'] = 'For internal cache only. Maximum number of records to keep in the cache. Recommended value: 50. Use lower values to reduce memory usage.'; $string['configintro'] = 'On this page you can specify a number of configuration variables that help make Moodle work properly on your server. Don\'t worry too much about it - the defaults will usually work fine and you can always come back to this page later and change these settings.'; $string['configintroadmin'] = 'On this page you should configure your main administrator account which will have complete control over the site. Make sure you give it a secure username and password as well as a valid email address. You can create more admin accounts later on.'; $string['configintrosite'] = 'This page allows you to configure the front page and name of this new site. You can come back here later to change these settings any time using the Administration menus.'; @@ -248,8 +245,6 @@ $string['configmaxconsecutiveidentchars'] = 'Passwords must not have more than this number of consecutive identical characters. Use 0 to disable this check.'; $string['configmaxeditingtime'] = 'This specifies the amount of time people have to re-edit forum postings, glossary comments etc. Usually 30 minutes is a good value.'; $string['configmaxevents'] = 'Events to Lookahead'; -$string['configmemcachedhosts'] = 'For memcached. Comma-separated list of hosts that are running the memcached daemon. Use IP addresses to avoid DNS latency. memcached does not behave well if you add/remove hosts on a running setup.'; -$string['configmemcachedpconn'] = 'For memcached. Use persistent connections. Use carefully -- it can make Apache/PHP crash after a restart of the memcached daemon.'; $string['configmessaging'] = 'Should the messaging system between site users be enabled?'; $string['configmessagingallowemailoverride'] = 'Allow users to have email message notifications sent to an email address other than the email address in their profile'; $string['configmessaginghidereadnotifications'] = 'Hide read notifications of events like forum posts when viewing messaging history'; @@ -286,8 +281,6 @@ $string['configproxytype'] = 'Type of web proxy (PHP5 and cURL extension required for SOCKS5 support).'; $string['configproxyuser'] = 'Username needed to access internet through proxy if required, empty if none (PHP cURL extension required).'; $string['configquarantinedir'] = 'If you want clam AV to move infected files to a quarantine directory, enter it here. It must be writable by the webserver. If you leave this blank, or if you enter a directory that doesn\'t exist or isn\'t writable, infected files will be deleted. Do not include a trailing slash.'; -$string['configrcache'] = 'Use the cache to store database records. Remember to set \'cachetype\' as well!'; -$string['configrcachettl'] = 'Time-to-live for cached records, in seconds. Use a short (<15) value here.'; $string['configrecaptchaprivatekey'] = 'String of characters used to communicate between your Moodle server and the recaptcha server. Obtain one for this site by visiting http://www.google.com/recaptcha'; $string['configrecaptchapublickey'] = 'String of characters used to display the reCAPTCHA element in the signup form. Generated by http://www.google.com/recaptcha'; $string['configrequestcategoryselection'] = 'Allow the selection of a category when requesting a course.'; @@ -597,7 +590,6 @@ $string['incompatibleblocks'] = 'Incompatible blocks'; $string['installhijacked'] = 'Installation must be finished from the original IP address, sorry.'; $string['installsessionerror'] = 'Can not initialise PHP session, please verify that your browser accepts cookies.'; -$string['intcachemax'] = 'Int. cache max'; $string['intlrecommended'] = 'Intl extension is used to improve internationalization support, such as locale aware sorting.'; $string['invalidsection'] = 'Invalid section.'; $string['invaliduserchangeme'] = 'Username "changeme" is reserved -- you cannot create an account with it.'; @@ -681,8 +673,6 @@ $string['mediapluginswfnote'] = 'As a default security measure, normal users should not be allowed to embed swf flash files.'; $string['mediapluginwmv'] = 'Enable .wmv filter'; $string['mediapluginyoutube'] = 'Enable YouTube links filter'; -$string['memcachedhosts'] = 'memcached hosts'; -$string['memcachedpconn'] = 'memcached use persistent connections'; $string['messaging'] = 'Enable messaging system'; $string['messagingallowemailoverride'] = 'Notification email override'; $string['messaginghidereadnotifications'] = 'Hide read notifications'; @@ -866,8 +856,6 @@ $string['questioncwqpfsok'] = 'Good. There are no \'random\' questions in your quizzes that are set up to select questions from a mixture of shared and unshared question categories.'; $string['questiontype'] = 'Question type'; $string['questiontypes'] = 'Question types'; -$string['rcache'] = 'Record cache'; -$string['rcachettl'] = 'Record cache TTL'; $string['recaptchaprivatekey'] = 'ReCAPTCHA private key'; $string['recaptchapublickey'] = 'ReCAPTCHA public key'; $string['register'] = 'Register your site'; diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 65c304649add9..d630e2171d0f8 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -1473,6 +1473,19 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2012111200.01); } + if ($oldversion < 2012111601.01) { + // Clea up after old shared memory caching support. + unset_config('cachetype'); + unset_config('rcache'); + unset_config('rcachettl'); + unset_config('intcachemax'); + unset_config('memcachedhosts'); + unset_config('memcachedpconn'); + + // Main savepoint reached. + upgrade_main_savepoint(true, 2012111601.01); + } + return true; } diff --git a/lib/eaccelerator.class.php b/lib/eaccelerator.class.php deleted file mode 100644 index bde70b9b5061c..0000000000000 --- a/lib/eaccelerator.class.php +++ /dev/null @@ -1,189 +0,0 @@ -. - -/** - * This class abstracts eaccelerator/turckmmcache - * API to provide - * - * - get() - * - set() - * - delete() - * - getforfill() - * - releaseforfill() - * - * Note: do NOT store booleans here. For compatibility with - * memcached, a false value is indistinguisable from a - * "not found in cache" response. - * - * @package core - * @subpackage lib - * @copyright Martin Langhoff - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -/** - * - * @copyright Martin Langhoff - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @package moodlecore - */ -class eaccelerator { - - /** - * @todo Document this function - * - * @global object - */ - function eaccelerator() { - global $CFG; - if ( function_exists('eaccelerator_get')) { - $this->mode = 'eaccelerator'; - } elseif (function_exists('mmcache_get')) { - $this->mode = 'mmcache'; - } else { - debugging("\$CFG->eaccelerator is set to true but the required functions are not available. You need to have either eaccelerator or turckmmcache extensions installed, compiled with the shmem keys option enabled."); - } - - $this->prefix = $CFG->dbname .'|' . $CFG->prefix . '|'; - } - - /** - * The status of the eaccelerator, if it has been established - * this will return true - * - * @return bool - */ - function status() { - if (isset($this->mode)) { - return true; - } - return false; - } - - /** - * @todo Document this function - * - * @param string $key - * @param string $value - * @param int $ttl - * @return mixed - */ - function set($key, $value, $ttl=0) { - $set = $this->mode . '_put'; - $unlock = $this->mode . '_unlock'; - - // we may have acquired a lock via getforfill - // release if it exists - @$unlock($this->prefix . $key . '_forfill'); - - return $set($this->prefix . $key, serialize($value), $ttl); - } - - /** - * @todo Document this function - * - * @param string $key - * @return string|bool String if success else false - */ - function get($key) { - $fn = $this->mode . '_get'; - $rec = $fn($this->prefix . $key); - if (is_null($rec)) { - return false; - } - return unserialize($rec); - } - - /** - * @todo Document this function - * - * @param string $key - * @return mixed - */ - function delete($key) { - $fn = $this->mode . '_rm'; - return $fn($this->prefix . $key); - } - - /** - * In the simple case, this function will - * get the cached value if available. If the entry - * is not cached, it will try to get an exclusive - * lock that announces that this process will - * populate the cache. - * - * If we fail to get the lock -- this means another - * process is doing it. - * so we wait (block) for a few microseconds while we wait for - * the cache to be filled or the lock to timeout. - * - * If you get a false from this call, you _must_ - * populate the cache ASAP or indicate that - * you won't by calling releaseforfill(). - * - * This technique forces serialisation and so helps deal - * with thundering herd scenarios where a lot of clients - * ask the for the same idempotent (and costly) operation. - * The implementation is based on suggestions in this message - * http://marc.theaimsgroup.com/?l=git&m=116562052506776&w=2 - * - * @param $key string - * @return mixed on cache hit, false otherwise - */ - function getforfill ($key) { - $get = $this->mode . '_get'; - $lock = $this->mode . '_lock'; - - $rec = $get($this->prefix . $key); - if (!is_null($rec)) { - return unserialize($rec); - } - if ($lock($this->prefix . $key . '_forfill')) { - // we obtained the _forfill lock - // our caller will compute and set the value - return false; - } - // someone else has the lock - // "block" till we can get the value - // actually, loop .05s waiting for it - for ($n=0;$n<5;$n++) { - usleep(10000); - $rec = $get($this->prefix . $key); - if (!is_null($rec)) { - return unserialize($rec); - } - } - return false; - } - - /** - * Release the exclusive lock obtained by - * getforfill(). See getforfill() - * for more details. - * - * @param $key string - * @return bool - */ - function releaseforfill ($key) { - $unlock = $this->mode . '_unlock'; - return $unlock($this->prefix . $key . '_forfill'); - } -} - -?> \ No newline at end of file diff --git a/lib/memcached.class.php b/lib/memcached.class.php deleted file mode 100644 index 35ac0f4f89205..0000000000000 --- a/lib/memcached.class.php +++ /dev/null @@ -1,160 +0,0 @@ -. - -/** - * @package core - * @subpackage lib - * @copyright Martin Langhoff - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -/** - * This class abstracts PHP's PECL memcached - * API to provide - * - * - get() - * - set() - * - delete() - * - getforfill() - * - releaseforfill() - * - * Author: Martin Langhoff - * - * Note: do NOT store booleans here. With memcached, a false value - * is indistinguisable from a "not found in cache" response. - * - * @package moodlecore - * @copyright Martin Langhoff - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - **/ -class memcached { - - function memcached() { - global $CFG; - - if (!function_exists('memcache_connect')) { - debugging("Memcached is set to true but the memcached extension is not installed"); - return false; - } - $this->_cache = new Memcache; - - $hosts = explode(',', $CFG->memcachedhosts); - if (count($hosts) === 1 && !empty($CFG->memcachedpconn)) { - // the faster pconnect is only available - // for single-server setups - // NOTE: PHP-PECL client is buggy and pconnect() - // will segfault if the server is unavailable - $this->_cache->pconnect($hosts[0]); - } else { - // multi-host setup will share key space - foreach ($hosts as $host) { - $host = trim($host); - $this->_cache->addServer($host); - } - } - - $this->prefix = $CFG->dbname .'|' . $CFG->prefix . '|'; - } - - function status() { - if (is_object($this->_cache)) { - return true; - } - return false; - } - - function set($key, $value, $ttl=0) { - - // we may have acquired a lock via getforfill - // release if it exists - @$this->_cache->delete($this->prefix . $key . '_forfill'); - - return $this->_cache->set($this->prefix . $key, $value, false); - } - - function get($key) { - $rec = $this->_cache->get($this->prefix . $key); - return $rec; - } - - function delete($key) { - return $this->_cache->delete($this->prefix . $key); - } - - /** - * In the simple case, this function will - * get the cached value if available. If the entry - * is not cached, it will try to get an exclusive - * lock that announces that this process will - * populate the cache. - * - * If we fail to get the lock -- this means another - * process is doing it. - * so we wait (block) for a few microseconds while we wait for - * the cache to be filled or the lock to timeout. - * - * If you get a false from this call, you _must_ - * populate the cache ASAP or indicate that - * you won't by calling releaseforfill(). - * - * This technique forces serialisation and so helps deal - * with thundering herd scenarios where a lot of clients - * ask the for the same idempotent (and costly) operation. - * The implementation is based on suggestions in this message - * http://marc.theaimsgroup.com/?l=git&m=116562052506776&w=2 - * - * @param $key string - * @return mixed on cache hit, NULL otherwise - */ - function getforfill ($key) { - - $rec = $this->_cache->get($this->prefix . $key); - if ($rec) { - return $rec; - } - if ($this->_cache->add($this->prefix . $key . '_forfill', 'true', false, 1)) { - // we obtained the _forfill lock - // our caller will compute and set the value - return false; - } - // someone else has the lock - // "block" till we can get the value - // actually, loop .05s waiting for it - for ($n=0;$n<5;$n++) { - usleep(10000); - $rec = $this->_cache->get($this->prefix . $key); - if ($rec) { - return $rec; - } - } - return false; - } - - /** - * Release the exclusive lock obtained by - * getforfill(). See getforfill() - * for more details. - * - * @param $key string - * @return bool - */ - function releaseforfill ($key) { - return $this->_cache->delete($this->prefix . $key . '_forfill'); - } -} diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 7279079f7f077..62648b8a6cb92 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -1589,7 +1589,7 @@ function set_cache_flag($type, $name, $value, $expiry=NULL) { if ($f = $DB->get_record('cache_flags', array('name'=>$name, 'flagtype'=>$type), '*', IGNORE_MULTIPLE)) { // this is a potential problem in DEBUG_DEVELOPER if ($f->value == $value and $f->expiry == $expiry and $f->timemodified == $timemodified) { - return true; //no need to update; helps rcache too + return true; //no need to update } $f->value = $value; $f->expiry = $expiry; @@ -10482,15 +10482,6 @@ function get_performance_info() { $info['txt'] .= "Session: {$info['sessionsize']} "; } -/* if (isset($rcache->hits) && isset($rcache->misses)) { - $info['rcachehits'] = $rcache->hits; - $info['rcachemisses'] = $rcache->misses; - $info['html'] .= 'Record cache hit/miss ratio : '. - "{$rcache->hits}/{$rcache->misses} "; - $info['txt'] .= 'rcache: '. - "{$rcache->hits}/{$rcache->misses} "; - }*/ - if ($stats = cache_helper::get_stats()) { $html = ''; $html .= 'Caches interaction by definition then store'; diff --git a/lib/setup.php b/lib/setup.php index 90c5c73962ebc..1b53e752c3bda 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -344,13 +344,6 @@ */ global $OUTPUT; -/** - * Shared memory cache. - * @global object $MCACHE - * @name $MCACHE - */ -global $MCACHE; - /** * Cache used within grouplib to cache data within current request only. * @@ -592,42 +585,6 @@ die; } -// Shared-Memory cache init -- will set $MCACHE -// $MCACHE is a global object that offers at least add(), set() and delete() -// with similar semantics to the memcached PHP API http://php.net/memcache -// Ensure we define rcache - so we can later check for it -// with a really fast and unambiguous $CFG->rcache === false -if (!empty($CFG->cachetype)) { - if (empty($CFG->rcache)) { - $CFG->rcache = false; - } else { - $CFG->rcache = true; - } - - // do not try to initialize if cache disabled - if (!$CFG->rcache) { - $CFG->cachetype = ''; - } - - if ($CFG->cachetype === 'memcached' && !empty($CFG->memcachedhosts)) { - if (!init_memcached()) { - debugging("Error initialising memcached"); - $CFG->cachetype = ''; - $CFG->rcache = false; - } - } else if ($CFG->cachetype === 'eaccelerator') { - if (!init_eaccelerator()) { - debugging("Error initialising eaccelerator cache"); - $CFG->cachetype = ''; - $CFG->rcache = false; - } - } - -} else { // just make sure it is defined - $CFG->cachetype = ''; - $CFG->rcache = false; -} - // Calculate and set $CFG->ostype to be used everywhere. Possible values are: // - WINDOWS: for any Windows flavour. // - UNIX: for the rest diff --git a/lib/setuplib.php b/lib/setuplib.php index 33894adc14b33..38f746f76ac5c 100644 --- a/lib/setuplib.php +++ b/lib/setuplib.php @@ -1292,41 +1292,6 @@ function make_cache_directory($directory, $exceptiononerror = true) { return make_writable_directory("$CFG->cachedir/$directory", $exceptiononerror); } - -/** - * Initialises an Memcached instance - * @global memcached $MCACHE - * @return boolean Returns true if an mcached instance could be successfully initialised - */ -function init_memcached() { - global $CFG, $MCACHE; - - include_once($CFG->libdir . '/memcached.class.php'); - $MCACHE = new memcached; - if ($MCACHE->status()) { - return true; - } - unset($MCACHE); - return false; -} - -/** - * Initialises an eAccelerator instance - * @global eaccelerator $MCACHE - * @return boolean Returns true if an eAccelerator instance could be successfully initialised - */ -function init_eaccelerator() { - global $CFG, $MCACHE; - - include_once($CFG->libdir . '/eaccelerator.class.php'); - $MCACHE = new eaccelerator; - if ($MCACHE->status()) { - return true; - } - unset($MCACHE); - return false; -} - /** * Checks if current user is a web crawler. * diff --git a/version.php b/version.php index 87c44901a6744..0e2b56e4a01ae 100644 --- a/version.php +++ b/version.php @@ -30,7 +30,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2012111601.00; // YYYYMMDD = weekly release date of this DEV branch +$version = 2012111601.01; // YYYYMMDD = weekly release date of this DEV branch // RR = release increments - 00 in DEV branches // .XX = incremental changes