Commits

Robert Brewer  committed cd42d4b

Adding a server.nodelay option, and making wsgiserver set TCP_NODELAY by default. See http://www.cmlenz.net/archives/2008/03/python-httplib-performance-problems for the use case.

  • Participants
  • Parent commits ec72c91

Comments (0)

Files changed (3)

File cherrypy/_cpserver.py

     instance = None
     ssl_certificate = None
     ssl_private_key = None
+    nodelay = True
     
     def __init__(self):
         ServerAdapter.__init__(self, cherrypy.engine)

File cherrypy/_cpwsgi.py

     
     wsgiserver has been designed to not reference CherryPy in any way,
     so that it can be used in other frameworks and applications. Therefore,
-    we wrap it here, so we can set our own mount points from cherrypy.tree.
+    we wrap it here, so we can set our own mount points from cherrypy.tree
+    and apply some attributes from config -> cherrypy.server -> wsgiserver.
     """
     
     ConnectionClass = CPHTTPConnection
                    shutdown_timeout = server.shutdown_timeout,
                    )
         self.protocol = server.protocol_version
+        self.nodelay = server.nodelay
         self.ssl_certificate = server.ssl_certificate
         self.ssl_private_key = server.ssl_private_key
 

File cherrypy/wsgiserver/__init__.py

         specifies the maximum number of queued connections (default 5).
     timeout: the timeout in seconds for accepted connections (default 10).
     
+    nodelay: if True (the default since 3.1), sets the TCP_NODELAY socket
+        option.
+    
     protocol: the version string to write in the Status-Line of all
         HTTP responses. For example, "HTTP/1.1" (the default). This
         also limits the supported features used in the response.
     version = "CherryPy/3.1.0beta3"
     ready = False
     _interrupt = None
+    
+    nodelay = True
+    
     ConnectionClass = HTTPConnection
     environ = {}
     
         """Create (or recreate) the actual socket object."""
         self.socket = socket.socket(family, type, proto)
         self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
-##        self.socket.setsockopt(socket.SOL_SOCKET, socket.TCP_NODELAY, 1)
+        if self.nodelay:
+            self.socket.setsockopt(socket.SOL_SOCKET, socket.TCP_NODELAY, 1)
         if self.ssl_certificate and self.ssl_private_key:
             if SSL is None:
                 raise ImportError("You must install pyOpenSSL to use HTTPS.")