0

I have implmented a TCP to HTTP proxy server using urllib,

which converts a TCP request to a HTTP request to a specific server,

It's something like this:

class RequestHandler(socketserver.BaseRequestHandler):

    def handle(self):
        size, = struct.unpack('L', s.recv(4))
        data = s.recv(size)
        assert len(data) == size
        res = urllib.urlopen('http://myserver.com/', encode_data(data)).read()
        s.sendall(res)
        s.shutdown(SHUT_WR)

if __name__ == '__main__':
    address = ('', 8080)
    server = socketserver.ThreadingTCPServer(address, RequestHandler)
    server.serve_forever()        

But it became very slow on many connections(not too many: about 20) at the same time.

Where is the bottleneck? Is it related with GIL issue?

BTW: I'm on Windows so ForkingMixin is not available here

  • @user522809: Isn't HTTP protocol over TCP protocol. Or to say, HTTP would be an application level protocol. – pyfunc Nov 28 '10 at 07:49
  • @pyfunc: Not a general TCP2HTTP proxy. It only converts some specific TCP request to corresponding HTTP request. You can say HTTP is used here as an app level protocol. – user522809 Nov 28 '10 at 07:54

1 Answers1

0

Use profiler, one of: http://docs.python.org/library/profile.html

Lex
  • 1,378
  • 11
  • 10
  • http://stackoverflow.com/questions/582336/how-can-you-profile-a-python-script/1922945#1922945 – Lex Nov 28 '10 at 10:27