diff --git a/app/http.php b/app/http.php index 5a8f16f232..9bd9501fb5 100644 --- a/app/http.php +++ b/app/http.php @@ -249,11 +249,6 @@ $http->on('request', function (SwooleRequest $swooleRequest, SwooleResponse $swo return; } - $pools = $register->get('pools'); /** @var Group $pools */ - var_dump('current console connection'); - var_dump($pools->get('console')->pop()->getID()); - var_dump('current pool size'); - var_dump($pools->get('console')->count()); // Console::log('sleep start'); // System::sleep(3); // Console::log('sleep end'); diff --git a/app/init.php b/app/init.php index 384e8159cd..9782af7265 100644 --- a/app/init.php +++ b/app/init.php @@ -1,205 +1,5 @@ name = $name; - $this->size = $size; - $this->init = $init; - $this->channel = new Channel($size); - } - - /** - * @return string - */ - public function getName(): string - { - return $this->name; - } - - /** - * @return int - */ - public function getSize(): int - { - return $this->size; - } - - /** - * @return int - */ - public function getReconnectAttempts(): int - { - return $this->reconnectAttempts; - } - - /** - * @var int $reconnectAttempts - * @return self - */ - public function setReconnectAttempts(int $reconnectAttempts): self - { - $this->reconnectAttempts = $reconnectAttempts; - return $this; - } - - /** - * @return int - */ - public function getReconnectSleep(): int - { - return $this->reconnectSleep; - } - - /** - * @var int $reconnectSleep - * @return self - */ - public function setReconnectSleep(int $reconnectSleep): self - { - $this->reconnectSleep = $reconnectSleep; - return $this; - } - - /** - * @return self - */ - public function fill(): self - { - if(!$this->channel->isEmpty()) { - return $this; - } - for ($i=0; $i < $this->size; $i++) { - $attempts = 0; - - do { - try { - $attempts++; - $connection = new Connection(($this->init)()); - break; // leave loop if successful - } catch (\Exception $e) { - if ($attempts >= $this->getReconnectAttempts()) { - throw new \Exception('Failed to create connection: ' . $e->getMessage()); - } - sleep($this->getReconnectSleep()); - } - } while ($attempts < $this->getReconnectAttempts()); - - $connection->setID($this->getName().'-'.$i); - - $this->channel->push($connection); - } - - return $this; - } - - /** - * @return Connection - */ - public function pop(): Connection - { - if ($this->channel->isEmpty()) { - throw new Exception('Pool is empty'); - } - - $connection = $this->channel->pop(); - $this->active[$connection->getID()] = $connection; - - return $connection; - } - - /** - * @param Connection $connection - * @return self - */ - public function push(Connection $connection): self - { - $this->channel->push($connection); - unset($this->active[$connection->getID()]); - - return $this; - } - - /** - * @return int - */ - public function count(): int - { - return $this->channel->length(); - } - - /** - * @return self - */ - public function reclaim(): self - { - foreach ($this->active as $connection) { - $this->push($connection); - } - return $this; - } - - /** - * @return bool - */ - public function isEmpty(): bool - { - return $this->channel->isEmpty(); - } - - /** - * @return bool - */ - public function isFull(): bool - { - return $this->channel->isFull(); - } -} /** * Init @@ -270,6 +70,7 @@ use Utopia\CLI\Console; use Utopia\Database\Adapter\MariaDB; use Utopia\Database\Adapter\MySQL; use Utopia\Pools\Group; +use Utopia\Pools\Pool; use Ahc\Jwt\JWT; use Ahc\Jwt\JWTException; use MaxMind\Db\Reader; @@ -821,10 +622,7 @@ $register->set('pools', function () { break; } - - - - $pool = new Pool($name, 64, function () use ($type, $resource, $dsn) { + $pool = new Pool($name, 5, function () use ($type, $resource, $dsn) { // Get Adapter $adapter = null; diff --git a/docker-compose.yml b/docker-compose.yml index f7229ce27b..34a9d5993c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -84,7 +84,6 @@ services: - ./public:/usr/src/code/public - ./src:/usr/src/code/src - ./dev:/usr/local/dev - - ./vendor/utopia-php/framework:/usr/src/code/vendor/utopia-php/framework depends_on: - mariadb - redis @@ -361,7 +360,6 @@ services: volumes: - ./app:/usr/src/code/app - ./src:/usr/src/code/src - #- ./vendor/utopia-php/database:/usr/src/code/vendor/utopia-php/database depends_on: - redis - mariadb @@ -619,7 +617,6 @@ services: volumes: - ./app:/usr/src/code/app - ./src:/usr/src/code/src - #- ./vendor/utopia-php/database:/usr/src/code/vendor/utopia-php/database depends_on: - redis environment: