Skip to content

Commit 30855f3

Browse files
committed
Merge branch 'master' into 3.2-merge
# Conflicts: # .github/workflows/test.yml # src/grpc-client/src/BaseClient.php
2 parents 56ee0ec + ce84a53 commit 30855f3

File tree

7 files changed

+7
-61
lines changed

7 files changed

+7
-61
lines changed

src/Listener/MetricBufferWatcher.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313
namespace Hyperf\Metric\Listener;
1414

1515
use Hyperf\Contract\ConfigInterface;
16-
use Hyperf\Coordinator\Constants;
17-
use Hyperf\Coordinator\CoordinatorManager;
1816
use Hyperf\Coordinator\Timer;
19-
use Hyperf\Coroutine\Coroutine;
2017
use Hyperf\Event\Contract\ListenerInterface;
2118
use Hyperf\Framework\Event\BeforeWorkerStart;
2219
use Hyperf\Metric\Contract\MetricCollectorInterface;
@@ -69,13 +66,8 @@ public function process(object $event): void
6966
}
7067

7168
$timerInterval = $this->config->get('metric.buffer_interval', 5);
72-
$timerId = $this->timer->tick($timerInterval, function () {
69+
$this->timer->tick($timerInterval, function () {
7370
$this->collector->flush();
7471
});
75-
// Clean up timer on worker exit;
76-
Coroutine::create(function () use ($timerId) {
77-
CoordinatorManager::until(Constants::WORKER_EXIT)->yield();
78-
$this->timer->clear($timerId);
79-
});
8072
}
8173
}

src/Listener/OnBeforeHandle.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
use Hyperf\Command\Event\BeforeHandle;
1616
use Hyperf\Contract\ConfigInterface;
1717
use Hyperf\Contract\StdoutLoggerInterface;
18-
use Hyperf\Coordinator\Constants;
19-
use Hyperf\Coordinator\CoordinatorManager;
2018
use Hyperf\Coordinator\Timer;
21-
use Hyperf\Coroutine\Coroutine;
2219
use Hyperf\Event\Contract\ListenerInterface;
2320
use Hyperf\Metric\Contract\MetricFactoryInterface;
2421
use Hyperf\Metric\Event\MetricFactoryReady;
@@ -113,16 +110,11 @@ public function process(object $event): void
113110
);
114111

115112
$timerInterval = $this->config->get('metric.default_metric_interval', 5);
116-
$timerId = $this->timer->tick($timerInterval, function () use ($metrics) {
113+
$this->timer->tick($timerInterval, function () use ($metrics) {
117114
$this->trySet('gc_', $metrics, gc_status());
118115
$this->trySet('', $metrics, getrusage());
119116
$metrics['memory_usage']->set(memory_get_usage());
120117
$metrics['memory_peak_usage']->set(memory_get_peak_usage());
121118
});
122-
// Clean up timer on worker exit;
123-
Coroutine::create(function () use ($timerId) {
124-
CoordinatorManager::until(Constants::WORKER_EXIT)->yield();
125-
$this->timer->clear($timerId);
126-
});
127119
}
128120
}

src/Listener/OnCoroutineServerStart.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
namespace Hyperf\Metric\Listener;
1414

1515
use Hyperf\Contract\ConfigInterface;
16-
use Hyperf\Coordinator\Constants;
17-
use Hyperf\Coordinator\CoordinatorManager;
1816
use Hyperf\Coordinator\Timer;
1917
use Hyperf\Coroutine\Coroutine;
2018
use Hyperf\Event\Contract\ListenerInterface;
@@ -126,17 +124,12 @@ public function process(object $event): void
126124
);
127125

128126
$timerInterval = $this->config->get('metric.default_metric_interval', 5);
129-
$timerId = $this->timer->tick($timerInterval, function () use ($metrics) {
127+
$this->timer->tick($timerInterval, function () use ($metrics) {
130128
$this->trySet('gc_', $metrics, gc_status());
131129
$this->trySet('', $metrics, getrusage());
132130

133131
$metrics['memory_usage']->set(memory_get_usage());
134132
$metrics['memory_peak_usage']->set(memory_get_peak_usage());
135133
});
136-
// Clean up timer on worker exit;
137-
Coroutine::create(function () use ($timerId) {
138-
CoordinatorManager::until(Constants::WORKER_EXIT)->yield();
139-
$this->timer->clear($timerId);
140-
});
141134
}
142135
}

src/Listener/OnMetricFactoryReady.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313
namespace Hyperf\Metric\Listener;
1414

1515
use Hyperf\Contract\ConfigInterface;
16-
use Hyperf\Coordinator\Constants;
17-
use Hyperf\Coordinator\CoordinatorManager;
1816
use Hyperf\Coordinator\Timer;
19-
use Hyperf\Coroutine\Coroutine;
2017
use Hyperf\Engine\Coroutine as Co;
2118
use Hyperf\Event\Contract\ListenerInterface;
2219
use Hyperf\Metric\Contract\MetricFactoryInterface;
@@ -108,7 +105,7 @@ public function process(object $event): void
108105
}
109106

110107
$timerInterval = $this->config->get('metric.default_metric_interval', 5);
111-
$timerId = $this->timer->tick($timerInterval, function () use ($metrics, $serverStatsFactory) {
108+
$this->timer->tick($timerInterval, function () use ($metrics, $serverStatsFactory) {
112109
$this->trySet('', $metrics, Co::stats());
113110
$this->trySet('timer_', $metrics, Timer::stats());
114111

@@ -125,11 +122,5 @@ public function process(object $event): void
125122
$metrics['metric_process_memory_usage']->set(memory_get_usage());
126123
$metrics['metric_process_memory_peak_usage']->set(memory_get_peak_usage());
127124
});
128-
129-
// Clean up timer on worker exit;
130-
Coroutine::create(function () use ($timerId) {
131-
CoordinatorManager::until(Constants::WORKER_EXIT)->yield();
132-
$this->timer->clear($timerId);
133-
});
134125
}
135126
}

src/Listener/OnWorkerStart.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313
namespace Hyperf\Metric\Listener;
1414

1515
use Hyperf\Contract\ConfigInterface;
16-
use Hyperf\Coordinator\Constants;
17-
use Hyperf\Coordinator\CoordinatorManager;
1816
use Hyperf\Coordinator\Timer;
19-
use Hyperf\Coroutine\Coroutine;
2017
use Hyperf\Event\Contract\ListenerInterface;
2118
use Hyperf\Framework\Event\BeforeWorkerStart;
2219
use Hyperf\Metric\Contract\MetricFactoryInterface;
@@ -125,7 +122,7 @@ public function process(object $event): void
125122
);
126123

127124
$timerInterval = $this->config->get('metric.default_metric_interval', 5);
128-
$timerId = $this->timer->tick($timerInterval, function () use ($metrics) {
125+
$this->timer->tick($timerInterval, function () use ($metrics) {
129126
$server = $this->container->get(Server::class);
130127
$serverStats = $server->stats();
131128
$this->trySet('gc_', $metrics, gc_status());
@@ -136,11 +133,6 @@ public function process(object $event): void
136133
$metrics['memory_usage']->set(memory_get_usage());
137134
$metrics['memory_peak_usage']->set(memory_get_peak_usage());
138135
});
139-
// Clean up timer on worker exit;
140-
Coroutine::create(function () use ($timerId) {
141-
CoordinatorManager::until(Constants::WORKER_EXIT)->yield();
142-
$this->timer->clear($timerId);
143-
});
144136
}
145137

146138
private function shouldFireMetricFactoryReadyEvent(int $workerId): bool

src/Listener/PoolWatcher.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313
namespace Hyperf\Metric\Listener;
1414

1515
use Hyperf\Contract\ConfigInterface;
16-
use Hyperf\Coordinator\Constants;
17-
use Hyperf\Coordinator\CoordinatorManager;
1816
use Hyperf\Coordinator\Timer;
19-
use Hyperf\Coroutine\Coroutine;
2017
use Hyperf\Framework\Event\BeforeWorkerStart;
2118
use Hyperf\Metric\Contract\MetricFactoryInterface;
2219
use Hyperf\Pool\Pool;
@@ -69,7 +66,7 @@ public function watch(Pool $pool, string $poolName, int $workerId)
6966

7067
$config = $this->container->get(ConfigInterface::class);
7168
$timerInterval = $config->get('metric.default_metric_interval', 5);
72-
$timerId = $this->timer->tick($timerInterval, function () use (
69+
$this->timer->tick($timerInterval, function () use (
7370
$connectionsInUseGauge,
7471
$connectionsInWaitingGauge,
7572
$maxConnectionsGauge,
@@ -79,10 +76,6 @@ public function watch(Pool $pool, string $poolName, int $workerId)
7976
$connectionsInWaitingGauge->set((float) $pool->getConnectionsInChannel());
8077
$connectionsInUseGauge->set((float) $pool->getCurrentConnections());
8178
});
82-
Coroutine::create(function () use ($timerId) {
83-
CoordinatorManager::until(Constants::WORKER_EXIT)->yield();
84-
$this->timer->clear($timerId);
85-
});
8679
}
8780

8881
abstract protected function getPrefix();

src/Listener/QueueWatcher.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414

1515
use Hyperf\AsyncQueue\Driver\DriverFactory;
1616
use Hyperf\Contract\ConfigInterface;
17-
use Hyperf\Coordinator\Constants;
18-
use Hyperf\Coordinator\CoordinatorManager;
1917
use Hyperf\Coordinator\Timer;
20-
use Hyperf\Coroutine\Coroutine;
2118
use Hyperf\Event\Contract\ListenerInterface;
2219
use Hyperf\Metric\Event\MetricFactoryReady;
2320
use Psr\Container\ContainerInterface;
@@ -71,16 +68,12 @@ public function process(object $event): void
7168

7269
$config = $this->container->get(ConfigInterface::class);
7370
$timerInterval = $config->get('metric.default_metric_interval', 5);
74-
$timerId = $this->timer->tick($timerInterval, function () use ($waiting, $delayed, $failed, $timeout, $queue) {
71+
$this->timer->tick($timerInterval, function () use ($waiting, $delayed, $failed, $timeout, $queue) {
7572
$info = $queue->info();
7673
$waiting->set((float) $info['waiting']);
7774
$delayed->set((float) $info['delayed']);
7875
$failed->set((float) $info['failed']);
7976
$timeout->set((float) $info['timeout']);
8077
});
81-
Coroutine::create(function () use ($timerId) {
82-
CoordinatorManager::until(Constants::WORKER_EXIT)->yield();
83-
$this->timer->clear($timerId);
84-
});
8578
}
8679
}

0 commit comments

Comments
 (0)