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

Python TCP连接数和HTTP事务数之间的差异,python,centos,Python,Centos,在我的大学项目中,我正在尝试开发一个基于python的流量生成器。我在vmware上创建了2台CentOS机器,其中1台用作我的客户端,1台用作我的服务器。我使用了IP别名技术,仅使用单个客户机/服务器机器就可以增加客户机和服务器的数量。到目前为止,我已经在客户端机器上创建了50个IP别名,在服务器机器上创建了10个IP别名。我还使用多处理模块从所有50个客户端到所有10个服务器并发生成流量。我还在/var/www/html目录中的服务器上开发了一些配置文件1kb、10kb、50kb、100kb

在我的大学项目中,我正在尝试开发一个基于python的流量生成器。我在vmware上创建了2台CentOS机器,其中1台用作我的客户端,1台用作我的服务器。我使用了IP别名技术,仅使用单个客户机/服务器机器就可以增加客户机和服务器的数量。到目前为止,我已经在客户端机器上创建了50个IP别名,在服务器机器上创建了10个IP别名。我还使用多处理模块从所有50个客户端到所有10个服务器并发生成流量。我还在/var/www/html目录中的服务器上开发了一些配置文件1kb、10kb、50kb、100kb、500kb、1mb,因为我使用的是Apache服务器,并且我使用urllib2从我的客户机向这些配置文件发送请求。接下来,我的指南希望我监视在流量生成会话期间生成的TCP连接数和HTTP事务数。首先,我无法清楚区分这两个实体。据我所知,TCP连接是TCP会话SYN/ACK/FIN等,HTTP事务是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

对1的回答是:对,对2的回答是:计算您连接的次数,并计算您使用所选方法发出GET/POST/DELETE/HEAD的次数。Hello@AnttiHaapala我在这里附加了我的代码。您能告诉我如何计算TCP连接数和HTTP事务数吗?好的,对于HTTP事务,我将使用一个全局计数器,在每个opener.openx.read行之后递增。但是我如何在这里获得TCP连接的价值呢?如果您知道代码在做什么,您可以确定这些数字,但我猜您的向导希望您使用网络嗅探器。它可以告诉您TCP连接的数量,并且在了解HTTP的情况下,它还可以告诉您HTTP请求的数量。在任何情况下,我都看不到与编程相关的问题。urllib2不支持keepalive连接,每个HTTP请求都是一个新连接