public function runSet(Set $set, $timeout = null)
    {
        foreach ($this->getServers() as $server) {
            $conn = Connection::connect($server, $timeout);
            if (!Connection::isConnected($conn)) {
                unset($this->servers[$server]);
                continue;
            }

            $this->conn[] = $conn;
        }

        $totalTasks = $set->tasksCount;
        $taskKeys = array_keys($set->tasks);
        $t = 0;

        if ($timeout !== null) {
            $socket_timeout = min(10, (int) $timeout);
        } else {
            $socket_timeout = 10;
        }

        while (!$set->finished()) {
            if ($timeout !== null) {
                if (empty($start)) {
                    $start = microtime(true);
                } else {
                    $now = microtime(true);
                    if ($now - $start >= $timeout) {
                        break;
                    }
                }
            }

            if ($t < $totalTasks) {
                $k = $taskKeys[$t];
                $this->submitTask($set->tasks[$k]);
                if ($set->tasks[$k]->type == Task::JOB_BACKGROUND ||
                    $set->tasks[$k]->type == Task::JOB_HIGH_BACKGROUND ||
                    $set->tasks[$k]->type == Task::JOB_LOW_BACKGROUND ||
                    $set->tasks[$k]->type == Task::JOB_EPOCH) {
                    $set->tasks[$k]->finished = true;
                    --$set->tasksCount;
                }

                ++$t;
            }

            $write = null;
            $except = null;
            $read = $this->conn;
            socket_select($read, $write, $except, $socket_timeout);
            foreach ($read as $socket) {
                $resp = Connection::read($socket);
                if (count($resp)) {
                    $this->handleResponse($resp, $socket, $set);
                }
            }
        }
    }