This commit is contained in:
2021-01-04 18:45:08 +08:00
parent 22b34ac0fc
commit 29fe4f59b2
4 changed files with 8 additions and 3 deletions
+2
View File
@@ -34,6 +34,8 @@ class OnWorkerStart extends Callback
if (!empty($get_name) && !Snowflake::isMac()) { if (!empty($get_name) && !Snowflake::isMac()) {
swoole_set_process_name($get_name); swoole_set_process_name($get_name);
} }
putenv('workerId=' . $worker_id);
if ($worker_id >= $server->setting['worker_num']) { if ($worker_id >= $server->setting['worker_num']) {
fire(Event::SERVER_TASK_START); fire(Event::SERVER_TASK_START);
return; return;
+3
View File
@@ -108,6 +108,9 @@ abstract class Pool extends Component
*/ */
public function createConnect(array $config, string $coroutineName, callable $createHandler): void public function createConnect(array $config, string $coroutineName, callable $createHandler): void
{ {
if ($this->size($coroutineName) > 0) {
return;
}
if (Context::hasContext('create:connect:' . $coroutineName)) { if (Context::hasContext('create:connect:' . $coroutineName)) {
return; return;
} }
+1 -1
View File
@@ -235,7 +235,7 @@ class Connection extends Pool
if (!empty($charset)) { if (!empty($charset)) {
$link->query('SET NAMES ' . $charset); $link->query('SET NAMES ' . $charset);
} }
$this->success('create db client -> ' . $cds . ':' . $this->hasCreate[$coroutineName] . ':' . $this->size($coroutineName)); $this->success('create db client -> ' . $cds . ':' . env('workerId', 0));
$this->incr($coroutineName); $this->incr($coroutineName);
if ($number = Context::getContext('begin_' . $coroutineName, Coroutine::getCid())) { if ($number = Context::getContext('begin_' . $coroutineName, Coroutine::getCid())) {
$number > 0 && $link->beginTransaction(); $number > 0 && $link->beginTransaction();
+1 -1
View File
@@ -78,7 +78,7 @@ class Redis extends Pool
if (empty($config['auth']) || !$redis->auth($config['auth'])) { if (empty($config['auth']) || !$redis->auth($config['auth'])) {
throw new RedisConnectException(sprintf('Redis Error: %s, Host %s, Auth %s', $redis->getLastError(), $config['host'], $config['auth'])); throw new RedisConnectException(sprintf('Redis Error: %s, Host %s, Auth %s', $redis->getLastError(), $config['host'], $config['auth']));
} }
$this->success('create redis client -> ' . $config['host'] . ':' . $this->size($coroutineName)); $this->success('create redis client -> ' . $config['host'] . ':' . env('workerId', 0));
if (!isset($config['read_timeout'])) { if (!isset($config['read_timeout'])) {
$config['read_timeout'] = 10; $config['read_timeout'] = 10;
} }