[Zope3-checkins] SVN: Zope3/trunk/src/zope/server/ Added a method of setting socket options and turned on TCP_NODELAY.

Shane Hathaway shane at zope.com
Thu Sep 2 01:24:06 EDT 2004


Log message for revision 27407:
  Added a method of setting socket options and turned on TCP_NODELAY.
  
  Zope buffers everything already, so the Nagle algorithm is likely 
  to delay unnecessarily in most forseeable cases.
  


Changed:
  U   Zope3/trunk/src/zope/server/adjustments.py
  U   Zope3/trunk/src/zope/server/serverbase.py


-=-
Modified: Zope3/trunk/src/zope/server/adjustments.py
===================================================================
--- Zope3/trunk/src/zope/server/adjustments.py	2004-09-02 05:20:28 UTC (rev 27406)
+++ Zope3/trunk/src/zope/server/adjustments.py	2004-09-02 05:24:05 UTC (rev 27407)
@@ -15,6 +15,8 @@
 
 $Id$
 """
+import socket
+
 from zope.server import maxsockets
 
 
@@ -33,7 +35,11 @@
     recv_bytes = 8192
 
     # send_bytes is the number of bytes to send to socket.send().
-    send_bytes = 8192
+    # Multiples of 9000 should avoid partly-filled packets, but don't
+    # set this larger than the TCP write buffer size.  In Linux,
+    # /proc/sys/net/ipv4/tcp_wmem controls the minimum, default, and
+    # maximum sizes of TCP write buffers.
+    send_bytes = 9000
 
     # copy_bytes is the number of bytes to copy from one file to another.
     copy_bytes = 65536
@@ -61,5 +67,13 @@
     # Boolean: turn off to not log premature client disconnects.
     log_socket_errors = 1
 
+    # The socket options to set on receiving a connection.
+    # It is a list of (level, optname, value) tuples.
+    # TCP_NODELAY is probably good for Zope, since Zope buffers
+    # data itself.
+    socket_options = [
+        (socket.SOL_TCP, socket.TCP_NODELAY, 1),
+        ]
 
+
 default_adj = Adjustments()

Modified: Zope3/trunk/src/zope/server/serverbase.py
===================================================================
--- Zope3/trunk/src/zope/server/serverbase.py	2004-09-02 05:20:28 UTC (rev 27406)
+++ Zope3/trunk/src/zope/server/serverbase.py	2004-09-02 05:24:05 UTC (rev 27407)
@@ -145,4 +145,6 @@
                 self.log_info ('warning: server accept() threw an exception',
                                'warning')
             return
+        for (level, optname, value) in self.adj.socket_options:
+            conn.setsockopt(level, optname, value)
         self.channel_class(self, conn, addr, self.adj)



More information about the Zope3-Checkins mailing list