From a9cd0b9fe191ecdd1c984c17ac9b44b274018146 Mon Sep 17 00:00:00 2001 From: Rhilip Date: Sun, 17 Mar 2019 20:04:57 +0800 Subject: [PATCH] perf(Config): Remove `configTable_construct_lock` Initialize DynamicConfig Only When Table item is not exist and The Config Component is in Worker #1 --- framework/Component/Config.php | 4 +--- framework/Http/HttpServer.php | 3 --- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/framework/Component/Config.php b/framework/Component/Config.php index 433a170..9fb0fbb 100644 --- a/framework/Component/Config.php +++ b/framework/Component/Config.php @@ -22,13 +22,11 @@ public function onInitialize(array $config = []) // Get \Swoole\Table object From \Server, So that we can share same dynamic config $this->cacheTable = app()->getServ()->configTable; - // If empty Config Table and this component get construct Lock - if ($this->cacheTable->count() == 0 && app()->getServ()->configTable_construct_lock->trylock()) { + if ($this->cacheTable->count() == 0 && app()->getWorker() == 0) { $configs = app()->pdo->createCommand("SELECT `name`,`value` FROM `site_config`")->queryAll(); foreach ($configs as $config) { $this->cacheTable->set($config["name"], [$this->valueField => $config["value"]]); } - app()->getServ()->configTable_construct_lock->unlock(); } } diff --git a/framework/Http/HttpServer.php b/framework/Http/HttpServer.php index da3671e..4bbca3d 100644 --- a/framework/Http/HttpServer.php +++ b/framework/Http/HttpServer.php @@ -160,9 +160,6 @@ protected function createSever() { $configTable->column('data', \Swoole\Table::TYPE_STRING, 256); $configTable->create(); $this->_server->configTable = $configTable; - - // 为 Dynamic Config construct行为创建一个锁,防止不同Worker下的Config同时写入(虽然这种情况也没什么事) - $this->_server->configTable_construct_lock = new \Swoole\Lock(SWOOLE_MUTEX); } // 欢迎信息