Skip to content

Commit

Permalink
feat: 优化consumer减少连接数
Browse files Browse the repository at this point in the history
  • Loading branch information
linkunyuan committed Jan 31, 2024
1 parent a20d833 commit f0f8fc6
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/Consumer/BaseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ public function run($arg)
EventMainServerCreate::listenProcessInfo();
}

// TODO 待优化为移入addTick并从sysinfo取?
// 分片处理
$queues = $this->getListenQueues();
foreach ($queues as $queue) {

$this->addTick($this->args['tick'] ?? 1000, function () use ($queue) {

RedisPool::invoke(function (Redis $Redis) use ($queue) {
$this->addTick($this->args['tick'] ?? 1000, function () use ($queues) {

RedisPool::invoke(function (Redis $Redis) use ($queues) {
foreach ($queues as $queue) {
for ($i = 0; $i < $this->args['limit'] ?? 200; ++$i) {
$data = $Redis->lPop($queue);
if ( ! $data) {
Expand All @@ -93,8 +93,8 @@ public function run($arg)
Trigger::getInstance()->throwable($throwable);
}
}
}, $this->args['pool'] ?? 'default');
});
}
}
}, $this->args['pool'] ?? 'default');
});
}
}

0 comments on commit f0f8fc6

Please sign in to comment.