From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Michael Albinus Newsgroups: gmane.emacs.bugs Subject: bug#56342: TRAMP (sh) issues way too many commands, thus being very slow over high-ping networks Date: Sat, 02 Jul 2022 17:58:25 +0200 Message-ID: <8735fjh5ge.fsf@gmx.de> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2440"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: 56342@debbugs.gnu.org To: Paul Pogonyshev Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jul 02 17:59:11 2022 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 1o7fWZ-0000PZ-FB for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 02 Jul 2022 17:59:11 +0200 Original-Received: from localhost ([::1]:49424 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o7fWY-00055v-0q for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 02 Jul 2022 11:59:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34664) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7fWQ-00054Z-A7 for bug-gnu-emacs@gnu.org; Sat, 02 Jul 2022 11:59:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:48719) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o7fWQ-0001Yi-0n for bug-gnu-emacs@gnu.org; Sat, 02 Jul 2022 11:59:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1o7fWP-0000lR-T2 for bug-gnu-emacs@gnu.org; Sat, 02 Jul 2022 11:59:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Michael Albinus Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 02 Jul 2022 15:59:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 56342 X-GNU-PR-Package: emacs Original-Received: via spool by 56342-submit@debbugs.gnu.org id=B56342.16567775342923 (code B ref 56342); Sat, 02 Jul 2022 15:59:01 +0000 Original-Received: (at 56342) by debbugs.gnu.org; 2 Jul 2022 15:58:54 +0000 Original-Received: from localhost ([127.0.0.1]:42616 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o7fWD-0000l1-T3 for submit@debbugs.gnu.org; Sat, 02 Jul 2022 11:58:54 -0400 Original-Received: from mout.gmx.net ([212.227.17.21]:55131) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o7fVx-0000kX-Vi for 56342@debbugs.gnu.org; Sat, 02 Jul 2022 11:58:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1656777506; bh=MtM60nc1KMdSxWxSNJRbSiLze047/ykc1JWPMZZodhA=; h=X-UI-Sender-Class:From:To:Cc:Subject:References:Date:In-Reply-To; b=ZGgGx+frSJ7N9//b9DqHx0MhOWQpZ8v1uXYlqZ/2zOJWjwWgnQWMhPFKM9xzQeLQF X7QG/lM6uye1j2+eJkIGMjQ96pKW5+S5SdYh4oHJ+vrvrrzZFHOThkF7ZaBn4lD83y +el+OKdfXBkL5wUJCaFzTpwWJO2+8wEFxwTMK2vA= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Original-Received: from gandalf.gmx.de ([79.140.124.34]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1Mdvqg-1naGEm2Jx0-00b0Sv; Sat, 02 Jul 2022 17:58:26 +0200 In-Reply-To: (Paul Pogonyshev's message of "Fri, 1 Jul 2022 19:14:08 +0200") X-Provags-ID: V03:K1:vYFVPzj1cDr+YNIPnrd0wNeQwua1NszhmPQTBbcOcERKFm9lCpZ wVslu824VsW726KEL9kzzXrs8ILrUdEwqRDje1wf1kBihRij4c6RvtmlOYOypg5dWm7K+fR DXTuYFdA4u2mX5SwIlWvsZC00awDW9QiPESIfyPu27PgM2TU6hDawX7GZ5d3km0B1VsAuMq rtO+vj33ubDWyiuSlCudQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:CGXOlt0FqJo=:n7XoCTZWglEetoSHYmeQTM nb/Ls3/SbB1E1kXwA21ddZqWoCVdWAm8zyoEsY5WMTF711xBifq6liE2EEVqhlKi/Y07QWyOw qgBW8nD7hoNcAdZzCmE0L5xvyC+Ne7cUiu0ME+5a0xwmRh2MLt76cvQfcgybRfuAu18VItRHR M3+/xrgfKjeDxZl8O8WFJ7nE4XLOU/pMYtCb/aNg/ga1OjLI2bT0qidrFNi+/5My1GLiTPfPw 7KSkzqmCkm7waWpA6VVqAKozTXJ33SMeaVvuCeEFdIX73PUwbtKgY818maP8NBei3bmOnxskt nttMzQ43QmKqpP5S/IGf5XnpJZYmtEAUiTMfNpQd2kN/+j51g7oYz74SQEiofr5fuleElYjKh lar+9G905WvG/je1sktbp/oJcTX5l8tkcWfGgZ4SkOyVZeN9zs4kPkPNGWrG28zmZ7IjWnP9j RdVPhkoOBlHUdzeGb9YNf88NRg8Uiq4AUVMzHlnN0wUakwrU2qdgeexF8Nz7TpGuRStpcHk2F g12nUFawN9530vn08fsgxme5waLOnp4silRt/Ut0q9qy9zQ8bONQf4NQjHZgrzJ3DOJOUq/4e loeVp7/T7BOG/dWXTC+j8c5y7ak245GJ7Cs0h/+5uSf0ZcACPrtK6CL/H0n5iePqC5YrODhM0 jlfBmo5GgJgwmm0IgetD4i1kwiALd3yypOStHgtepH34WLn4leKtl+LQfqyu9yheSkvlPFqfa vJ4Y4Ai8/v8UT6bjigfEF9X1+l7XpwrPGxRP7oEPAIfiAxL3CteJV2gWvCxQwqD+7Jfg0P0E 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" Xref: news.gmane.io gmane.emacs.bugs:235923 Archived-At: Paul Pogonyshev writes: Hi Paul, > 1) check if connection is alive (`echo are you awake'); > 2) test if the file exists; > 3) creating a temporary file for the chunk to be inserted; I guess it > tries until it finds an unused filename, e.g. here it seems to be done > after `test -e /tmp/tramp.OD3cCu', which doesn't exist; > 4) 'touch' on the temporary file, presumably to create it; > 5) 'chmod' on the temporary, presumably so that other users cannot > read it; > 6) copying the requested chunk from the full file into the temporary > (using `dd'); > 7) finding the real name of the temporary with `readlink'; > 8) finding attributes of the temporary with `stat'; > 9) gzipping the temporary for transmition from the remote to the local > machine; > 10) testing if the temporary is a directory (WTF?); > 11) removing the temporary. > > I guess it should be obvious that this is a bit too much for one > `insert-file-contents' call. In general, I agree. However, some of the commands are caused by primitive file operations, like file-exists-p. Tramp cannot know what will be the next call, and it doesn't have all the opportunities to optimize, compared with the overall picture you see in the eleven steps. > Suggested improvements: > > * TRAMP should issue just one `stat' command to find out most of the > things about a file: whether it exists, if it is a directory, its real > name when dereferencing links and whatever stats it is used to find > now; from `$ stat --help' this seems to be possible. In other words, > TRAMP shouldn't use simple commands like `test -e': any ping, even > nominal, will negate any gains from using a tad faster command. > Instead, if it needs to find anything about a file, it should ask the > remote about as many things as possible in one go: it is very likely > that the additional information will be needed soon and even if not, > this is basically free compared to ping anyway. Not all remote hosts carry a stat command, and not all existing stat's are GNU compatible. But yes, if possible, Tramp shall gather as much information in one run, and cache the results for further use. I will see what could be done. Will come back with a proposal next days (note that this will be for Emacs 29, ie git master). > * TRAMP code should prefer the approach "try do something and handle > resulting errors" where possible. For example, don't check if the file > exists, try to read it right away and handle failures properly. Code > like `(when (file-exists-p ...) do-something)' adds an unnecessary > command call and creates a racing condition anyway. Also, error-free > requests should be more frequent, so they should be the main > optimization goal. I'm not sure if it is applicable to TRAMP itself > and doesn't come from a higher level, though. Indeed, this is not Tramp's responsibility. Tramp is a stupid library. If there is a call for file-exists-p, it must return the answer. It doesn't know what will be the next request. So I'm rather pesimistic that Tramp can improve here. Best regards, Michael.