Attachment 'README.txt'

Download

   1 This server is an HTTP wrapper around the asyncode module.
   2 
   3 1) It can handle HTTP versions 0.9, 1.0, and 1.1 but, I will make no claim that
   4 it will handle all the corner cases.
   5 
   6 2) It will handle Keep-Alive correctly for version 1.0 and 1.1, there is no
   7 keep alive for 0.9.
   8 
   9 3) It will not handle pipe-lining for version 1.1 (Queuing multiple requests
  10 before responding to any of them).
  11 
  12 4) There is a script in the /tests directory named testACHTTPServer.py which
  13 is used to test the AsyncoreHTTPServer module.
  14 
  15   a) The are the maximum requests with none dropped.
  16 
  17 Connection: keep-alive
  18 ----------------------
  19 The statistics for this server using the arguments below are, where
  20 localhost:8081 is the host:port, HEAD or GET is the HTTP method on the server,
  21 165 is the number of times to repeat the request, 15.0 is the socket
  22 timeout while waiting for a new connection, and True is to keep alive the
  23 connection after each request.
  24 
  25 $ time ./testACHTTPServer.py -h localhost:8081 -m [HEAD|GET] -p / -c 165 \
  26        -t 15.0 -k True
  27 
  28 1) Six separate runs using HEAD averaged 0.301 seconds which is 548 requests
  29 per second.
  30 
  31 2) Six separate runs using GET averaged 0.354 seconds which is 466 requests
  32 per second.
  33 
  34 Connection: close
  35 -----------------
  36 The statistics for this server using the arguments below are, where
  37 localhost:8081 is the host:port, HEAD or GET is the HTTP method on the server,
  38 45 is the number of times to repeat the request, 15.0 is the socket timeout
  39 while waiting for a new connection, and False is to not keep alive the
  40 connection after each request.
  41 
  42 $ time ./testACHTTPServer.py -h localhost:8081 -m [HEAD|GET] -p / -c 45 \
  43        -t 15.0 -k False
  44 
  45 1) Six separate runs using HEAD averaged 0.161 seconds which is 280 requests
  46 per second.
  47 
  48 2) Six separate runs using Get averaged 0.177 seconds which is 254 requests
  49 per second.
  50 
  51 Conclusion
  52 ----------
  53 If the connection is kept alive many more requests to the same resource can
  54 handled sequentially without dropping any connections. This shows that
  55 AsyncoreHTTPServer can keep up with a very fast client if the connection is
  56 kept alive.
  57 
  58 Wrapping AsyncoreHTTPServer
  59 ===========================
  60 
  61 Below is an example of how to wrap AsyncoreHTTPServer so AsyncoreHTTPServer
  62 can be used in a stand alone application.
  63 
  64 class StandAloneServer(AsyncoreHTTPServer):
  65 
  66     def __init__(self):
  67         # Flag to tell the server to exit from a forever loop.
  68         self.__exit = False
  69 
  70     def start(self, host, port, handler=StandAloneHandler):
  71         """
  72         Start the server.
  73 
  74         @param host: The host to run on.
  75         @param port: The port to run on.
  76         @param handler: The request handler to use. This handler should wrap
  77                         either AsyncoreHTTPRequestHandler or WSGIAsynHandler.
  78         """
  79         msg = "The Stand Alone Service is up for business..."
  80         AsyncoreHTTPServer.__init__(self, host, port, handler,
  81                                     logger="StandAlone",
  82                                     httpTimeout=300)
  83         self.setBacklog(5)
  84 
  85         for count in range(10):
  86             try:
  87                 AsyncoreHTTPServer.start(self)
  88                 print "\n%s" % msg
  89                 break
  90             except socket.error, e:
  91                 print "%s: %s, will try again in one minute." % \
  92                       (sys.argv[0], e[1]))
  93 
  94             time.sleep(60)
  95 
  96     def serve_forever(self, timeout=30.0):
  97         """
  98         This method will only exit when self.__exit is True.
  99         """
 100         while not self.__exit:
 101             self.loop(timeout=timeout)
 102 
 103     def exitServer(self, signum, frame):
 104         """
 105         Exit the server. Callback for the signal handler.
 106 
 107         @param signum: A number representing the signal to catch.
 108         @param frame: The current stack frame (None or a frame object)
 109         """
 110         print "%s: Caught signal %s exiting Template Service." % \
 111               sys.argv[0], signum)
 112         self.__exit = True
 113         self.closeAllChannels()
 114 
 115 Then this would be called like so:
 116 
 117 if __name__ == '__main__':
 118     import traceback, signal
 119 
 120     # Get the host and port from somewhere.
 121     host = 'localhost'
 122     port = 80
 123 
 124     try:
 125         ts = StandAloneServer()
 126         signal.signal(signal.SIGTERM, ts.exitServer)
 127         ts.start(host, port)
 128         ts.serve_forever()
 129     except Exception:
 130         print "%s: %s\n" % (sys.exc_info()[0], sys.exc_info()[1])
 131         tb = sys.exc_info()[2]
 132         traceback.print_tb(tb)
 133         sys.exit(1)
 134 
 135     sys.exit(0)
 136 
 137 ===============================================
 138 If there are any questions feel free to ask me.
 139 Carl J. Nobile
 140 mailto:carl.nobile@gmail.com

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.

You are not allowed to attach a file to this page.