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

Discussion in 'Python' started by Rémi, Jul 9, 2011.

  1. Rémi

    Rémi Guest

    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
    Rémi, Jul 9, 2011
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gary
    Replies:
    1
    Views:
    309
    Janaka
    Oct 16, 2003
  2. Raga
    Replies:
    4
    Views:
    1,622
  3. possibilitybox
    Replies:
    12
    Views:
    540
    Kent Johnson
    Apr 30, 2005
  4. Replies:
    1
    Views:
    551
    Toni Erdmann
    Mar 2, 2005
  5. Greg
    Replies:
    4
    Views:
    288
    Steven Simpson
    Aug 16, 2012
Loading...

Share This Page