pyhon-高并发测试
使用gevent。对注册、接口进行200的并发量进行测试。
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#设置路径:Defualt Settings---Editor--File and Code Templates
# Author:肖遥
import time
import json
import random
from urllib.error import URLError
from urllib import request
import http.client
import requests
import gevent
from gevent import monkey # 补丁
monkey.patch_all() #** 请求URL **
url = 'http://172.17.0.128:15124/mdm/public/query'
headers = {'Content-Type': 'application/json'} error=[] def make_data(num):
"""制造请求数据"""
# data = {
# "id": num,
# "name": "test" + str(num),
# }
data={"Request": {"Head": {"LicId": "", "ContentType": "text/json", "TranCode": "DeptInfo", "ServiceVersion": "5.0.2",
"ContentEncoding": "", "Timestamp": "2018-10-19 17:09:55.137", "TransferType": "",
"SecurityContent": "", "OrgId": "01", "Callback": "", "AppId": "HIS0311", "Version": "1.1",
"SecurityPolicy": "", "AppType": "PC", "MessageId": "EA455467-A04A-4E73-8BE4-190078D3C258"}
, "Body": {"Page": 1, "PageSize": 30, "Params": [{"key": "deptCode", "value": "T234"}]}}}
return data def run():
"""三种模拟请求"""
num = random.randint(1, 9)
data = make_data(num)
global error
try:
# # s1:request请求
# req = request.Request(url=url, data=data, headers=headers, method="POST")
# response = request.urlopen(req)
# resp = response.read()
# print("服务器返回值为:\n", resp.decode('utf-8')) # s2:httpclient请求
# httpclient = http.client.HTTPConnection(host='127.0.0.1', port=8001)
# httpclient.request("POST", '/insert', data, headers)
# response = httpclient.getresponse()
# print(response.read().decode()) # s3:requests请求
resp = requests.post(url=url, json=data, headers=headers)
print("状态:\n", resp)
print("请求头:\n", resp.headers)
print("服务器返回值为:\n", resp.content.decode())
if resp.status_code != 200:
error.append("0")
except URLError as e:
print('请求', e)
# error.append("ue0")
except Exception as e:
error.append("re0")
print('请求错误:', e) def call_gevent(count):
"""调用gevent 模拟高并发"""
begin_time = time.time()
run_gevent_list = []
for i in range(count):
print('--------------%d--Test-------------' % i)
run_gevent_list.append(gevent.spawn(run()))
gevent.joinall(run_gevent_list)
end = time.time()
print('单次测试时间(平均)s:', (end - begin_time) / count)
print('累计测试时间 s:', end - begin_time)
print("运行失败用例数:",error.count("0"))
print("运行报错数:",error.count("re0") ) if __name__ == '__main__':
# 10万并发请求
test_count = 200
call_gevent(count=test_count)
pyhon-高并发测试的更多相关文章
- Jmeter之仿真高并发测试-集合点
场景: 大家在使用Jmeter测试的时候应该发现了, (1)线程启动了就会直接发送测试请求:--如果要模拟在一瞬间高并发量测试的时候,需要调高线程数量,这很耗测试机器的性能,往往无法支持较大的并发数, ...
- Java高并发测试框架JCStress
前言 如果要研究高并发,一般会借助高并发工具来进行测试.JCStress(Java Concurrency Stress)它是OpenJDK中的一个高并发测试工具,它可以帮助我们研究在高并发场景下JV ...
- 对redis高并发测试的研究
以下引用大神的: 测试项目: https://github.com/14251104246/redis-demo.git 准备 使用docker-compose命令启动redis服务器(可以用其他方式 ...
- java高并发测试代码
package com.example.test; import java.net.URL;import java.net.URLConnection;import java.util.concurr ...
- CountDownLatch模拟高并发测试代码
直接上代码进行验证吧 /** * 通过countdownlatch的机制,来实现并发运行 * 模拟200个并发测试 * @author ll * @date 2018年4月18日 下午3:55:59 ...
- jmeter(高并发测试)
1.首先jmeter需要JDK8以上得运行环境 2.下载jmeter,官方网址:http://jmeter.apache.org/download_jmeter.cgi 3.安装jmeter.jmet ...
- http_load 高并发测试
安装http_load 下载 sudo wget http://www.acme.com/software/http_load/http_load-09Mar2016.tar.gz 解压 sudo t ...
- webbench高并发测试
安装ctags sudo apt-get install ctags 安装webbench 下载webbench http://home.tiscali.cz/~cz210552/distfiles/ ...
- siege 高并发测试工具
安装siege 下载 http://download.joedog.org/siege/siege-4.0.4.tar.gz 解压 sudo tar -zvxf siege-4.0.4.tar.gz ...
- Spring boot 实现高吞吐量异步处理(适用于高并发场景)
技术要点 org.springframework.web.context.request.async.DeferredResult<T> 示例如下: 1. 新建Maven项目 asy ...
随机推荐
- JQuery EasyUI 结合ztrIee的后台页面开发
JQuery EasyUI 结合 zTree树形结构制作web页面.easyui用起来比较简单,很好的封装了jquery的部分功能,使用起来更加方便,但是从1.2.3版本以后,商业用途是需要付费的, ...
- iOS 15 无法弹出授权弹框之解决方案---Your app uses the AppTrackingTransparency framework, but we are unable to locate the App Tracking Transparency permission request when reviewed on iOS 15.0
2021年9月30日下午:我正愉快的期盼着即将到来的国庆假期,时不时刷新下appstoreconnect的网址,28号就提上去的包,今天还在审核中....由于这个版本刚升级的xcode系统和新出的iO ...
- 【Azure Developer】Azure Automation 自动化账号生成的时候怎么生成连接 与证书 (Connection & Certificate)
Azure Automation :The Azure Automation service provides a highly reliable and scalable workflow exec ...
- Spring中IOC的理解
Spring中IOC的理解 1.什么是IOC? (1)控制反转.把对象创建和对象间的调用过程交给Spring进行管理. (2)使用IOC的目的:为了耦合度降低. 2.IOC底层原理? (1)xml解析 ...
- 实践篇 -- Redis客户端缓存在SpringBoot应用的探究
本文探究Redis最新特性--客户端缓存在SpringBoot上的应用实战. Redis Tracking Redis客户端缓存机制基于Redis Tracking机制实现的.我们先了解一下Redis ...
- 3DGIS开发使用的开源项目
gdal proj4 vcglib assimp libjpg libpng osg libtess2 cesiumjs glm
- 讲讲java中线程池的实现
今天跟一个同学谈到java中的线程池的实现,才发现有些知识点已经记不清了,所以特意把源码打开,对官方文档做了些说明. 其实这些理解了之后,读懂源码应该是没多大问题了,有感兴趣的小伙伴们可以看完说明后自 ...
- CAM对象样式表
CAM对象样式表 121 160 UF_machining_task_type UF_mach_order_task_subtype 112 UF_machining_null_grp_type 无 ...
- Java中的函数式编程(六)流Stream基础
写在前面 如果说函数式接口和lambda表达式是Java中函数式编程的基石,那么stream就是在基石上的最富丽堂皇的大厦. 只有熟悉了stream,你才能说熟悉了Java 的函数式编程. 本文主要介 ...
- MySQL:提高笔记-5
MySQL:提高笔记-5 学完基础的语法后,进一步对 MySQL 进行学习,前几篇为: MySQL:提高笔记-1 MySQL:提高笔记-2 MySQL:提高笔记-3 MySQL:提高笔记-4 MySQ ...