Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
perf(Config): Remove configTable_construct_lock
Browse files Browse the repository at this point in the history
Initialize DynamicConfig Only When Table item is not exist and The Config
Component is in Worker #1
  • Loading branch information
Rhilip committed Mar 17, 2019
1 parent 233e62d commit a9cd0b9
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 6 deletions.
4 changes: 1 addition & 3 deletions framework/Component/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
3 changes: 0 additions & 3 deletions framework/Http/HttpServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

// 欢迎信息
Expand Down

0 comments on commit a9cd0b9

Please sign in to comment.