mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-12 18:02:40 +01:00
Garbage collect TTL'd cache entries from the general cache
Summary: We currently garbage collect general cache entries after a set period of time (30 days by default), but the recent changes to DarkConsole have left us writing a lot of large, short-TTL data to the cache. In addition to a maximum age, GC cache entires after they TTL out. Test Plan: Ran GC daemon, saw TTL'd entries get collected. Inserted a TTL'd entry, saw it get collected by GC. Saw non-ttl'd entries not get collected. Reviewers: chad Reviewed By: chad CC: aran Differential Revision: https://secure.phabricator.com/D4990
This commit is contained in:
parent
c2642c8a40
commit
26aac16346
4 changed files with 25 additions and 0 deletions
2
resources/sql/patches/20130217.cachettl.sql
Normal file
2
resources/sql/patches/20130217.cachettl.sql
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE {$NAMESPACE}_cache.cache_general
|
||||||
|
ADD KEY `key_ttl` (cacheExpires);
|
|
@ -2912,6 +2912,7 @@ phutil_register_library_map(array(
|
||||||
2 => 'PhabricatorPolicyInterface',
|
2 => 'PhabricatorPolicyInterface',
|
||||||
3 => 'PhabricatorSubscribableInterface',
|
3 => 'PhabricatorSubscribableInterface',
|
||||||
4 => 'PhabricatorTokenReceiverInterface',
|
4 => 'PhabricatorTokenReceiverInterface',
|
||||||
|
5 => 'PhabricatorApplicationTransactionInterface',
|
||||||
),
|
),
|
||||||
'PholioMockCommentController' => 'PholioController',
|
'PholioMockCommentController' => 'PholioController',
|
||||||
'PholioMockEditController' => 'PholioController',
|
'PholioMockEditController' => 'PholioController',
|
||||||
|
|
|
@ -15,6 +15,7 @@ final class PhabricatorGarbageCollectorDaemon extends PhabricatorDaemon {
|
||||||
$n_parse = $this->collectParseCaches();
|
$n_parse = $this->collectParseCaches();
|
||||||
$n_markup = $this->collectMarkupCaches();
|
$n_markup = $this->collectMarkupCaches();
|
||||||
$n_tasks = $this->collectArchivedTasks();
|
$n_tasks = $this->collectArchivedTasks();
|
||||||
|
$n_cache_ttl = $this->collectGeneralCacheTTL();
|
||||||
$n_cache = $this->collectGeneralCaches();
|
$n_cache = $this->collectGeneralCaches();
|
||||||
|
|
||||||
$collected = array(
|
$collected = array(
|
||||||
|
@ -23,6 +24,7 @@ final class PhabricatorGarbageCollectorDaemon extends PhabricatorDaemon {
|
||||||
'Differential Parse Cache' => $n_parse,
|
'Differential Parse Cache' => $n_parse,
|
||||||
'Markup Cache' => $n_markup,
|
'Markup Cache' => $n_markup,
|
||||||
'Archived Tasks' => $n_tasks,
|
'Archived Tasks' => $n_tasks,
|
||||||
|
'General Cache TTL' => $n_cache_ttl,
|
||||||
'General Cache Entries' => $n_cache,
|
'General Cache Entries' => $n_cache,
|
||||||
);
|
);
|
||||||
$collected = array_filter($collected);
|
$collected = array_filter($collected);
|
||||||
|
@ -169,6 +171,21 @@ final class PhabricatorGarbageCollectorDaemon extends PhabricatorDaemon {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private function collectGeneralCacheTTL() {
|
||||||
|
$cache = new PhabricatorKeyValueDatabaseCache();
|
||||||
|
$conn_w = $cache->establishConnection('w');
|
||||||
|
|
||||||
|
queryfx(
|
||||||
|
$conn_w,
|
||||||
|
'DELETE FROM %T WHERE cacheExpires < %d
|
||||||
|
ORDER BY cacheExpires ASC LIMIT 100',
|
||||||
|
$cache->getTableName(),
|
||||||
|
time());
|
||||||
|
|
||||||
|
return $conn_w->getAffectedRows();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private function collectGeneralCaches() {
|
private function collectGeneralCaches() {
|
||||||
$key = 'gcdaemon.ttl.general-cache';
|
$key = 'gcdaemon.ttl.general-cache';
|
||||||
$ttl = PhabricatorEnv::getEnvConfig($key);
|
$ttl = PhabricatorEnv::getEnvConfig($key);
|
||||||
|
@ -189,4 +206,5 @@ final class PhabricatorGarbageCollectorDaemon extends PhabricatorDaemon {
|
||||||
return $conn_w->getAffectedRows();
|
return $conn_w->getAffectedRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1125,6 +1125,10 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList {
|
||||||
'type' => 'sql',
|
'type' => 'sql',
|
||||||
'name' => $this->getPatchPath('20130214.token.sql'),
|
'name' => $this->getPatchPath('20130214.token.sql'),
|
||||||
),
|
),
|
||||||
|
'20130217.cachettl.sql' => array(
|
||||||
|
'type' => 'sql',
|
||||||
|
'name' => $this->getPatchPath('20130217.cachettl.sql'),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue