测试 ELPA 镜像速度以及获取最后更新时间

发现 ELPA 镜像又没有更新了。不想每次都打开浏览器查看镜像网站同步状态,于是把自己用的 find-fastest-mirror-for-me 函数改了一下,输出结果加上最后更新时间戳(遗憾的是 gitlab/github 的 http headers 不包含更新时间戳):

image

(defun find-fastest-mirror-for-me ()
  "Find the fatest mirror for me.

Inspied by @xuchunyang https://emacs-china.org/t/elpa/11192/9"
  (interactive)
  (require 'request)
  (with-output-to-temp-buffer "*Elpa mirror test*"
    (princ "  score (s)  mirror                        last updated\n")
    (princ "-----------  ----------------------------  ------------------\n"))
  (dolist (mirror package-mirror-alist)
    (let ((url (cdr (assoc "melpa" mirror)))
          (begin-time (float-time (current-time)))
          (request-backend (car '(curl url-retrieve))))
      (request (concat url "archive-contents")
        :timeout 30
        :complete
        (cl-function
         (lambda (&key response symbol-status &allow-other-keys)
           (with-current-buffer "*Elpa mirror test*"
             (goto-char (point-max))
             (let ((inhibit-read-only t))
               (insert (format "%11s  %-29s [%s]\n"
                               (if (eq symbol-status 'success)
                                   (format
                                    "%6fs"
                                    (- (float-time (current-time)) begin-time))
                                 symbol-status)
                               (url-host (url-generic-parse-url url))
                               (if (eq symbol-status 'success)
                                   (request-response-header response "Last-Modified"))))))))))))

代码基于 @xuchunyang 的《 本地测试 ELPA 镜像的速度 - #9,来自 xuchunyang 》,并改为异步请求(依赖 request 包),齐发并进节省时间。结果也不排序,先返回先打印。

使用时需预先定一个 package-mirror-alist 变量,其各式为:

(defconst package-mirror-alist
  '((default
     ("gnu"          . "https://elpa.gnu.org/packages/")
     ("melpa"        . "https://melpa.org/packages/")
     ("org"          . "https://orgmode.org/elpa/"))
    (emacs-china
     ("gnu"          . "https://elpa.emacs-china.org/gnu/")
     ("melpa"        . "https://elpa.emacs-china.org/melpa/")
     ("org"          . "https://elpa.emacs-china.org/org/"))
    ...))

有这个变量之后,切换镜像也很方便:(setq package-archives (assoc-default 'emacs-china package-mirror-alist))

1 个赞

Emacs China ELPA 镜像的 Rsync 服务停止了,下游没法更新。我现在不管理了,不清楚具体情况,

➜  ~ rsync --list-only rsync://elpa.emacs-china.org/elpa/
rsync: failed to connect to elpa.emacs-china.org: Connection refused (61)
rsync error: error in socket IO (code 10) at /System/Volumes/Data/SWE/macOS/BuildRoots/d7e177bcf5/Library/Caches/com.apple.xbs/Sources/rsync/rsync-55/rsync/clientserver.c(106) [receiver=2.6.9]
➜  ~

只有源头 melpa.org 在更新,镜像全部停更了,d12frosted 也已两周没更新:

  score (s)  mirror                        last updated
-----------  ----------------------------  ------------------
      error  mirrors.nju.edu.cn            [nil]
  3.803740s  mirrors.cloud.tencent.com     [Sat, 21 Aug 2021 20:23:55 GMT]
 14.012204s  gitlab.com/d12frosted         [Fri, 10 Sep 2021 04:09:26 GMT]
 14.065581s  mirrors.tuna.tsinghua.edu.cn  [Fri, 17 Sep 2021 00:25:00 GMT]
 14.148432s  mirrors.sjtug.sjtu.edu.cn     [Fri, 17 Sep 2021 00:25:00 GMT]
 14.484564s  melpa.org                     [Thu, 30 Sep 2021 21:31:28 GMT]
 16.128350s  mirrors.ustc.edu.cn           [Sun, 12 Sep 2021 14:09:43 GMT]
    timeout  elpa.emacs-china.org          [nil]
    timeout  mirrors.163.com               [nil]
1 个赞

GitHub 上 d12frosted/elpa-mirror 还是更新的,而国内大部分 elpa 镜像源都是基于本站的。

我用了1楼的代码,报错error in process sentinel: Symbol’s value as variable is void: begin-time,是哪里缺少设置么?

默认地址选的是本站, 版本:emacs 27.2 OS: mint 20.2

估计是没开启 lexical-binding

1 个赞