在我的大学项目中,我正在尝试开发一个基于python的流量生成器,我在vmware上创建了2台CentOS机器,我使用1作为我的客户机,1作为我的服务器机器。我使用了IP别名技术来增加客户机和服务器的数量,只使用一台客户机/服务器机器。到目前为止,我已经在我的客户机上创建了50个IP别名,在我的服务器机器上创建了10个IP别名。我还使用多处理模块同时生成从所有50个客户端到所有10个服务器的流量。我还在我的服务器上开发了一些配置文件(1kb、10kb、50kb、100kb、500kb、1mb)(因为我在使用Apache服务器,所以我在/var/www/html目录下)并使用urllib2从客户机向这些概要文件发送请求。接下来,我的指南希望我监视在流量生成会话期间生成的TCP连接和HTTP事务的数量。首先,我不能清楚地区分这两个实体。根据我的理解,TCP连接是TCP会话SYN/ACK/FIN等,而HTTP Transaction是HTTP方法GET/POST/DELETE/HEAD等的数量,这是正确的吗?如果没有,那么这个问题的正确答案是什么?第二,如何使用python监控这两个实体?在
'''
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=[] #some shared variables
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
目前没有回答
相关问题 更多 >
编程相关推荐