对于我的大学项目,我正在使用 python 构建一个流量生成工具。我在 Vmware 上开发了自己的 linux 服务器和客户端。我正在使用 urllib2 在 python 中生成流量。我在这里面临的问题是,当我在客户端机器上运行我的脚本(使用多处理不断向 linux 服务器发送请求)时,它在前几分钟工作正常,比如大约 2000 个请求,但之后它显示“连接重置peer”错误,我的脚本崩溃了。可能是什么问题呢?我试过这样做,但没有帮助。
如何防止此超时错误并连续运行脚本数小时?
'''
Traffic Generator Script:
Here I have used IP Aliasing to create multiple clients on single vm machine. same I have done on server side to create multiple servers. I have around 50 clients and 10 servers
'''
import multiprocessing
import urllib2
import random
import myurllist #list of all destination urls for all 10 servers
import time
import socbindtry #script that binds various virtual/aliased client ips to the script
response_time=[]
error_count=multiprocessing.Value('i',0)
def send_request3(): #function to send requests from alias client ip 1
opener=urllib2.build_opener(socbindtry.BindableHTTPHandler3)#bind to alias client ip1
try:
tstart=time.time()
for i in range(myurllist.url):
x=random.choice(myurllist.url[i])
opener.open(x).read()
print "file downloaded:",x
response_time.append(time.time()-tstart)
except urllib2.URLError, e:
error_count.value=error_count.value+1
def send_request4(): #function to send requests from alias client ip 2
opener=urllib2.build_opener(socbindtry.BindableHTTPHandler4)#bind to alias client ip2
try:
tstart=time.time()
for i in range(myurllist.url):
x=random.choice(myurllist.url[i])
opener.open(x).read()
print "file downloaded:",x
response_time.append(time.time()-tstart)
except urllib2.URLError, e:
error_count.value=error_count.value+1
#50 such functions are defined here for 50 clients
process=[]
def func():
global process
process.append(multiprocessing.Process(target=send_request3))
process.append(multiprocessing.Process(target=send_request4))
process.append(multiprocessing.Process(target=send_request5))
process.append(multiprocessing.Process(target=send_request6))
#append 50 functions here
for i in range(len(process)):
process[i].start()
for i in range(len(process)):
process[i].join()
print"All work Done..!!"
return
start=float(time.time())
func()
end=float(time.time())-start
print end