0

For my college project I am building one traffic generation tool using python. I have developed my own linux server and client on Vmware. I am using urllib2 for traffic generation in python. The problem that I am facing here is when I run my scripts on client machine(that are continuously sending request to linux server using multiprocessing), it works fine for first few minutes say for around 2000 requests but after that it shows "connection reset by peer" error and my script than collapses. What could be the problem? I tried doing this, but it was not helpful.

How can I prevent this time-out error and run my script continuously for hours?

'''
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
Bhoomika Sheth
  • 323
  • 5
  • 17
  • Does the server script stop running? – Paul Rooney Mar 23 '15 at 05:01
  • Could we see part of the code you wrote to figure out the problem? – dgsleeps Mar 23 '15 at 05:02
  • @Paul Rooney : I am not running any script on server. I have just created some text files in /var/www/html directory on server. And i am sending http requests to these files from my client. And I am getting 200 response status for them. Do I need to do some programming on server also? How to do so? Can anyone guide me? – Bhoomika Sheth Mar 23 '15 at 06:39
  • No sorry. I thought you had your own client and server. If you are just using apache or whatever it shouldn't require a server side component. – Paul Rooney Mar 23 '15 at 07:15
  • yes i am using apache 2.2.15. but i can stop apache service and redefine my own server if it could help to resolve this connection reset problem.. can you guide me how to do so? – Bhoomika Sheth Mar 23 '15 at 07:40

1 Answers1

0

Without more information it is hard to know what is happening specifically. First off - use netstat to get your baseline (prior to script execution):

$ netstat -nap > /tmp/pre-stats

then run your scripts and capture stats when you get the error:

$ netstats -nap > /tmp/post-stats

After you've done that running checking the two may give you some ideas. So for example you may be running out of sockets server-side with too many processes waiting in CLOSE_WAIT/TIME_WAIT ( http://vincent.bernat.im/en/blog/2014-tcp-time-wait-state-linux.html ). This could easily prevent new sockets from opening thus throwing "connection reset by peer".

You definitely have some sort of resource problem - you need to do a bit more to dig up information on where the bottleneck is.

depending on what it is - it may be your client not closing TCP connection properly, or server holding on to a connection for too long - there could be multiple things. IT could also be that VMWare for some reason is not able to keep up with traffic between VMs.

Droopy4096
  • 311
  • 1
  • 10
  • I did what you suggested but I am not able to conclude anything here.. can you help me to proceed further? – Bhoomika Sheth Mar 24 '15 at 04:44
  • @BhoomikaSheth what did your pre-stats and post-stats show? you may want to post them either as gists or on pastbin-alikes with URL here. posting your code as a gist may be beneficial too . you've got modules there that may be the culprit... also what does apache log says on "server" side? – Droopy4096 Mar 25 '15 at 05:05