p4_syncbench.py #2

  • //
  • main/
  • guest/
  • robert_cowham/
  • p4benchmark/
  • main/
  • locust_files/
  • p4_syncbench.py
  • View
  • Commits
  • Open Download .zip Download (2 KB)
#! /usr/bin/env python3
#
# Perforce benchmarks using Locust.io framework
#
# Copyright (C) 2016, Robert Cowham, Perforce
#

from __future__ import print_function

import os
import sys
import logging
from locust import Locust, events, task, TaskSet
from locust.exception import StopLocust

import P4

from p4benchutils import popen, fmtsize, readConfig, Timer, P4Benchmark

from locust.stats import RequestStats
def noop(*arg, **kwargs):
    logger.info("Stats reset prevented by monkey patch!")
RequestStats.reset_all = noop

python3 = sys.version_info[0] >= 3

logger = logging.getLogger("p4_syncbench")

startdir = os.getcwd()

CONFIG_FILE = "config_p4_syncbench.yml"   # Configuration parameters

class P4BuildFarmBenchmark(P4Benchmark):
    """Performs basic benchmark test - Perforce specific subclass"""

    def __init__(self, startdir, config):
        super(P4BuildFarmBenchmark, self).__init__(logger, startdir, config, "p4buildfarm")

def buildFarmActions(bench, request_type):
    "Build farm basically just does a sync"
    count = 0
    t = Timer(request_type)
    name = "create"
    try:
        bench.createWorkspace()
        count = 1
        t.report_success(name, count)
    except Exception as e:
        logger.exception(e)
        t.report_failure(name, e)
    t = Timer(request_type)
    name = "sync"
    try:
        count = bench.syncWorkspace(t)
        t.report_success(name, count)
    except Exception as e:
        logger.exception(e)
        t.report_failure(name, e)

class AllTasks(TaskSet):
    """Entry point for locust"""

    min_wait = 1000
    max_wait = 10000
    request_type = "p4"

    def __init__(self, *args, **kwargs):
        super(AllTasks, self).__init__(*args, **kwargs)
        self.config = readConfig(startdir, CONFIG_FILE)
        self.min_wait = self.config["general"]["min_wait"]
        self.max_wait = self.config["general"]["max_wait"]

    def on_start(self):
        pass

    @task(10)
    def buildFarmActions(self):
        task_name = "p4buildfarm"
        self.bench = P4BuildFarmBenchmark(startdir, self.config)
        buildFarmActions(self.bench, task_name)
        logger.info("Finished %s" % task_name)
        raise StopLocust("task_name")   # Run once only and die

class P4RepoTestLocust(Locust):
    """Will be imported and then run by locust"""
    task_set = AllTasks
# Change User Description Committed
#2 25529 Robert Cowham Latest copy of files including docker compose setup.
Merging
//guest/robert_cowham/p4benchmark/pb/...
to //guest/robert_cowham/p4benchmark/main/...
#1 24727 Robert Cowham Refactored
//guest/robert_cowham/p4benchmark/main/locust_files/p4_bench.py
#1 24711 Robert Cowham Restructure and tidy up
//guest/robert_cowham/p4benchmark/main/p4_bench.py
#20 24686 Robert Cowham Getting it working - especially with Python3
#19 22003 Robert Cowham Latest state - with p4python and no syncing
#18 21899 Robert Cowham Randomly choose hostname instead of attempting to evenly split
#17 21885 Robert Cowham Add sync_args
#16 21820 Robert Cowham Remove unused code.
Make a little more configurable via config file
#15 21800 Robert Cowham Sync one level down - hard coded to select 50 for now
#14 21799 Robert Cowham Avoid mkdirs error.
Remove user task
#13 21793 Robert Cowham Use hostname to choose which server to connect to
#12 21769 Robert Cowham Allow multiple ports to be specified - for random choice
#11 21767 Robert Cowham add latest stuff with analyse
#10 21761 Robert Cowham Avoid stats reset.
Stop each task after it has run once
#9 21760 Robert Cowham Log config and ws options
#8 21759 Robert Cowham Allow options to be configurable
#7 21744 Robert Cowham Output sync progress via logger too
#6 21743 Robert Cowham Make it configurable
#5 21742 Robert Cowham Added partial sync reporting
#4 21737 Robert Cowham Fix dirs command
#3 21735 Robert Cowham Put all benchmark into one file
#2 21718 Robert Cowham Refactored a little - into one file
#1 21717 Robert Cowham Trying nested tasks