python压测接口_python实现多线程压测post接口服务

import urllib

import urllib2

import random

import sys

import threading,time

from time import sleep, ctime

import json

import time

host_url='http://127.0.0.1:8070'

def now() :

return str( time.strftime( '%Y-%m-%d %H:%M:%S' , time.localtime() ) )

def post1():

print 'start loop', 'at:', now()

start = time.clock()

uid=random.randint(0, 2000000)

url=host_url+'/bigdata/crm/getGroupResCount'

values ={"query_where": [{"item": "uid","query": [{"op": "

jdata = json.dumps(values)

req = urllib2.Request(url, jdata)

req.add_header('Content-Type', 'application/json')

response = urllib2.urlopen(req)

end = time.clock()

print "run: %f s" % (end - start)

print response.read()

def post2():

print 'start loop', 'at:', now()

start = time.clock()

uid=random.randint(0, 2000000)

url=host_url+'/bigdata/crm/generateDataFile'

values ={"groupType": "dynamic","groupID": "123","query_where": [{"item": "uid","query": [{"op": "

jdata = json.dumps(values)

req = urllib2.Request(url, jdata)

req.add_header('Content-Type', 'application/json')

response = urllib2.urlopen(req)

end = time.clock()

print "run: %f s" % (end - start)

print response.read()

def post():

post1()

#post2()

def main():

loop=int(sys.argv[1])

ths=int(sys.argv[2])

for i in xrange(loop):

threadpool=[]

for i in xrange(ths):

th = threading.Thread(target= post)

threadpool.append(th)

for th in threadpool:

th.start()

for th in threadpool :

threading.Thread.join( th )

post()

if __name__ == '__main__':

main()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值