示例#1
0
文件: wrk.py 项目: ondrej-fabry/csit
def run_wrk(tg_node, profile_name, tg_numa, test_type, warm_up=False):
    """Send the traffic as defined in the profile.

    :param tg_node: Traffic generator node.
    :param profile_name: The name of wrk traffic profile.
    :param tg_numa: Numa node on which wrk will run.
    :param test_type: The type of the tests: cps, rps, bw
    :param warm_up: If True, warm-up traffic is generated before test traffic.
    :type profile_name: str
    :type tg_node: dict
    :type tg_numa: int
    :type test_type: str
    :type warm_up: bool
    :returns: Message with measured data.
    :rtype: str
    :raises: RuntimeError if node type is not a TG.
    """

    if tg_node['type'] != NodeType.TG:
        raise RuntimeError('Node type is not a TG.')

    # Parse and validate the profile
    profile_path = (
        "resources/traffic_profiles/wrk/{0}.yaml".format(profile_name))
    profile = WrkTrafficProfile(profile_path).traffic_profile

    cores = CpuUtils.cpu_list_per_node(tg_node, tg_numa)
    first_cpu = cores[profile["first-cpu"]]

    if len(profile["urls"]) == 1 and profile["cpus"] == 1:
        params = [
            "traffic_1_url_1_core",
            str(first_cpu),
            str(profile["nr-of-threads"]),
            str(profile["nr-of-connections"]),
            "{0}s".format(profile["duration"]),
            "'{0}'".format(profile["header"]),
            str(profile["timeout"]),
            str(profile["script"]),
            str(profile["latency"]), "'{0}'".format(" ".join(profile["urls"]))
        ]
        if warm_up:
            warm_up_params = deepcopy(params)
            warm_up_params[4] = "10s"
    elif len(profile["urls"]) == profile["cpus"]:
        params = [
            "traffic_n_urls_n_cores",
            str(first_cpu),
            str(profile["nr-of-threads"]),
            str(profile["nr-of-connections"]),
            "{0}s".format(profile["duration"]),
            "'{0}'".format(profile["header"]),
            str(profile["timeout"]),
            str(profile["script"]),
            str(profile["latency"]), "'{0}'".format(" ".join(profile["urls"]))
        ]
        if warm_up:
            warm_up_params = deepcopy(params)
            warm_up_params[4] = "10s"
    else:
        params = [
            "traffic_n_urls_m_cores",
            str(first_cpu),
            str(profile["cpus"] / len(profile["urls"])),
            str(profile["nr-of-threads"]),
            str(profile["nr-of-connections"]),
            "{0}s".format(profile["duration"]),
            "'{0}'".format(profile["header"]),
            str(profile["timeout"]),
            str(profile["script"]),
            str(profile["latency"]), "'{0}'".format(" ".join(profile["urls"]))
        ]
        if warm_up:
            warm_up_params = deepcopy(params)
            warm_up_params[5] = "10s"

    args = " ".join(params)

    ssh = SSH()
    ssh.connect(tg_node)

    if warm_up:
        warm_up_args = " ".join(warm_up_params)
        ret, _, _ = ssh.exec_command(
            "{0}/resources/tools/wrk/wrk_utils.sh {1}".format(
                Constants.REMOTE_FW_DIR, warm_up_args),
            timeout=1800)
        if int(ret) != 0:
            raise RuntimeError('wrk runtime error.')
        sleep(60)

    ret, stdout, _ = ssh.exec_command(
        "{0}/resources/tools/wrk/wrk_utils.sh {1}".format(
            Constants.REMOTE_FW_DIR, args),
        timeout=1800)
    if int(ret) != 0:
        raise RuntimeError('wrk runtime error.')

    stats = _parse_wrk_output(stdout)

    log_msg = "\nMeasured values:\n"
    if test_type == "cps":
        log_msg += "Connections/sec: Avg / Stdev / Max  / +/- Stdev\n"
        for item in stats["rps-stats-lst"]:
            log_msg += "{0} / {1} / {2} / {3}\n".format(*item)
        log_msg += "Total cps: {0}cps\n".format(stats["rps-sum"])
    elif test_type == "rps":
        log_msg += "Requests/sec: Avg / Stdev / Max  / +/- Stdev\n"
        for item in stats["rps-stats-lst"]:
            log_msg += "{0} / {1} / {2} / {3}\n".format(*item)
        log_msg += "Total rps: {0}rps\n".format(stats["rps-sum"])
    elif test_type == "bw":
        log_msg += "Transfer/sec: {0}Bps".format(stats["bw-sum"])

    logger.info(log_msg)

    return log_msg
示例#2
0
def run_wrk(tg_node, profile_name, tg_numa, test_type, warm_up=False):
    """Send the traffic as defined in the profile.

    :param tg_node: Traffic generator node.
    :param profile_name: The name of wrk traffic profile.
    :param tg_numa: Numa node on which wrk will run.
    :param test_type: The type of the tests: cps, rps, bw
    :param warm_up: If True, warm-up traffic is generated before test traffic.
    :type profile_name: str
    :type tg_node: dict
    :type tg_numa: int
    :type test_type: str
    :type warm_up: bool
    :returns: Message with measured data.
    :rtype: str
    :raises: RuntimeError if node type is not a TG.
    """

    if tg_node[u"type"] != NodeType.TG:
        raise RuntimeError(u"Node type is not a TG.")

    # Parse and validate the profile
    profile_path = f"resources/traffic_profiles/wrk/{profile_name}.yaml"
    profile = WrkTrafficProfile(profile_path).traffic_profile

    cores = CpuUtils.cpu_list_per_node(tg_node, tg_numa)
    first_cpu = cores[profile[u"first-cpu"]]

    if len(profile[u"urls"]) == 1 and profile[u"cpus"] == 1:
        params = [
            u"traffic_1_url_1_core",
            str(first_cpu),
            str(profile[u"nr-of-threads"]),
            str(profile[u"nr-of-connections"]), f"{profile[u'duration']}s",
            f"'{profile[u'header']}'",
            str(profile[u"timeout"]),
            str(profile[u"script"]),
            str(profile[u"latency"]), f"'{u' '.join(profile[u'urls'])}'"
        ]
        if warm_up:
            warm_up_params = deepcopy(params)
            warm_up_params[4] = u"10s"
    elif len(profile[u"urls"]) == profile[u"cpus"]:
        params = [
            u"traffic_n_urls_n_cores",
            str(first_cpu),
            str(profile[u"nr-of-threads"]),
            str(profile[u"nr-of-connections"]), f"{profile[u'duration']}s",
            f"'{profile[u'header']}'",
            str(profile[u"timeout"]),
            str(profile[u"script"]),
            str(profile[u"latency"]), f"'{u' '.join(profile[u'urls'])}'"
        ]
        if warm_up:
            warm_up_params = deepcopy(params)
            warm_up_params[4] = u"10s"
    else:
        params = [
            u"traffic_n_urls_m_cores",
            str(first_cpu),
            str(profile[u"cpus"] // len(profile[u"urls"])),
            str(profile[u"nr-of-threads"]),
            str(profile[u"nr-of-connections"]), f"{profile[u'duration']}s",
            f"'{profile[u'header']}'",
            str(profile[u"timeout"]),
            str(profile[u"script"]),
            str(profile[u"latency"]), f"'{u' '.join(profile[u'urls'])}'"
        ]
        if warm_up:
            warm_up_params = deepcopy(params)
            warm_up_params[5] = u"10s"

    args = u" ".join(params)

    ssh = SSH()
    ssh.connect(tg_node)

    if warm_up:
        warm_up_args = u" ".join(warm_up_params)
        ret, _, _ = ssh.exec_command(
            f"{Constants.REMOTE_FW_DIR}/resources/tools/wrk/wrk_utils.sh "
            f"{warm_up_args}",
            timeout=1800)
        if int(ret) != 0:
            raise RuntimeError(u"wrk runtime error.")
        sleep(60)

    ret, stdout, _ = ssh.exec_command(
        f"{Constants.REMOTE_FW_DIR}/resources/tools/wrk/wrk_utils.sh {args}",
        timeout=1800)
    if int(ret) != 0:
        raise RuntimeError('wrk runtime error.')

    stats = _parse_wrk_output(stdout)

    log_msg = u"\nMeasured values:\n"
    if test_type == u"cps":
        log_msg += u"Connections/sec: Avg / Stdev / Max  / +/- Stdev\n"
        for item in stats[u"rps-stats-lst"]:
            log_msg += u" / ".join(map(str, item)) + u"\n"
        log_msg += f"Total cps: {stats[u'rps-sum']}cps\n"
    elif test_type == u"rps":
        log_msg += u"Requests/sec: Avg / Stdev / Max  / +/- Stdev\n"
        for item in stats[u"rps-stats-lst"]:
            log_msg += u" / ".join(map(str, item)) + u"\n"
        log_msg += f"Total rps: {stats[u'rps-sum']}rps\n"
    elif test_type == u"bw":
        log_msg += f"Transfer/sec: {stats[u'bw-sum']}Bps"

    logger.info(log_msg)

    return log_msg