1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-29 10:12:41 +01:00

Move GC into PHP and simplify it

Summary:
  - Move GC options into PHP.
  - Remove the "run at" and "run for" options. The GC daemon doesn't actually do any table scans, is very gentle, and runs for like 3 seconds per day in any normal install. Just limit it to running once every 4 hours when it's caught up and call it a day.

Test Plan: Edited GC options.

Reviewers: btrahan, codeblock

Reviewed By: codeblock

CC: aran

Maniphest Tasks: T2255

Differential Revision: https://secure.phabricator.com/D4321
This commit is contained in:
epriestley 2013-01-02 14:03:08 -08:00
parent 9cef013def
commit a3fdb20a8e
4 changed files with 56 additions and 50 deletions

View file

@ -1144,20 +1144,6 @@ return array(
// manageable. To run garbage collection, launch a // manageable. To run garbage collection, launch a
// PhabricatorGarbageCollector daemon. // PhabricatorGarbageCollector daemon.
// Since the GC daemon can issue large writes and table scans, you may want to
// run it only during off hours or make sure it is scheduled so it doesn't
// overlap with backups. This determines when the daemon can start running
// each day.
'gcdaemon.run-at' => '12 AM',
// How many seconds after 'gcdaemon.run-at' the daemon may collect garbage
// for. By default it runs continuously, but you can set it to run for a
// limited period of time. For instance, if you do backups at 3 AM, you might
// run garbage collection for an hour beforehand. This is not a high-precision
// limit so you may want to leave some room for the GC to actually stop, and
// if you set it to something like 3 seconds you're on your own.
'gcdaemon.run-for' => 24 * 60 * 60,
// These 'ttl' keys configure how much old data the GC daemon keeps around. // These 'ttl' keys configure how much old data the GC daemon keeps around.
// Objects older than the ttl will be collected. Set any value to 0 to store // Objects older than the ttl will be collected. Set any value to 0 to store
// data indefinitely. // data indefinitely.

View file

@ -843,6 +843,7 @@ phutil_register_library_map(array(
'PhabricatorFlagQuery' => 'applications/flag/query/PhabricatorFlagQuery.php', 'PhabricatorFlagQuery' => 'applications/flag/query/PhabricatorFlagQuery.php',
'PhabricatorFlagsUIEventListener' => 'applications/flag/events/PhabricatorFlagsUIEventListener.php', 'PhabricatorFlagsUIEventListener' => 'applications/flag/events/PhabricatorFlagsUIEventListener.php',
'PhabricatorFormExample' => 'applications/uiexample/examples/PhabricatorFormExample.php', 'PhabricatorFormExample' => 'applications/uiexample/examples/PhabricatorFormExample.php',
'PhabricatorGarbageCollectorConfigOptions' => 'applications/config/option/PhabricatorGarbageCollectorConfigOptions.php',
'PhabricatorGarbageCollectorDaemon' => 'infrastructure/daemon/PhabricatorGarbageCollectorDaemon.php', 'PhabricatorGarbageCollectorDaemon' => 'infrastructure/daemon/PhabricatorGarbageCollectorDaemon.php',
'PhabricatorGitGraphStream' => 'applications/repository/daemon/PhabricatorGitGraphStream.php', 'PhabricatorGitGraphStream' => 'applications/repository/daemon/PhabricatorGitGraphStream.php',
'PhabricatorGitHubConfigOptions' => 'applications/config/option/PhabricatorGitHubConfigOptions.php', 'PhabricatorGitHubConfigOptions' => 'applications/config/option/PhabricatorGitHubConfigOptions.php',
@ -2180,6 +2181,7 @@ phutil_register_library_map(array(
'PhabricatorFlagListView' => 'AphrontView', 'PhabricatorFlagListView' => 'AphrontView',
'PhabricatorFlagsUIEventListener' => 'PhutilEventListener', 'PhabricatorFlagsUIEventListener' => 'PhutilEventListener',
'PhabricatorFormExample' => 'PhabricatorUIExample', 'PhabricatorFormExample' => 'PhabricatorUIExample',
'PhabricatorGarbageCollectorConfigOptions' => 'PhabricatorApplicationConfigOptions',
'PhabricatorGarbageCollectorDaemon' => 'PhabricatorDaemon', 'PhabricatorGarbageCollectorDaemon' => 'PhabricatorDaemon',
'PhabricatorGitHubConfigOptions' => 'PhabricatorApplicationConfigOptions', 'PhabricatorGitHubConfigOptions' => 'PhabricatorApplicationConfigOptions',
'PhabricatorGlobalLock' => 'PhutilLock', 'PhabricatorGlobalLock' => 'PhutilLock',

View file

@ -0,0 +1,52 @@
<?php
final class PhabricatorGarbageCollectorConfigOptions
extends PhabricatorApplicationConfigOptions {
public function getName() {
return pht("Garbage Collector");
}
public function getDescription() {
return pht("Configure the GC for old logs, caches, etc.");
}
public function getOptions() {
$options = array(
'gcdaemon.ttl.herald-transcripts' => array(
30,
pht('Number of seconds to retain Herald transcripts for.')),
'gcdaemon.ttl.daemon-logs' => array(
14,
pht('Number of seconds to retain Daemon logs for.')),
'gcdaemon.ttl.differential-parse-cache' => array(
14,
pht('Number of seconds to retain Differential parse caches for.')),
'gcdaemon.ttl.markup-cache' => array(
30,
pht('Number of seconds to retain Markup cache entries for.')),
'gcdaemon.ttl.task-archive' => array(
14,
pht('Number of seconds to retain archived background tasks for.')),
'gcdaemon.ttl.general-cache' => array(
30,
pht('Number of seconds to retain general cache entries for.')),
);
$result = array();
foreach ($options as $key => $spec) {
list($default_days, $description) = $spec;
$result[] = $this
->newOption($key, 'int', $default_days * (24 * 60 * 60))
->setDescription($description)
->addExample((7 * 24 * 60 * 60), pht('Retain for 1 week'))
->addExample((14 * 24 * 60 * 60), pht('Retain for 2 weeks'))
->addExample((30 * 24 * 60 * 60), pht('Retain for 30 days'))
->addExample((60 * 24 * 60 * 60), pht('Retain for 60 days'))
->addExample(0, pht('Retain indefinitely'));
}
return $result;
}
}

View file

@ -9,41 +9,7 @@
final class PhabricatorGarbageCollectorDaemon extends PhabricatorDaemon { final class PhabricatorGarbageCollectorDaemon extends PhabricatorDaemon {
public function run() { public function run() {
// Keep track of when we start and stop the GC so we can emit useful log
// messages.
$just_ran = false;
do { do {
$run_at = PhabricatorEnv::getEnvConfig('gcdaemon.run-at');
$run_for = PhabricatorEnv::getEnvConfig('gcdaemon.run-for');
// Just use the default timezone, we don't need to get fancy and try
// to localize this.
$start = strtotime($run_at);
if ($start === false) {
throw new Exception(
"Configuration 'gcdaemon.run-at' could not be parsed: '{$run_at}'.");
}
$now = time();
if ($now < $start || $now > ($start + $run_for)) {
if ($just_ran) {
$this->log("Stopped garbage collector.");
$just_ran = false;
}
// The configuration says we can't collect garbage right now, so
// just sleep until we can.
$this->sleep(300);
continue;
}
if (!$just_ran) {
$this->log("Started garbage collector.");
$just_ran = true;
}
$n_herald = $this->collectHeraldTranscripts(); $n_herald = $this->collectHeraldTranscripts();
$n_daemon = $this->collectDaemonLogs(); $n_daemon = $this->collectDaemonLogs();
$n_parse = $this->collectParseCaches(); $n_parse = $this->collectParseCaches();
@ -70,8 +36,8 @@ final class PhabricatorGarbageCollectorDaemon extends PhabricatorDaemon {
if ($total < 100) { if ($total < 100) {
// We didn't max out any of the GCs so we're basically caught up. Ease // We didn't max out any of the GCs so we're basically caught up. Ease
// off the GC loop so we don't keep doing table scans just to delete // off the GC loop so we don't keep doing table scans just to delete
// a handful of rows. // a handful of rows; wake up in a few hours.
$this->sleep(300); $this->sleep(4 * (60 * 60));
} else { } else {
$this->stillWorking(); $this->stillWorking();
} }