예제 #1
0
def fast_run(begin, end):
    log.warning("开始index{} 结束index{}".format(begin, end))
    run_start_time = time.time()
    log.info('开始发起快速异步请求....')
    for request in syncPool[int(begin):int(end)]:
        request.start()
    log.warning("请求消耗时间 {:.2f} 豪秒".format((time.time() - run_start_time) * 1000))
예제 #2
0
def loadRequestData(filePath):
    log.info("开始读取数据")
    file = open(filePath, 'r', encoding='utf-8')
    lines = file.readlines()
    for line in lines:
        line = line.replace("RequestBody:",
                            "").replace("openkey:", "").strip('\n').split(" ")
        request_data.append(line)
    return len(lines)
예제 #3
0
def slow_run(begin, end, slowTime):
    log.warning("开始index{} 结束index{}".format(begin, end))
    run_start_time = time.time()
    log.info('开始发起慢速异步请求....')
    if slowTime == 0:
        fast_run(begin, end)
    else:
        waitTime = round(((slowTime * 1000) / len(syncPool)) / 1000, 3)
        log.info("延迟时间为{}毫秒".format(waitTime * 1000))
        for request in syncPool[int(begin):int(end)]:
            request.start()
            time.sleep(waitTime)
    log.warning("请求消耗时间 {} 豪秒".format((time.time() - run_start_time) * 1000))
예제 #4
0
def init(count, url, methods='GET', params='{}', read=False):
    start_time = time.time()
    log.info('开始预创建请求池....')
    if read:
        for requestId in range(count):
            # dataList = data.request_data[requestId]
            # if utils.check_json(str(dataList[0]).replace("'", "")):
            #     params = json.loads(str(dataList[0]).replace("'", ""))
            # else:
            #     log.logger.error('json数据格式错误 跳过构建该请求')
            #     continue
            request = sync.SyncRequestTask(requestId, url, methods, params, headers)
            syncPool.append(request)
    else:
        for requestId in range(count):
            request = sync.SyncRequestTask(requestId, url, methods, params, headers)
            syncPool.append(request)
    log.info("初始化消耗时间 {:.2f} 豪秒".format((time.time() - start_time) * 1000))
예제 #5
0
def data_build(id, ms):
    log.info('ID {} 响应 {:.2f} 毫秒'.format(id, ms * 1000))
    ids.append(id)
    response_time.append(ms * 1000)