[ https://issues.apache.org/jira/browse/THRIFT-4668?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16695576#comment-16695576 ]
ASF GitHub Bot commented on THRIFT-4668: ---------------------------------------- lshgdut edited a comment on issue #1631: THRIFT-4668: make socket backlog configurable for python URL: https://github.com/apache/thrift/pull/1631#issuecomment-440920684 The value of `socket.SOMAXCONN` depends on different operate systems: - on Window 7, it is `2147483647` - on Centos or Debian, it is `128`, even I have set a different value to `/proc/sys/net/core/somaxconn` According to `Python-2.7.14/Modules/socketmodule.c`: ```c 4967 /* Maximum number of connections for "listen" */ 4968: #ifdef SOMAXCONN 4969: PyModule_AddIntConstant(m, "SOMAXCONN", SOMAXCONN); 4970 #else 4971: PyModule_AddIntConstant(m, "SOMAXCONN", 5); /* Common value */ 4972 #endif ``` The value of `SOMAXCONN` depend on system macro `SOMAXCONN`: - on Window 7, I can not explain why it is 2147483647 - on linux, `SOMAXCONN` is defined in '/usr/include/bits/socket.h +144', hard code to 128 Linux set `SOMAXCONN` macro to` core.sysctl_somaxconn` first, then check the sysctl value of 'net.core.somaxconn' existing or not and override it if possible. When socket listening, if `backlog` is greater than SOMAXCONN, the kernel will take the value of `min(backlog, SOMAXCONN)`. Here is linux kernel code below: ```c // From linux-3.10.0-693.25.4.el7/net/socket.c +1534 /* * Perform a listen. Basically, we allow the protocol to do anything * necessary for a listen, and if that works, we mark the socket as * ready for listening. */ SYSCALL_DEFINE2(listen, int, fd, int, backlog) { struct socket *sock; int err, fput_needed; int somaxconn; sock = sockfd_lookup_light(fd, &err, &fput_needed); if (sock) { somaxconn = sock_net(sock->sk)->core.sysctl_somaxconn; if ((unsigned int)backlog > somaxconn) backlog = somaxconn; err = security_socket_listen(sock, backlog); if (!err) err = sock->ops->listen(sock, backlog); fput_light(sock->file, fput_needed); } return err; } ``` Therefore, limit `_backlog` to `socket.SOMAXCONN` will make `core.net.somaxconn` not working properly on linux. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > make socket backlog configurable for python > ------------------------------------------- > > Key: THRIFT-4668 > URL: https://issues.apache.org/jira/browse/THRIFT-4668 > Project: Thrift > Issue Type: Improvement > Components: Python - Library > Affects Versions: 0.11.0 > Reporter: lsh > Priority: Minor > Labels: patch > > The backlog parameter of socket.listen was hard coded, so I can't customize > it in my code. > Adding `setBacklog` to `TServerSocket` can resolve my problem. :) -- This message was sent by Atlassian JIRA (v7.6.3#76005)