host, $this->user, $this->password); $connector = new SocketMysqlConnector; $this->connectionPool = new MysqlConnectionPool( config: $config, maxConnections: $this->poolLimit, connector: $connector, ); $this->connection = $connector->connect($config); $this->pdoConnection = new \PDO("mysql:host=$this->host", $this->user, $this->password); $this->pdoConnection->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false); } public function cleanup(): void { $this->connectionPool->close(); $this->connection->close(); } public function benchPdoQueries(): void { $statement = $this->pdoConnection->prepare("SELECT ?"); foreach (\range(1, $this->maxQueries) as $i) { $statement->execute([$i]); $statement->fetch(\PDO::FETCH_ASSOC); } } public function benchSequentialQueries(): void { $statement = $this->connection->prepare("SELECT ?"); foreach (\range(1, $this->maxQueries) as $i) { \iterator_to_array($statement->execute([$i])); } } public function benchConcurrentQueriesUsingSingleConnection(): void { $this->runConcurrentQueries($this->connection); } public function benchConcurrentQueriesUsingConnectionPool(): void { $this->runConcurrentQueries($this->connectionPool); } private function runConcurrentQueries(MysqlLink $link): void { $statement = $link->prepare("SELECT ?"); Future\await(\array_map( fn (int $i) => async(fn () => \iterator_to_array($statement->execute([$i]))), \range(1, $this->maxQueries), )); } }