Browse Source

Merge pull request #4549 from MrPetovan/task/4518-add-memcached-support

[develop] Performance: Add memcached support/Improve database cache (redux)
pull/4561/head
Michael Vogel 3 years ago
committed by GitHub
parent
commit
cc688e2b4f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 437 additions and 221 deletions
  1. +13
    -10
      boot.php
  2. +6
    -6
      database.sql
  3. +5
    -3
      doc/database/db_cache.md
  4. +5
    -3
      doc/htconfig.md
  5. +23
    -8
      friendica_test_data.sql
  6. +21
    -2
      include/api.php
  7. +4
    -0
      src/App.php
  8. +65
    -148
      src/Core/Cache.php
  9. +56
    -0
      src/Core/Cache/DatabaseCacheDriver.php
  10. +50
    -0
      src/Core/Cache/ICacheDriver.php
  11. +77
    -0
      src/Core/Cache/MemcacheCacheDriver.php
  12. +68
    -0
      src/Core/Cache/MemcachedCacheDriver.php
  13. +5
    -5
      src/Core/Session.php
  14. +7
    -28
      src/Core/Session/CacheSessionHandler.php
  15. +26
    -2
      src/Core/Worker.php
  16. +6
    -6
      src/Database/DBStructure.php

+ 13
- 10
boot.php View File

@ -1,6 +1,6 @@
<?php
/**
* @file_tag_unsave_file boot.php
* @file boot.php
* This file defines some global constants and includes the central App class.
*/
@ -21,6 +21,7 @@ require_once __DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'a
use Friendica\App;
use Friendica\Core\Addon;
use Friendica\Core\Cache;
use Friendica\Core\Config;
use Friendica\Core\L10n;
use Friendica\Core\PConfig;
@ -39,7 +40,7 @@ define('FRIENDICA_PLATFORM', 'Friendica');
define('FRIENDICA_CODENAME', 'Asparagus');
define('FRIENDICA_VERSION', '3.6-dev');
define('DFRN_PROTOCOL_VERSION', '2.23');
define('DB_UPDATE_VERSION', 1255);
define('DB_UPDATE_VERSION', 1256);
define('NEW_UPDATE_ROUTINE_VERSION', 1170);
/**
@ -121,18 +122,20 @@ define('LOGGER_ALL', 4);
/**
* @name Cache
* @deprecated since version 3.6
* @see Cache
*
* Cache levels
* @{
*/
define('CACHE_MONTH', 0);
define('CACHE_WEEK', 1);
define('CACHE_DAY', 2);
define('CACHE_HOUR', 3);
define('CACHE_HALF_HOUR', 4);
define('CACHE_QUARTER_HOUR', 5);
define('CACHE_FIVE_MINUTES', 6);
define('CACHE_MINUTE', 7);
define('CACHE_MONTH', Cache::MONTH);
define('CACHE_WEEK', Cache::WEEK);
define('CACHE_DAY', Cache::DAY);
define('CACHE_HOUR', Cache::HOUR);
define('CACHE_HALF_HOUR', Cache::HALF_HOUR);
define('CACHE_QUARTER_HOUR', Cache::QUARTER_HOUR);
define('CACHE_FIVE_MINUTES', Cache::FIVE_MINUTES);
define('CACHE_MINUTE', Cache::MINUTE);
/* @}*/
/**


+ 6
- 6
database.sql View File

@ -1,6 +1,6 @@
-- ------------------------------------------
-- Friendica 3.6-dev (Asparagus)
-- DB_UPDATE_VERSION 1255
-- DB_UPDATE_VERSION 1256
-- ------------------------------------------
@ -55,12 +55,12 @@ CREATE TABLE IF NOT EXISTS `auth_codes` (
-- TABLE cache
--
CREATE TABLE IF NOT EXISTS `cache` (
`k` varbinary(255) NOT NULL COMMENT '',
`v` mediumtext COMMENT '',
`expire_mode` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
`updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
`k` varbinary(255) NOT NULL COMMENT 'cache key',
`v` mediumtext COMMENT 'cached serialized value',
`expires` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of cache expiration',
`updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of cache insertion',
PRIMARY KEY(`k`),
INDEX `expire_mode_updated` (`expire_mode`,`updated`)
INDEX `k_expires` (`k`,`expires`)
) DEFAULT COLLATE utf8mb4_general_ci;
--


+ 5
- 3
doc/database/db_cache.md View File

@ -1,11 +1,13 @@
Table cache
===========
Stores temporary data
| Field | Description | Type | Null | Key | Default | Extra |
| ------------ | ---------------------------------- | ------------ | ---- | --- | ------------------- | ----- |
| k | horizontal width + url or resource | varchar(255) | NO | PRI | NULL | |
| v | OEmbed response from site | text | NO | | NULL | |
| k | cache key | varchar(255) | NO | PRI | NULL | |
| v | cached serialized value | text | NO | | NULL | |
| expires | datetime of cache expiration | datetime | NO | MUL | 0001-01-01 00:00:00 | |
| updated | datetime of cache insertion | datetime | NO | MUL | 0001-01-01 00:00:00 | |
| expire_mode | | int(11) | NO | | 0 | |
Return to [database documentation](help/database)

+ 5
- 3
doc/htconfig.md View File

@ -58,9 +58,11 @@ Example: To set the automatic database cleanup process add this line to your .ht
* **max_processes_backend** - Maximum number of concurrent database processes for background tasks. Default value is 5.
* **max_processes_frontend** - Maximum number of concurrent database processes for foreground tasks. Default value is 20.
* **min_poll_interval** - minimal distance in minutes between two polls for a contact. Default is 1. Reasonable values are between 1 and 59.
* **memcache** (Boolean) - Use memcache. To use memcache the PECL extension "memcache" has to be installed and activated.
* **memcache_host** - Hostname of the memcache daemon. Default is '127.0.0.1'.
* **memcache_port** - Portnumber of the memcache daemon. Default is 11211.
* **session_handler** (database|cache|native) - Whether to use Cache to store session data or to use PHP native session storage. Default value is `database`.
* **cache_driver** (database|memcache|memcached) - Whether to use Memcache or Memcached to store temporary cache. Default value is `database`.
* **memcache_host** - Host name of the memcache daemon. Default is '127.0.0.1'.
* **memcache_port** - Port number of the memcache daemon. Default is 11211.
* **memcached_hosts** - Array of Memcached servers info `[host, port(, weight)]`. Default value is `[['127.0.0.1', 11211]]`.
* **no_count** (Boolean) - Don't do count calculations (currently only when showing albums)
* **no_oembed** (Boolean) - Don't use OEmbed to fetch more information about a link.
* **no_smilies** (Boolean) - Don't show smilies.


+ 23
- 8
friendica_test_data.sql
File diff suppressed because it is too large
View File


+ 21
- 2
include/api.php View File

@ -317,12 +317,16 @@ function api_call(App $a)
/// @TODO round() really everywhere?
logger(
parse_url($a->query_string, PHP_URL_PATH) . ": " . sprintf(
"Database: %s/%s, Network: %s, I/O: %s, Other: %s, Total: %s",
"Database: %s/%s, Cache %s/%s, Network: %s, I/O: %s, Other: %s, Total: %s",
round($a->performance["database"] - $a->performance["database_write"], 3),
round($a->performance["database_write"], 3),
round($a->performance["cache"], 3),
round($a->performance["cache_write"], 3),
round($a->performance["network"], 2),
round($a->performance["file"], 2),
round($duration - ($a->performance["database"] + $a->performance["network"] + $a->performance["file"]), 2),
round($duration - ($a->performance["database"]
+ $a->performance["cache"] + $a->performance["cache_write"]
+ $a->performance["network"] + $a->performance["file"]), 2),
round($duration, 2)
),
LOGGER_DEBUG
@ -344,6 +348,21 @@ function api_call(App $a)
}
}
$o = "Cache Read:\n";
foreach ($a->callstack["cache"] as $func => $time) {
$time = round($time, 3);
if ($time > 0) {
$o .= $func . ": " . $time . "\n";
}
}
$o .= "\nCache Write:\n";
foreach ($a->callstack["cache_write"] as $func => $time) {
$time = round($time, 3);
if ($time > 0) {
$o .= $func . ": " . $time . "\n";
}
}
$o .= "\nNetwork:\n";
foreach ($a->callstack["network"] as $func => $time) {
$time = round($time, 3);


+ 4
- 0
src/App.php View File

@ -148,6 +148,8 @@ class App
$this->performance['start'] = microtime(true);
$this->performance['database'] = 0;
$this->performance['database_write'] = 0;
$this->performance['cache'] = 0;
$this->performance['cache_write'] = 0;
$this->performance['network'] = 0;
$this->performance['file'] = 0;
$this->performance['rendering'] = 0;
@ -157,6 +159,8 @@ class App
$this->callstack['database'] = [];
$this->callstack['database_write'] = [];
$this->callstack['cache'] = [];
$this->callstack['cache_write'] = [];
$this->callstack['network'] = [];
$this->callstack['file'] = [];
$this->callstack['rendering'] = [];


+ 65
- 148
src/Core/Cache.php View File

@ -4,44 +4,45 @@
*/
namespace Friendica\Core;
use Friendica\Core\Cache;
use Friendica\Core\Config;
use Friendica\Database\DBM;
use Friendica\Util\DateTimeFormat;
use dba;
use Memcache;
require_once 'include/dba.php';
/**
* @brief Class for storing data for a short time
*/
class Cache
class Cache extends \Friendica\BaseObject
{
const MONTH = 0;
const WEEK = 1;
const DAY = 2;
const HOUR = 3;
const HALF_HOUR = 4;
const QUARTER_HOUR = 5;
const FIVE_MINUTES = 6;
const MINUTE = 7;
/**
* @brief Check for Memcache and open a connection if configured
*
* @return Memcache|boolean The Memcache object - or "false" if not successful
* @var Cache\ICacheDriver
*/
public static function memcache()
{
if (!class_exists('Memcache', false)) {
return false;
}
if (!Config::get('system', 'memcache')) {
return false;
}
static $driver = null;
$memcache_host = Config::get('system', 'memcache_host', '127.0.0.1');
$memcache_port = Config::get('system', 'memcache_port', 11211);
public static function init()
{
switch(Config::get('system', 'cache_driver', 'database')) {
case 'memcache':
$memcache_host = Config::get('system', 'memcache_host', '127.0.0.1');
$memcache_port = Config::get('system', 'memcache_port', 11211);
$memcache = new Memcache();
self::$driver = new Cache\MemcacheCacheDriver($memcache_host, $memcache_port);
break;
case 'memcached':
$memcached_hosts = Config::get('system', 'memcached_hosts', [['127.0.0.1', 11211]]);
if (!$memcache->connect($memcache_host, $memcache_port)) {
return false;
self::$driver = new Cache\MemcachedCacheDriver($memcached_hosts);
break;
default:
self::$driver = new Cache\DatabaseCacheDriver();
}
return $memcache;
}
/**
@ -51,31 +52,31 @@ class Cache
*
* @return integer The cache duration in seconds
*/
private static function duration($level)
public static function duration($level)
{
switch ($level) {
case CACHE_MONTH:
case self::MONTH:
$seconds = 2592000;
break;
case CACHE_WEEK:
case self::WEEK:
$seconds = 604800;
break;
case CACHE_DAY:
case self::DAY:
$seconds = 86400;
break;
case CACHE_HOUR:
case self::HOUR:
$seconds = 3600;
break;
case CACHE_HALF_HOUR:
case self::HALF_HOUR:
$seconds = 1800;
break;
case CACHE_QUARTER_HOUR:
case self::QUARTER_HOUR:
$seconds = 900;
break;
case CACHE_FIVE_MINUTES:
case self::FIVE_MINUTES:
$seconds = 300;
break;
case CACHE_MINUTE:
case self::MINUTE:
default:
$seconds = 60;
break;
@ -83,6 +84,20 @@ class Cache
return $seconds;
}
/**
* Returns the current cache driver
*
* @return Cache\ICacheDriver
*/
private static function getDriver()
{
if (self::$driver === null) {
self::init();
}
return self::$driver;
}
/**
* @brief Fetch cached data according to the key
*
@ -92,40 +107,13 @@ class Cache
*/
public static function get($key)
{
$memcache = self::memcache();
if (is_object($memcache)) {
// We fetch with the hostname as key to avoid problems with other applications
$cached = $memcache->get(get_app()->get_hostname().":".$key);
$value = @unserialize($cached);
// Only return a value if the serialized value is valid.
// We also check if the db entry is a serialized
// boolean 'false' value (which we want to return).
if ($cached === serialize(false) || $value !== false) {
return $value;
}
return null;
}
$time = microtime(true);
// Frequently clear cache
self::clear();
$return = self::getDriver()->get($key);
$cache = dba::selectFirst('cache', ['v'], ['k' => $key]);
self::getApp()->save_timestamp($time, 'cache');
if (DBM::is_result($cache)) {
$cached = $cache['v'];
$value = @unserialize($cached);
// Only return a value if the serialized value is valid.
// We also check if the db entry is a serialized
// boolean 'false' value (which we want to return).
if ($cached === serialize(false) || $value !== false) {
return $value;
}
}
return null;
return $return;
}
/**
@ -137,20 +125,17 @@ class Cache
* @param mixed $value The value that is about to be stored
* @param integer $duration The cache lifespan
*
* @return void
* @return bool
*/
public static function set($key, $value, $duration = CACHE_MONTH)
public static function set($key, $value, $duration = self::MONTH)
{
// Do we have an installed memcache? Use it instead.
$memcache = self::memcache();
if (is_object($memcache)) {
// We store with the hostname as key to avoid problems with other applications
$memcache->set(get_app()->get_hostname().":".$key, serialize($value), MEMCACHE_COMPRESSED, self::duration($duration));
return;
}
$fields = ['v' => serialize($value), 'expire_mode' => $duration, 'updated' => DateTimeFormat::utcNow()];
$condition = ['k' => $key];
dba::update('cache', $fields, $condition, true);
$time = microtime(true);
$return = self::getDriver()->set($key, $value, $duration);
self::getApp()->save_timestamp($time, 'cache_write');
return $return;
}
/**
@ -160,76 +145,8 @@ class Cache
*
* @return void
*/
public static function clear($max_level = CACHE_MONTH)
public static function clear()
{
// Clear long lasting cache entries only once a day
if (Config::get("system", "cache_cleared_day") < time() - self::duration(CACHE_DAY)) {
if ($max_level == CACHE_MONTH) {
$condition = ["`updated` < ? AND `expire_mode` = ?",
DateTimeFormat::utc("now - 30 days"),
CACHE_MONTH];
dba::delete('cache', $condition);
}
if ($max_level <= CACHE_WEEK) {
$condition = ["`updated` < ? AND `expire_mode` = ?",
DateTimeFormat::utc("now - 7 days"),
CACHE_WEEK];
dba::delete('cache', $condition);
}
if ($max_level <= CACHE_DAY) {
$condition = ["`updated` < ? AND `expire_mode` = ?",
DateTimeFormat::utc("now - 1 days"),
CACHE_DAY];
dba::delete('cache', $condition);
}
Config::set("system", "cache_cleared_day", time());
}
if (($max_level <= CACHE_HOUR) && (Config::get("system", "cache_cleared_hour")) < time() - self::duration(CACHE_HOUR)) {
$condition = ["`updated` < ? AND `expire_mode` = ?",
DateTimeFormat::utc("now - 1 hours"),
CACHE_HOUR];
dba::delete('cache', $condition);
Config::set("system", "cache_cleared_hour", time());
}
if (($max_level <= CACHE_HALF_HOUR) && (Config::get("system", "cache_cleared_half_hour")) < time() - self::duration(CACHE_HALF_HOUR)) {
$condition = ["`updated` < ? AND `expire_mode` = ?",
DateTimeFormat::utc("now - 30 minutes"),
CACHE_HALF_HOUR];
dba::delete('cache', $condition);
Config::set("system", "cache_cleared_half_hour", time());
}
if (($max_level <= CACHE_QUARTER_HOUR) && (Config::get("system", "cache_cleared_quarter_hour")) < time() - self::duration(CACHE_QUARTER_HOUR)) {
$condition = ["`updated` < ? AND `expire_mode` = ?",
DateTimeFormat::utc("now - 15 minutes"),
CACHE_QUARTER_HOUR];
dba::delete('cache', $condition);
Config::set("system", "cache_cleared_quarter_hour", time());
}
if (($max_level <= CACHE_FIVE_MINUTES) && (Config::get("system", "cache_cleared_five_minute")) < time() - self::duration(CACHE_FIVE_MINUTES)) {
$condition = ["`updated` < ? AND `expire_mode` = ?",
DateTimeFormat::utc("now - 5 minutes"),
CACHE_FIVE_MINUTES];
dba::delete('cache', $condition);
Config::set("system", "cache_cleared_five_minute", time());
}
if (($max_level <= CACHE_MINUTE) && (Config::get("system", "cache_cleared_minute")) < time() - self::duration(CACHE_MINUTE)) {
$condition = ["`updated` < ? AND `expire_mode` = ?",
DateTimeFormat::utc("now - 1 minutes"),
CACHE_MINUTE];
dba::delete('cache', $condition);
Config::set("system", "cache_cleared_minute", time());
}
return self::getDriver()->clear();
}
}

+ 56
- 0
src/Core/Cache/DatabaseCacheDriver.php View File

@ -0,0 +1,56 @@
<?php
namespace Friendica\Core\Cache;
use dba;
use Friendica\Core\Cache;
use Friendica\Database\DBM;
use Friendica\Util\DateTimeFormat;
/**
* Database Cache Driver
*
* @author Hypolite Petovan <mrpetovan@gmail.com>
*/
class DatabaseCacheDriver implements ICacheDriver
{
public function get($key)
{
$cache = dba::selectFirst('cache', ['v'], ['`k` = ? AND `expires` >= ?', $key, DateTimeFormat::utcNow()]);
if (DBM::is_result($cache)) {
$cached = $cache['v'];
$value = @unserialize($cached);
// Only return a value if the serialized value is valid.
// We also check if the db entry is a serialized
// boolean 'false' value (which we want to return).
if ($cached === serialize(false) || $value !== false) {
return $value;
}
}
return null;
}
public function set($key, $value, $duration = Cache::MONTH)
{
$fields = [
'v' => serialize($value),
'expires' => DateTimeFormat::utc('now + ' . Cache::duration($duration) . ' seconds'),
'updated' => DateTimeFormat::utcNow()
];
return dba::update('cache', $fields, ['k' => $key], true);
}
public function delete($key)
{
return dba::delete('cache', ['k' => $key]);
}
public function clear()
{
return dba::delete('cache', ['`expires` < NOW()']);
}
}

+ 50
- 0
src/Core/Cache/ICacheDriver.php View File

@ -0,0 +1,50 @@
<?php
namespace Friendica\Core\Cache;
use Friendica\Core\Cache;
/**
* Cache Driver Interface
*
* @author Hypolite Petovan <mrpetovan@gmail.com>
*/
interface ICacheDriver
{
/**
* Fetches cached data according to the key
*
* @param string $key The key to the cached data
*
* @return mixed Cached $value or "null" if not found
*/
public function get($key);
/**
* Stores data in the cache identified by the key. The input $value can have multiple formats.
*
* @param string $key The cache key
* @param mixed $value The value to store
* @param integer $duration The cache lifespan, must be one of the Cache constants
*
* @return bool
*/
public function set($key, $value, $duration = Cache::MONTH);
/**
* Delete a key from the cache
*
* @param string $key
*
* @return bool
*/
public function delete($key);
/**
* Remove outdated data from the cache
*
* @return bool
*/
public function clear();
}

+ 77
- 0
src/Core/Cache/MemcacheCacheDriver.php View File

@ -0,0 +1,77 @@
<?php
namespace Friendica\Core\Cache;
use Friendica\BaseObject;
use Friendica\Core\Cache;
/**
* Memcache Cache Driver
*
* @author Hypolite Petovan <mrpetovan@gmail.com>
*/
class MemcacheCacheDriver extends BaseObject implements ICacheDriver
{
/**
* @var Memcache
*/
private $memcache;
public function __construct($memcache_host, $memcache_port)
{
if (!class_exists('Memcache', false)) {
throw new \Exception('Memcache class isn\'t available');
}
$this->memcache = new \Memcache();
if (!$this->memcache->connect($memcache_host, $memcache_port)) {
throw new \Exception('Expected Memcache server at ' . $memcache_host . ':' . $memcache_port . ' isn\'t available');
}
}
public function get($key)
{
$return = null;
// We fetch with the hostname as key to avoid problems with other applications
$cached = $this->memcache->get(self::getApp()->get_hostname() . ':' . $key);
// @see http://php.net/manual/en/memcache.get.php#84275
if (is_bool($cached) || is_double($cached) || is_long($cached)) {
return $return;
}
$value = @unserialize($cached);
// Only return a value if the serialized value is valid.
// We also check if the db entry is a serialized
// boolean 'false' value (which we want to return).
if ($cached === serialize(false) || $value !== false) {
$return = $value;
}
return $return;
}
public function set($key, $value, $duration = Cache::MONTH)
{
// We store with the hostname as key to avoid problems with other applications
return $this->memcache->set(
self::getApp()->get_hostname() . ":" . $key,
serialize($value),
MEMCACHE_COMPRESSED,
Cache::duration($duration)
);
}
public function delete($key)
{
return $this->memcache->delete($key);
}
public function clear()
{
return true;
}
}

+ 68
- 0
src/Core/Cache/MemcachedCacheDriver.php View File

@ -0,0 +1,68 @@
<?php
namespace Friendica\Core\Cache;
use Friendica\BaseObject;
use Friendica\Core\Cache;
/**
* Memcached Cache Driver
*
* @author Hypolite Petovan <mrpetovan@gmail.com>
*/
class MemcachedCacheDriver extends BaseObject implements ICacheDriver
{
/**
* @var Memcached
*/
private $memcached;
public function __construct(array $memcached_hosts)
{
if (!class_exists('Memcached', false)) {
throw new \Exception('Memcached class isn\'t available');
}
$this->memcached = new \Memcached();
$this->memcached->addServers($memcached_hosts);
if (count($this->memcached->getServerList()) == 0) {
throw new \Exception('Expected Memcached servers aren\'t available, config:' . var_export($memcached_hosts, true));
}
}
public function get($key)
{
$return = null;
// We fetch with the hostname as key to avoid problems with other applications
$value = $this->memcached->get(self::getApp()->get_hostname() . ':' . $key);
if ($this->memcached->getResultCode() === \Memcached::RES_SUCCESS) {
$return = $value;
}
return $return;
}
public function set($key, $value, $duration = Cache::MONTH)
{
// We store with the hostname as key to avoid problems with other applications
return $this->memcached->set(
self::getApp()->get_hostname() . ":" . $key,
$value,
Cache::duration($duration)
);
}
public function delete($key)
{
return $this->memcached->delete($key);
}
public function clear()
{
return true;
}
}

+ 5
- 5
src/Core/Session.php View File

@ -5,8 +5,8 @@
*/
namespace Friendica\Core;
use Friendica\Core\Session\CacheSessionHandler;
use Friendica\Core\Session\DatabaseSessionHandler;
use Friendica\Core\Session\MemcacheSessionHandler;
/**
* High-level Session service class
@ -28,10 +28,10 @@ class Session
ini_set('session.cookie_secure', 1);
}
if (!Config::get('system', 'disable_database_session')) {
$memcache = Cache::memcache();
if (is_object($memcache)) {
$SessionHandler = new MemcacheSessionHandler($memcache);
$session_handler = Config::get('system', 'session_handler', 'database');
if ($session_handler != 'native') {
if ($session_handler == 'cache' && Config::get('system', 'cache_driver', 'database') != 'database') {
$SessionHandler = new CacheSessionHandler();
} else {
$SessionHandler = new DatabaseSessionHandler();
}


src/Core/Session/MemcacheSessionHandler.php → src/Core/Session/CacheSessionHandler.php View File


+ 26
- 2
src/Core/Worker.php View File

@ -325,6 +325,8 @@ class Worker
$a->performance["start"] = microtime(true);
$a->performance["database"] = 0;
$a->performance["database_write"] = 0;
$a->performance["cache"] = 0;
$a->performance["cache_write"] = 0;
$a->performance["network"] = 0;
$a->performance["file"] = 0;
$a->performance["rendering"] = 0;
@ -409,6 +411,24 @@ class Worker
}
}
}
if (isset($a->callstack["dache"])) {
$o .= "\nCache Read:\n";
foreach ($a->callstack["dache"] as $func => $time) {
$time = round($time, 3);
if ($time > 0) {
$o .= $func.": ".$time."\n";
}
}
}
if (isset($a->callstack["dache_write"])) {
$o .= "\nCache Write:\n";
foreach ($a->callstack["dache_write"] as $func => $time) {
$time = round($time, 3);
if ($time > 0) {
$o .= $func.": ".$time."\n";
}
}
}
if (isset($a->callstack["network"])) {
$o .= "\nNetwork:\n";
foreach ($a->callstack["network"] as $func => $time) {
@ -422,12 +442,16 @@ class Worker
logger(
"ID ".$queue["id"].": ".$funcname.": ".sprintf(
"DB: %s/%s, Net: %s, I/O: %s, Other: %s, Total: %s".$o,
"DB: %s/%s, Cache: %s/%s, Net: %s, I/O: %s, Other: %s, Total: %s".$o,
number_format($a->performance["database"] - $a->performance["database_write"], 2),
number_format($a->performance["database_write"], 2),
number_format($a->performance["cache"], 2),
number_format($a->performance["cache_write"], 2),
number_format($a->performance["network"], 2),
number_format($a->performance["file"], 2),
number_format($duration - ($a->performance["database"] + $a->performance["network"] + $a->performance["file"]), 2),
number_format($duration - ($a->performance["database"]
+ $a->performance["cache"] + $a->performance["cache_write"]
+ $a->performance["network"] + $a->performance["file"]), 2),
number_format($duration, 2)
),
LOGGER_DEBUG


+ 6
- 6
src/Database/DBStructure.php View File

@ -712,16 +712,16 @@ class DBStructure
]
];
$database["cache"] = [
"comment" => "Used to store different data that doesn't to be stored for a long time",
"comment" => "Stores temporary data",
"fields" => [
"k" => ["type" => "varbinary(255)", "not null" => "1", "primary" => "1", "comment" => ""],
"v" => ["type" => "mediumtext", "comment" => ""],
"expire_mode" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
"updated" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
"k" => ["type" => "varbinary(255)", "not null" => "1", "primary" => "1", "comment" => "cache key"],
"v" => ["type" => "mediumtext", "comment" => "cached serialized value"],
"expires" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "datetime of cache expiration"],
"updated" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "datetime of cache insertion"],
],
"indexes" => [
"PRIMARY" => ["k"],
"expire_mode_updated" => ["expire_mode", "updated"],
"k_expires" => ["k", "expires"],
]
];
$database["challenge"] = [


Loading…
Cancel
Save