python实现不断模拟客户端请求,实现压力测试

来源:互联网 发布:知乎 陌生人 编辑:程序博客网 时间:2024/06/07 23:52

testVolumeClient.py

import urllib2
url = 'http://localhost:8000'

while True:
    urlrequest = urllib2.Request(url)
    urlresponse = urllib2.urlopen(urlrequest)
    print urlresponse.read()




testVolumeServer.py

import time
def myapp(environ, start_response):
    status = '200 OK'
    headers = [('Content-type', 'text/html')]
    now = time.strftime("%Y-%m-%d  %H:%M:%S")
    res = 'now time=%s \n' %now
    print(res)
    start_response(status, headers)
    return "Hello World! =%s" % res

from wsgiref.simple_server import make_server


httpd = make_server('', 8000, myapp)
print "Serving HTTP on port 8000..."
httpd.serve_forever()









0 0
原创粉丝点击