protected function getOptimalConnection(): \Plasma\DriverInterface {
        if(\count($this->connections) === 0) {
            $connection = $this->createNewConnection();
            $this->busyConnections->add($connection);
            
            return $connection;
        }
        
        /** @var \Plasma\DriverInterface  $connection */
        $this->connections->rewind();
        $connection = $this->connections->current();
        
        $backlog = $connection->getBacklogLength();
        $state = $connection->getBusyState();
        
        /** @var \Plasma\DriverInterface  $conn */
        foreach($this->connections as $conn) {
            $cbacklog = $conn->getBacklogLength();
            $cstate = $conn->getBusyState();
            
            if($cbacklog === 0 && $conn->getConnectionState() === \Plasma\DriverInterface::CONNECTION_OK && $cstate == \Plasma\DriverInterface::STATE_IDLE) {
                $this->connections->delete($conn);
                $this->busyConnections->add($conn);
                
                return $conn;
            }
            
            if($backlog > $cbacklog || $state > $cstate) {
                $connection = $conn;
                $backlog = $cbacklog;
                $state = $cstate;
            }
        }
        
        if($this->getConnectionCount() < $this->options['connections.max']) {
            $connection = $this->createNewConnection();
        }
        
        $this->connections->delete($connection);
        $this->busyConnections->add($connection);
        
        return $connection;
    }