From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Robert Pluim Newsgroups: gmane.emacs.devel Subject: Re: PATCH: add support for TCP_NODELAY on network streams Date: Wed, 11 Dec 2024 13:45:34 +0100 Message-ID: <87ed2e5qxd.fsf@gmail.com> References: <7292e8f5-2be9-4c76-b473-882ff437ad93@risk-engineering.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19742"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Eric Marsden Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Dec 11 13:46:48 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tLM76-0004vn-2h for ged-emacs-devel@m.gmane-mx.org; Wed, 11 Dec 2024 13:46:48 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLM6V-00014Q-9A; Wed, 11 Dec 2024 07:46:11 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLM67-00012L-FC for emacs-devel@gnu.org; Wed, 11 Dec 2024 07:45:59 -0500 Original-Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tLM60-0001D8-VT for emacs-devel@gnu.org; Wed, 11 Dec 2024 07:45:44 -0500 Original-Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-3862d16b4f5so385178f8f.0 for ; Wed, 11 Dec 2024 04:45:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733921136; x=1734525936; darn=gnu.org; h=content-transfer-encoding:mime-version:message-id:date :gmane-reply-to-list:references:in-reply-to:subject:cc:to:from:from :to:cc:subject:date:message-id:reply-to; bh=KeBjO7oFr1j47iyNlxj6UYO2dVdZ9ijcv4mEdsBuHM8=; b=WC8lsQf73E58k3QrvkwA4t18Z9LJQkGXVRF/AYP1U+zof8f5EJlar+WStREuwuBXAP SRBS4hq9Dmn3BfZ+36/aC9ONXHheCIGQg364yNcMRbAfcUlB05PeN5r9HX6PVvfYSBGs CqAke2A9WxTjZr7rbdU9oD15IRzbS2Li3OukMUrG0TAT/YawDqeRiiX4WAA3aDZ4/ZGg 4LBjDo+gEyWlL14l5dSt3iIT70888GyJSCDN7SN3RZ6uu2SBDq9NcDHmaQMOBubSHoM3 ItayEWJ1ULvyi1Ta/eoW8We3Vvo5Z2Qzd7pby7Mo0F64SAME9ykvHxpllqlSuErysYXp 61SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733921136; x=1734525936; h=content-transfer-encoding:mime-version:message-id:date :gmane-reply-to-list:references:in-reply-to:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=KeBjO7oFr1j47iyNlxj6UYO2dVdZ9ijcv4mEdsBuHM8=; b=lNpVfs+ae8L6tBLuDrL6E8dwk5WfmIlDE0NU57EFpogSqjkW4L5tYx+CfliauSG2DJ YY/YcgLlJIkCFHrgn1OxWqL344nfKf8Sxs9BIpIBMd7X7e/77T1puC9wHMf64Z8h6Zc0 VJ1+b7POkTHgSoK1B0jPfeX51m2EnOIYb5cMhJdUx9G1qWp+PAVEzBIrvFoJPhbb1RBK H5rgD5JaoJXcya2oNRrW6u5lcCqUoGHE12fS/jbON9idacM0CVMWSIlZ7lJdlAc13kiP FkU1d6YPWfI0cZ4EuBuCjpWny9neGyKjKIrGOfr4nOWwyEUyAuJi9SqgLN8GT8dZQ2DP 3d2Q== X-Gm-Message-State: AOJu0YyKVrW79zXSp0Sj1oFfvG7CK7/33oRHIw3w6rPTPZcelltdg0gc ldU3kn5m1BBETCN9RGCbZ/NqNqeoRLb2Tr/C6dqXX3XkLe2Gpt9nuadEhg== X-Gm-Gg: ASbGncuPFupSD2MrS69kS7CNKCiaZJFguLk1gREoLIhku6CM4hwZXTjDfz5PQ+cygYg 7LSGm9Gj+V+65LusX5vHVbIXE/N+QmARQsjT/zOAHZZnDbCFfy7ZC2AkTrpdB81Lc3IRiBe/Mk6 vJMy295XqlLe1FKMt/9iibYkz6kSvtTFHxhN7tJv7Pc3QSNverItivGY5xYGUkBPBpBIcmxZg+H DHhU/DQzXj5YPynE9Bj2k9H6LzEhDEuirJlzRupaQ== X-Google-Smtp-Source: AGHT+IFowT8eDCsPVVZW0iYk26QtV5LK64hV9a+egojltuCQrS8IC39hbVqhL5mGWsoA5/HbdIpZUg== X-Received: by 2002:a5d:584a:0:b0:386:3afc:14a7 with SMTP id ffacd0b85a97d-3864de9e223mr1661372f8f.7.1733921135543; Wed, 11 Dec 2024 04:45:35 -0800 (PST) Original-Received: from rltb ([2a01:e0a:3f3:fb51:c52c:e130:63af:d25d]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3878248f697sm1218818f8f.12.2024.12.11.04.45.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 04:45:35 -0800 (PST) In-Reply-To: <7292e8f5-2be9-4c76-b473-882ff437ad93@risk-engineering.org> (Eric Marsden's message of "Wed, 11 Dec 2024 11:51:27 +0100") Gmane-Reply-To-List: yes Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=rpluim@gmail.com; helo=mail-wr1-x432.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:326349 Archived-At: >>>>> On Wed, 11 Dec 2024 11:51:27 +0100, Eric Marsden said: Eric> Hi, Eric> The attached patch adds support for the socket option TCP_NODELAY, Eric> to disable Nagle's algorithm. This means that network segments are Eric> sent as soon as possible, even when they contain little data. This Eric> reduces network latency on the network connection, but can lead to Eric> many small packets being sent. Eric> I have only tested on Linux/AMD64, but support for this socket op= tion Eric> is very widespread. If setting it fails you can get an error, so that=CA=BCs not a big deal. I should be able to verify it on macOS later this week. Eric> My motivation for adding this support is that Emacs is very slow Eric> when connecting to the PostgreSQL database over the network, using Eric> my pg-el library, and is unable to saturate CPU when sending a Eric> stream of messages. It is much faster when using a local Unix Eric> connection and saturates CPU. Eric> With this patch, a test case that takes 911 seconds goes down to Eric> 76 seconds (x 12 speedup). Eric> Eric ENOCOMMITMESSAGE Eric> diff --git a/doc/lispref/processes.texi b/doc/lispref/processes.t= exi Eric> index 79ef959ae65..93ac5a6aa7d 100644 Eric> --- a/doc/lispref/processes.texi Eric> +++ b/doc/lispref/processes.texi Eric> @@ -3090,6 +3090,13 @@ Network Options Eric> may be a period of time after the last use of that port (by any Eric> process on the host) where it is not possible to make a new serv= er on Eric> that port. Eric> + Eric> +@item :nodelay @var{nodelay-flag} Eric> +If @var{nodelay-flag} is non-@code{nil}, the @code{TCP_NODELAY} = option Eric> +is enabled on the socket. This disables the Nagle algorithm, mea= ning Eric> +that network segments are sent as soon as possible, even when th= ey Eric> +contain little data. This reduces network latency on the network Eric> +connection, but can lead to many small packets being sent. Eric> @end table =20 Eric> @defun set-network-process-option process option value &optional= no-error Eric> diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/byteco= mp.el Eric> index f058fc48cc7..07eb4690fce 100644 Eric> --- a/lisp/emacs-lisp/bytecomp.el Eric> +++ b/lisp/emacs-lisp/bytecomp.el Eric> @@ -6049,8 +6049,8 @@ bytecomp--check-keyword-args Eric> :buffer :host :service :type :family :local :remote = :coding Eric> :nowait :noquery :stop :filter :filter-multibyte :se= ntinel Eric> :log :plist :tls-parameters :server :broadcast :dont= route Eric> - :keepalive :linger :oobinline :priority :reuseaddr := bindtodevice Eric> - :use-external-socket) Eric> + :keepalive :linger :oobinline :priority :reuseaddr := nodelay Eric> + :bindtodevice :use-external-socket) Eric> '(:name :service)))) I think you need to update the docstring of `make-network-process' as well, as it=CA=BCs possible to set options on process creation. Eric> (provide 'byte-compile) Eric> diff --git a/src/process.c b/src/process.c Eric> index b71ba3daf2d..0b994d6c5b7 100644 Eric> --- a/src/process.c Eric> +++ b/src/process.c Eric> @@ -38,6 +38,7 @@ Copyright (C) 1985-1988, 1993-1996, 1998-1999, = 2001-2024 Free Software Eric> #include Eric> #include Eric> #include Eric> +#include Eric> #include =20 Eric> #else Eric> @@ -2860,6 +2861,9 @@ DEFUN ("set-process-datagram-address", Fset= _process_datagram_address, Sset_proce Eric> #endif Eric> #ifdef SO_REUSEADDR Eric> { ":reuseaddr", SOL_SOCKET, SO_REUSEADDR, SOPT_BOOL, OPIX_RE= USEADDR }, Eric> +#endif Eric> +#ifdef TCP_NODELAY Eric> + { ":nodelay", IPPROTO_TCP, TCP_NODELAY, SOPT_BOOL, OPIX_MISC= }, Eric> #endif Eric> { 0, 0, 0, SOPT_UNKNOWN, OPIX_NONE } Eric> }; I=CA=BCm not sure why we have a separate field for the option type, when the only socket option that gets special treatment is :reuseaddr. Oh well, hysterical raisins :-) Robert --=20