7

After some pause (a few seconds) of idle I start typing and emacs does some network activities and because of my slow connection this looks like everything is slow and hanging all the time. I disabled all extra modes but this still happens, any idea what is going on?

UPDATE

This is what i get in tramp debug buffer:

21:57:55.654206 tramp-do-file-attributes-with-stat (5) # file attributes with stat: /home/u/f.htm
21:57:55.654709 tramp-send-command (6) # echo are you awake
21:57:57.373233 tramp-wait-for-regexp (6) # 
are you awake
///966dcbf73a99f3becae06a545679cb59#$
21:57:57.373649 tramp-send-command (6) # ( (test -e /home/u/f.htm || test -h /home/u/f.htm) && (\stat -c '((/////%N/////) %h %ue0 %ge0 %Xe0 %Ye0 %Ze0 %se0 /////%A///// t %ie0 -1)' /home/u/f.htm | sed -e 's/"/\\"/g' -e 's/\/\/\/\/\//"/g') || echo nil) 2>/dev/null; echo tramp_exit_status $?
2
  • Can you please add some more details? Where are you typing when this happens? Also try to reproduce the issue with emacs -Q or a minimal init file. May 16 '16 at 18:47
  • 1
    Added more details, with -Q got same behaviour
    – Dfr
    May 16 '16 at 19:07
5

When you start to type, Emacs starts to think about auto-saving. This could (or could not) include some checks on the remote side. Change the auto-save file location to your local directories, see the Tramp manual for recipes.

If you want to see in more detail what happens on the remote side, apply (setq tramp-verbose 6). There will be a Tramp debug buffer. Follow the lines which include the string (6), they show you the commands Tramp sends to the remote, and the command's output.

7
  • Added debug info to question, also I already have this in init file: (setq tramp-auto-save-directory "/tmp")
    – Dfr
    May 16 '16 at 19:03
  • This debug output is very short. I guess there is much more in. Could you pls send me the whole traces, off of sx? May 18 '16 at 10:56
  • Here is full listing: pastie.org/10842495
    – Dfr
    May 18 '16 at 15:22
  • The traces tell us the story. Nothing about auto-save or backup. But when you have started to type after a while, Emacs wants to know whether the file was changed in the meantime, since last interaction. And so it goes remote, in order to check it. May 19 '16 at 18:41
  • Ok, now i understand what is going on, but this check for remote files via slow connection becomes a disservice, any idea how to diable it ?
    – Dfr
    May 23 '16 at 9:04
3

According to your log and my own experiences, "ssh" command is executed several times. On slow connections this could take pretty long for each ssh command. For recent OpenSSH you can try to reuse connections, check this link here and set your ~/.ssh/config as follows (remember to mkdir ~/.ssh/sockets first):

Host *
ControlMaster auto
ControlPath ~/.ssh/sockets/%r@%h-%p
ControlPersist 600

Then you need to disable tramp's default ControlMaster settings in your ~/.emacs by

     (setq tramp-ssh-controlmaster-options "")

The next thing you will face is the auto-backup problem that Michael mentioned in his reply. My personal solution to this is combining the suggestion of tramp manual here and this emacs wiki, add the following code into ~/.emacs. A new variable disable-tramp-backups is introduced where you can list what kind of tramp connections you don't want to have backups. My following example disabled auto-backup for all tramped files. You can modify it according to my other examples in the comments.

;;(setq disable-tramp-backups nil) ;; allow all tramp files to be backuped
;;(setq disable-tramp-backups '("su" "sudo")) ;; only 'su' and 'sudo'
;;(setq disable-tramp-backups '("ssh" "sftp")) ;; only 'ssh' and 'sftp'
(defvar disable-tramp-backups '(all))

(eval-after-load "tramp"
  '(progn
     ;; Modified from https://www.gnu.org/software/emacs/manual/html_node/tramp/Auto_002dsave-and-Backup.html
     (setq backup-enable-predicate
           (lambda (name)
             (and (normal-backup-enable-predicate name)
              ;; Disable all tramp backups
              (and disable-tramp-backups
                   (member 'all disable-tramp-backups)
                   (not (file-remote-p name 'method)))
              (not ;; disable backup for tramp with the listed methods
               (let ((method (file-remote-p name 'method)))
                 (when (stringp method)
                   (member method disable-tramp-backups)))))))

     (defun tramp-set-auto-save--check (original)
       (if (funcall backup-enable-predicate (buffer-file-name))
           (funcall original)
         (auto-save-mode -1)))

     (advice-add 'tramp-set-auto-save :around #'tramp-set-auto-save--check)

     ;; Use my ~/.ssh/config control master settings according to https://puppet.com/blog/speed-up-ssh-by-reusing-connections
     (setq tramp-ssh-controlmaster-options "")))

The last thing you might need to take care is the hooks or idle-time functions you set in your ~/.emacs. If you ever invoke shell to run commands (e.g. via `shell-command' function ...) in those hooks/idle-time functions, those commands might be passed to remote machine and will be very slow too. You need to wrap those shell commands with the current buffer changed to somewhere else, like the 'scratch' buffer, for example:

(with-current-buffer (get-buffer "*scratch*")
    (shell-command "ls -al")) ;; just a sample shell command

If there are still other slow down problems, enable "Enter Debugger on Quit/C-g" option in Emacs. When emacs seems "hanging" there press C-g and see which function it stuck in.

That's about it. Hope this helps. If you find anything else, please also let me know.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.