Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > HTTP Proxy : receive call on local socket takes a lot of time

Reply
Thread Tools

HTTP Proxy : receive call on local socket takes a lot of time

 
 
Rémi
Guest
Posts: n/a
 
      07-09-2011
Hi all,

I am currently working on a HTTP Proxy. For maximum flexibility, I am
implementing the proxy at a low level : I am using the SocketServer library.

The server itself is very simple:

class MyTCPServer(SocketServer.TCPServer):
allow_reuse_address = 1

and the handler looks like:

class MyTCPHandler(SocketServer.BaseRequestHandler):

def handle(self):
# Prints ip and port
print "\n#### " + str(self.client_address) + " ####"

requestParser = HTTPRequestParser()

while True:
# Get packet
data = self.request.recv(4096)

if data == '':
break

# Parse request packet
if requestParser.got_new_chunk(data):
break

someStuff = ""
self.request.send(someStuff)


This is working fine, but I have a small performance issue.
The proxy is targeted by Firefox. Sometimes the first receive call on
the input socket takes a lot of time (up to 20s sometimes), which should
not be as this is a communication of two local sockets. This is
occurring maybe every 30 requests or so.

When looking at the logs I noticed that this weird behavior happens when
the client port is not contiguous to the previous ones. For example,
handling the fourth request takes a lot of time:

#### ('127.0.0.1', 49704) ####
#### ('127.0.0.1', 49705) ####
#### ('127.0.0.1', 49706) ####
#### ('127.0.0.1', 49674) ####


Do you have any idea what the problem could be ? I tried to manually
close self.request request, but I still have the problem. Is it related
to "allow_reuse_address = 1" ?

Thanks for your help !

Rémi
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
IllegalArgumentException with Socket API and Proxy with Proxy.Type.HTTP Greg Java 4 08-16-2012 08:26 PM
Thread.sleep takes lot of CPU time! Raga Java 4 07-18-2006 06:10 AM
large dictionary creation takes a LOT of time. possibilitybox Python 12 04-30-2005 05:35 PM
Uploading files takes a lot of time... Gary ASP .Net 1 10-16-2003 10:33 AM



Advertisments