Skip to content

Commit abc26aa

Browse files
committedFeb 20, 2019
Track total time from task creation to task archival
Summary: Ref T5401. Depends on D20201. Add timestamps to worker tasks to track task creation, and pass that through to archive tasks. This lets us measure the total time the task spent in the queue, not just the duration it was actually running. Also displays this information in the daemon status console; see screenshot: {F6225726} Test Plan: Stopped daemons, ran `bin/search index --all --background` to create lots of tasks, restarted daemons, observed expected values for `dateCreated` and `epochArchived` in the archive worker table. Also tested the changes to `unarchiveTask` by forcing a search task to permanently fail and then `bin/worker retry`ing it. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin, epriestley, PHID-OPKG-gm6ozazyms6q6i22gyam Maniphest Tasks: T5401 Differential Revision: https://secure.phabricator.com/D20200
1 parent 1b83256 commit abc26aa

File tree

5 files changed

+34
-4
lines changed

5 files changed

+34
-4
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE {$NAMESPACE}_worker.worker_archivetask
2+
ADD archivedEpoch INT UNSIGNED NULL;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ALTER TABLE {$NAMESPACE}_worker.worker_activetask
2+
ADD dateCreated int unsigned NOT NULL,
3+
ADD dateModified int unsigned NOT NULL;

‎src/applications/daemon/controller/PhabricatorDaemonConsoleController.php

+23-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function handleRequest(AphrontRequest $request) {
3131
$completed_info[$class] = array(
3232
'n' => 0,
3333
'duration' => 0,
34+
'queueTime' => 0,
3435
);
3536
}
3637
$completed_info[$class]['n']++;
@@ -41,16 +42,33 @@ public function handleRequest(AphrontRequest $request) {
4142
// compute utilization.
4243
$usage_total += $lease_overhead + ($duration / 1000000);
4344
$usage_start = min($usage_start, $completed_task->getDateModified());
45+
46+
$date_archived = $completed_task->getArchivedEpoch();
47+
$queue_seconds = $date_archived - $completed_task->getDateCreated();
48+
49+
// Don't measure queue time for tasks that completed in the same
50+
// epoch-second they were created in.
51+
if ($queue_seconds > 0) {
52+
$sec_in_us = phutil_units('1 second in microseconds');
53+
$queue_us = $queue_seconds * $sec_in_us;
54+
$queue_exclusive_us = $queue_us - $duration;
55+
$queue_exclusive_seconds = $queue_exclusive_us / $sec_in_us;
56+
$rounded = floor($queue_exclusive_seconds);
57+
$completed_info[$class]['queueTime'] += $rounded;
58+
}
4459
}
4560

4661
$completed_info = isort($completed_info, 'n');
4762

4863
$rows = array();
4964
foreach ($completed_info as $class => $info) {
65+
$duration_avg = new PhutilNumber((int)($info['duration'] / $info['n']));
66+
$queue_avg = new PhutilNumber((int)($info['queueTime'] / $info['n']));
5067
$rows[] = array(
5168
$class,
5269
number_format($info['n']),
53-
pht('%s us', new PhutilNumber((int)($info['duration'] / $info['n']))),
70+
pht('%s us', $duration_avg),
71+
pht('%s s', $queue_avg),
5472
);
5573
}
5674

@@ -98,6 +116,7 @@ public function handleRequest(AphrontRequest $request) {
98116
phutil_tag('em', array(), pht('Queue Utilization (Approximate)')),
99117
sprintf('%.1f%%', 100 * $used_time),
100118
null,
119+
null,
101120
);
102121
}
103122

@@ -108,13 +127,15 @@ public function handleRequest(AphrontRequest $request) {
108127
array(
109128
pht('Class'),
110129
pht('Count'),
111-
pht('Avg'),
130+
pht('Average Duration'),
131+
pht('Average Queue Time'),
112132
));
113133
$completed_table->setColumnClasses(
114134
array(
115135
'wide',
116136
'n',
117137
'n',
138+
'n',
118139
));
119140

120141
$completed_panel = id(new PHUIObjectBoxView())

‎src/infrastructure/daemon/workers/storage/PhabricatorWorkerActiveTask.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ protected function getConfiguration() {
1212

1313
$config = array(
1414
self::CONFIG_IDS => self::IDS_COUNTER,
15-
self::CONFIG_TIMESTAMPS => false,
1615
self::CONFIG_KEY_SCHEMA => array(
1716
'taskClass' => array(
1817
'columns' => array('taskClass'),
@@ -118,7 +117,9 @@ public function archiveTask($result, $duration) {
118117
->setPriority($this->getPriority())
119118
->setObjectPHID($this->getObjectPHID())
120119
->setResult($result)
121-
->setDuration($duration);
120+
->setDuration($duration)
121+
->setDateCreated($this->getDateCreated())
122+
->setArchivedEpoch(PhabricatorTime::getNow());
122123

123124
// NOTE: This deletes the active task (this object)!
124125
$archive->save();

‎src/infrastructure/daemon/workers/storage/PhabricatorWorkerArchiveTask.php

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ final class PhabricatorWorkerArchiveTask extends PhabricatorWorkerTask {
88

99
protected $duration;
1010
protected $result;
11+
protected $archivedEpoch;
1112

1213
protected function getConfiguration() {
1314
$parent = parent::getConfiguration();
@@ -22,6 +23,7 @@ protected function getConfiguration() {
2223
$config[self::CONFIG_COLUMN_SCHEMA] = array(
2324
'result' => 'uint32',
2425
'duration' => 'uint64',
26+
'archivedEpoch' => 'epoch?',
2527
) + $config[self::CONFIG_COLUMN_SCHEMA];
2628

2729
$config[self::CONFIG_KEY_SCHEMA] = array(
@@ -85,6 +87,7 @@ public function unarchiveTask() {
8587
->setDataID($this->getDataID())
8688
->setPriority($this->getPriority())
8789
->setObjectPHID($this->getObjectPHID())
90+
->setDateCreated($this->getDateCreated())
8891
->insert();
8992

9093
$this->setDataID(null);

0 commit comments

Comments
 (0)
Failed to load comments.