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"

转载于:https://www.cnblogs.com/xyao1/p/11003273.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值