Skip to content

Commit a3fdb20

Browse files
author
epriestley
committedJan 2, 2013
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
1 parent 9cef013 commit a3fdb20

File tree

4 files changed

+56
-50
lines changed

4 files changed

+56
-50
lines changed
 

‎conf/default.conf.php

-14
Original file line numberDiff line numberDiff line change
@@ -1144,20 +1144,6 @@
11441144
// manageable. To run garbage collection, launch a
11451145
// PhabricatorGarbageCollector daemon.
11461146

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

‎src/__phutil_library_map__.php

+2
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,7 @@
843843
'PhabricatorFlagQuery' => 'applications/flag/query/PhabricatorFlagQuery.php',
844844
'PhabricatorFlagsUIEventListener' => 'applications/flag/events/PhabricatorFlagsUIEventListener.php',
845845
'PhabricatorFormExample' => 'applications/uiexample/examples/PhabricatorFormExample.php',
846+
'PhabricatorGarbageCollectorConfigOptions' => 'applications/config/option/PhabricatorGarbageCollectorConfigOptions.php',
846847
'PhabricatorGarbageCollectorDaemon' => 'infrastructure/daemon/PhabricatorGarbageCollectorDaemon.php',
847848
'PhabricatorGitGraphStream' => 'applications/repository/daemon/PhabricatorGitGraphStream.php',
848849
'PhabricatorGitHubConfigOptions' => 'applications/config/option/PhabricatorGitHubConfigOptions.php',
@@ -2180,6 +2181,7 @@
21802181
'PhabricatorFlagListView' => 'AphrontView',
21812182
'PhabricatorFlagsUIEventListener' => 'PhutilEventListener',
21822183
'PhabricatorFormExample' => 'PhabricatorUIExample',
2184+
'PhabricatorGarbageCollectorConfigOptions' => 'PhabricatorApplicationConfigOptions',
21832185
'PhabricatorGarbageCollectorDaemon' => 'PhabricatorDaemon',
21842186
'PhabricatorGitHubConfigOptions' => 'PhabricatorApplicationConfigOptions',
21852187
'PhabricatorGlobalLock' => 'PhutilLock',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
final class PhabricatorGarbageCollectorConfigOptions
4+
extends PhabricatorApplicationConfigOptions {
5+
6+
public function getName() {
7+
return pht("Garbage Collector");
8+
}
9+
10+
public function getDescription() {
11+
return pht("Configure the GC for old logs, caches, etc.");
12+
}
13+
14+
public function getOptions() {
15+
16+
$options = array(
17+
'gcdaemon.ttl.herald-transcripts' => array(
18+
30,
19+
pht('Number of seconds to retain Herald transcripts for.')),
20+
'gcdaemon.ttl.daemon-logs' => array(
21+
14,
22+
pht('Number of seconds to retain Daemon logs for.')),
23+
'gcdaemon.ttl.differential-parse-cache' => array(
24+
14,
25+
pht('Number of seconds to retain Differential parse caches for.')),
26+
'gcdaemon.ttl.markup-cache' => array(
27+
30,
28+
pht('Number of seconds to retain Markup cache entries for.')),
29+
'gcdaemon.ttl.task-archive' => array(
30+
14,
31+
pht('Number of seconds to retain archived background tasks for.')),
32+
'gcdaemon.ttl.general-cache' => array(
33+
30,
34+
pht('Number of seconds to retain general cache entries for.')),
35+
);
36+
37+
$result = array();
38+
foreach ($options as $key => $spec) {
39+
list($default_days, $description) = $spec;
40+
$result[] = $this
41+
->newOption($key, 'int', $default_days * (24 * 60 * 60))
42+
->setDescription($description)
43+
->addExample((7 * 24 * 60 * 60), pht('Retain for 1 week'))
44+
->addExample((14 * 24 * 60 * 60), pht('Retain for 2 weeks'))
45+
->addExample((30 * 24 * 60 * 60), pht('Retain for 30 days'))
46+
->addExample((60 * 24 * 60 * 60), pht('Retain for 60 days'))
47+
->addExample(0, pht('Retain indefinitely'));
48+
}
49+
return $result;
50+
}
51+
52+
}

‎src/infrastructure/daemon/PhabricatorGarbageCollectorDaemon.php

+2-36
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,7 @@
99
final class PhabricatorGarbageCollectorDaemon extends PhabricatorDaemon {
1010

1111
public function run() {
12-
13-
// Keep track of when we start and stop the GC so we can emit useful log
14-
// messages.
15-
$just_ran = false;
16-
1712
do {
18-
$run_at = PhabricatorEnv::getEnvConfig('gcdaemon.run-at');
19-
$run_for = PhabricatorEnv::getEnvConfig('gcdaemon.run-for');
20-
21-
// Just use the default timezone, we don't need to get fancy and try
22-
// to localize this.
23-
$start = strtotime($run_at);
24-
if ($start === false) {
25-
throw new Exception(
26-
"Configuration 'gcdaemon.run-at' could not be parsed: '{$run_at}'.");
27-
}
28-
29-
$now = time();
30-
31-
if ($now < $start || $now > ($start + $run_for)) {
32-
if ($just_ran) {
33-
$this->log("Stopped garbage collector.");
34-
$just_ran = false;
35-
}
36-
// The configuration says we can't collect garbage right now, so
37-
// just sleep until we can.
38-
$this->sleep(300);
39-
continue;
40-
}
41-
42-
if (!$just_ran) {
43-
$this->log("Started garbage collector.");
44-
$just_ran = true;
45-
}
46-
4713
$n_herald = $this->collectHeraldTranscripts();
4814
$n_daemon = $this->collectDaemonLogs();
4915
$n_parse = $this->collectParseCaches();
@@ -70,8 +36,8 @@ public function run() {
7036
if ($total < 100) {
7137
// We didn't max out any of the GCs so we're basically caught up. Ease
7238
// off the GC loop so we don't keep doing table scans just to delete
73-
// a handful of rows.
74-
$this->sleep(300);
39+
// a handful of rows; wake up in a few hours.
40+
$this->sleep(4 * (60 * 60));
7541
} else {
7642
$this->stillWorking();
7743
}

0 commit comments

Comments
 (0)
Failed to load comments.