TCP连接数与HTTP事务数之间的差异

时间:2015-03-27 05:49:43

标签: python centos

对于我的大学项目,我正在尝试开发基于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 Session-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

0 个答案:

没有答案