1. 程式人生 > >python實現不斷模擬客戶端請求,實現壓力測試

python實現不斷模擬客戶端請求,實現壓力測試

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()