From 4d2b46267605dc97f3b17a194f4a8b7573196580 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Mon, 5 Jul 2021 16:52:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- System/Pool/ClientsPool.php | 47 ++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/System/Pool/ClientsPool.php b/System/Pool/ClientsPool.php index e8a426e3..5b8d1e35 100644 --- a/System/Pool/ClientsPool.php +++ b/System/Pool/ClientsPool.php @@ -80,29 +80,38 @@ class ClientsPool extends Component Timer::clear($this->creates); $this->creates = -1; } else { - $min = Config::get('databases.pool.min', 1); + $this->heartbeat_flush(); + } + } - $num = []; - $total = 0; - foreach (static::$_connections as $key => $channel) { - if (!isset($num[$key])) { - $num[$key] = 0; - } - if ($channel->length() > $min) { - $this->flush($channel, $min); - } - $length = $channel->length(); - $num[$key] += $length; - if (str_starts_with($key, 'Mysql') && (Snowflake::isWorker() || Snowflake::isTask()) && $length > 0) { - $this->debug('Worker #' . env('worker') . ' use client -> ' . $key . ':' . $length); - } - $total += $length; + /** + * @throws ConfigException + * @throws Exception + */ + private function heartbeat_flush() + { + $min = Config::get('databases.pool.min', 1); + + $num = []; + $total = 0; + foreach (static::$_connections as $key => $channel) { + if (!isset($num[$key])) { + $num[$key] = 0; } - if ($total < 1) { - Timer::clear($this->creates); - $this->creates = -1; + $length = $channel->length(); + if ($length > $min) { + $this->flush($channel, $min); } + $num[$key] += $length; + if (str_starts_with($key, 'Mysql') && (Snowflake::isWorker() || Snowflake::isTask()) && $length > 0) { + $this->debug('Worker #' . env('worker') . ' use client -> ' . $key . ':' . $length); + } + $total += $length; + } + if ($total < 1) { + Timer::clear($this->creates); + $this->creates = -1; } }