werew33 发表于 2015-11-4 08:59:02

Python 压力测试脚本

目的是写个脚本,起多线程去call一个接口,来测试一个并发问题。
实现方案是将接口做到了一个页面中,用python的http get请求来访问查询。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import urllib

import threading
from time import ctime,sleep



def t1(func):
for i in range(10):
    f=urllib.urlopen("http://www.mystation.com/myinterface.html?param=value")
    s=f.read()
    print "round:%s, tread number:%s, returnValue:%s,time:%s" % (i, func, s, ctime())
    sleep(1)


if __name__ == '__main__':
threads=[]
for i in range(100):
    name = "t%s" % (i)
    name = threading.Thread(target=t1,args=(i,))
    threads.append(name)


for t in threads:
    t.setDaemon(True)
    t.start()
t.join()






页: [1]
查看完整版本: Python 压力测试脚本