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.devel Subject: PATCH: add support for TCP_NODELAY on network streams Date: Wed, 11 Dec 2024 11:51:27 +0100 Message-ID: <7292e8f5-2be9-4c76-b473-882ff437ad93@risk-engineering.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------cDfWpXr8QlhSW7XUot7nCh4D" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1895"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Dec 11 11:52:19 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 1tLKKI-0000Ic-Aa for ged-emacs-devel@m.gmane-mx.org; Wed, 11 Dec 2024 11:52:18 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLKJi-0004XE-FD; Wed, 11 Dec 2024 05:51:42 -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 1tLKJf-0004Wy-0z for emacs-devel@gnu.org; Wed, 11 Dec 2024 05:51:39 -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 1tLKJa-0003LJ-Eq for emacs-devel@gnu.org; Wed, 11 Dec 2024 05:51:36 -0500 DKIM-Signature: a=rsa-sha256; bh=vs+91Rjq+gyJJP/tTxh9bxF/WA9kj2aMV4aVYrUmKZU=; 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=1733914326; v=1; x=1734346326; b=VhkG20HHnZPR4tRLMG1W7REDIdXrx5ihiZBjsoHyNoxZ12tqHw4jOyNazOBhZi3Q8Razr2Kh QK+SHTjeYKz/YvhM4Q2R6Bv1DY2L/cynVXiTq+Y6OLuC9yqxIe/ll98uwJ9xcRSd+iO9RbxTFYR mToq6obsxB02mDMafUPaUJkROqr16jpVT1ZqxwluYlO6fODxLfrGrOs1K0NXc2K4szWGOKnwyu9 Dl/DQVOeizrC3RI1peO3aMfmOxNN6R2KIkCY6AHf8x+4PP8gb7eCju+JaCNFPtORRgJAiRffoP5 5I8i38XkMEZ66H/R+0yD8djp/MJsoSB/Mj4mg8fB78toQ== Original-Received: by mail.risk-engineering.org (envelope-sender ) with ESMTPS id cbea3018; Wed, 11 Dec 2024 11:52:06 +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: 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:326342 Archived-At: This is a multi-part message in MIME format. --------------cDfWpXr8QlhSW7XUot7nCh4D 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. 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 --------------cDfWpXr8QlhSW7XUot7nCh4D Content-Type: text/x-patch; charset=UTF-8; name="add-tcp-nodelay.diff" Content-Disposition: attachment; filename="add-tcp-nodelay.diff" Content-Transfer-Encoding: base64 ZGlmZiAtLWdpdCBhL2RvYy9saXNwcmVmL3Byb2Nlc3Nlcy50ZXhpIGIvZG9jL2xpc3ByZWYv cHJvY2Vzc2VzLnRleGkKaW5kZXggNzllZjk1OWFlNjUuLjkzYWM1YTZhYTdkIDEwMDY0NAot LS0gYS9kb2MvbGlzcHJlZi9wcm9jZXNzZXMudGV4aQorKysgYi9kb2MvbGlzcHJlZi9wcm9j ZXNzZXMudGV4aQpAQCAtMzA5MCw2ICszMDkwLDEzIEBAIE5ldHdvcmsgT3B0aW9ucwogbWF5 IGJlIGEgcGVyaW9kIG9mIHRpbWUgYWZ0ZXIgdGhlIGxhc3QgdXNlIG9mIHRoYXQgcG9ydCAo YnkgYW55CiBwcm9jZXNzIG9uIHRoZSBob3N0KSB3aGVyZSBpdCBpcyBub3QgcG9zc2libGUg dG8gbWFrZSBhIG5ldyBzZXJ2ZXIgb24KIHRoYXQgcG9ydC4KKworQGl0ZW0gOm5vZGVsYXkg QHZhcntub2RlbGF5LWZsYWd9CitJZiBAdmFye25vZGVsYXktZmxhZ30gaXMgb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