From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eric Marsden Newsgroups: gmane.emacs.bugs Subject: bug#74793: [PATCH] Add support for TCP_NODELAY on network streams Date: Wed, 11 Dec 2024 17:17:38 +0100 Message-ID: <49fb242c-2334-43be-8001-1c0443af9d34@risk-engineering.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------p43pADu1kURQRsYHXVS1F0XT" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26088"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird To: 74793@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Dec 11 17:18:27 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1tLPPu-0006hu-P7 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 11 Dec 2024 17:18:26 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLPPZ-0007vM-Dy; Wed, 11 Dec 2024 11:18:05 -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 1tLPPW-0007up-ND for bug-gnu-emacs@gnu.org; Wed, 11 Dec 2024 11:18:02 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tLPPW-00077R-4p for bug-gnu-emacs@gnu.org; Wed, 11 Dec 2024 11:18:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=From:MIME-Version:Date:To:Subject; bh=9sCXmNd9ZuXoBUnfukMflm7/R17st3JKaooLKA9DJdg=; b=gt82H+dYkVfS4SDg31Ct0eniXs9e0nTAadIvbqRdtmi/RCtv4tvm60SpBc5+QqRl3JciVZGuzzo7g5FBCViaJvzRHlL4G0fydjyx5U0qabz2lQDXGkiQcOQ89EWaAT+I4pLEbDr0SHou256Ji50USehsnBGKakN3tTIviCQ4GxPHrIr/mSIkHmNW2Gpo+edUaJvQ6gqFt09QOyUXSNX1IUnMNnsTTRnn3ia+UV+0Iy4jX5dXEi7wrqnH2K6TvPJzD11sncSSfxy4f7+yghAVHMlb+j+mHR0BH7fxui6yNOB2Kay78ft5ha5+/uek5IL9rCOq8lhtJ2yRw33SASg5lA==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tLPPV-0002LJ-RG for bug-gnu-emacs@gnu.org; Wed, 11 Dec 2024 11:18:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eric Marsden Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 11 Dec 2024 16:18:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 74793 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.17339338698972 (code B ref -1); Wed, 11 Dec 2024 16:18:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 11 Dec 2024 16:17:49 +0000 Original-Received: from localhost ([127.0.0.1]:35863 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tLPPI-0002Kd-SH for submit@debbugs.gnu.org; Wed, 11 Dec 2024 11:17:49 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:34914) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tLPPG-0002KR-Nq for submit@debbugs.gnu.org; Wed, 11 Dec 2024 11:17:47 -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 1tLPPG-0007tC-9n for bug-gnu-emacs@gnu.org; Wed, 11 Dec 2024 11:17:46 -0500 Original-Received: from mail.risk-engineering.org ([2a01:4f8:c0c:a3f8::1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tLPPE-00075X-0i for bug-gnu-emacs@gnu.org; Wed, 11 Dec 2024 11:17:46 -0500 DKIM-Signature: a=rsa-sha256; bh=9sCXmNd9ZuXoBUnfukMflm7/R17st3JKaooLKA9DJdg=; c=relaxed/relaxed; d=risk-engineering.org; h=Subject:Subject:Sender:To:To:Cc:From:From:Date:Date:MIME-Version:MIME-Version:Content-Type:Content-Type:Content-Transfer-Encoding:Reply-To:In-Reply-To:Message-Id:Message-Id:References:Autocrypt:Openpgp; i=@risk-engineering.org; s=default; t=1733933896; v=1; x=1734365896; b=WT6gXgYDfDwVJKagJxsAIdqKurP0PuEHGg8r+Iv5CCjY3w/W5JrgMMI0BHfBOsfYuhwSraVg 7Gfq42ODlxf7bzg9mO7GwY5JAaBquv1SeJFmhoNXrsj6e8S9O1g3t2mBDw3tzaFxFUf6YIxU0Aw jXK1ybz0KNV9sX8wdQ02YYbI8xum/2GHdO4AgnswT1KAprx5gyvnz4uyfa6XPCGDLuuu/V2QuTJ IH9cFjd+vFu4WT54AZDrM6xhnws7uE/7EOcp379QnCWB8MhyrdB+u2Tv/11PyF3zt59phJDBv1e 7qR+BMaq4eIpn6j0cgxsaWDtcqgYSaD8SrGb9WZfSNgiw== Original-Received: by mail.risk-engineering.org (envelope-sender ) with ESMTPS id 02fc7528; Wed, 11 Dec 2024 17:18:16 +0100 Content-Language: en-US Received-SPF: pass client-ip=2a01:4f8:c0c:a3f8::1; envelope-from=eric.marsden@risk-engineering.org; helo=mail.risk-engineering.org X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:296848 Archived-At: This is a multi-part message in MIME format. --------------p43pADu1kURQRsYHXVS1F0XT Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi, The attached patch adds support for the socket option TCP_NODELAY, to disable Nagle's algorithm. This means that network segments are sent as soon as possible, even when they contain little data. This reduces network latency on the network connection, but can lead to many small packets being sent. I have only tested on Linux/AMD64, but support for this socket option is very widespread. Patch reformatted following feedback from Robert Pluim and Eli Zaretskii. My motivation for adding this support is that Emacs is very slow when connecting to the PostgreSQL database over the network, using my pg-el library, and is unable to saturate CPU when sending a stream of messages. It is much faster when using a local Unix connection and saturates CPU. With this patch, a test case that takes 911 seconds goes down to 76 seconds (x 12 speedup). Eric --------------p43pADu1kURQRsYHXVS1F0XT Content-Type: text/x-patch; charset=UTF-8; name="net-tcp-nodelay.patch" Content-Disposition: attachment; filename="net-tcp-nodelay.patch" Content-Transfer-Encoding: base64 RnJvbSAxODhhZjk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