进程创建时间、shell脚本和系统调用开销

ano*_*777 5 performance system-programming shell-script strace benchmark

我有一台使用 Arch Linux 和 Ubuntu (16.04) 双重启动的机器。

我最近开始使用Kakoune 文本编辑器,并注意到它的启动时间根据我使用的操作系统而有很大不同。但我相信根本问题并不是kakoune 直接造成的。

启动时,kakoune 运行一堆 shell 脚本,以启用与 x11 和 tmux、git、语法突出显示/颜色方案等的集成。可以禁用此功能,以便仅使用标志加载“vanilla”编辑器-n

命令:kak -e q将启动 kakoune,运行所有启动脚本并立即退出。

在 Arch 上:
time kak -e q需要1 秒
time kak -n -e q(无 shell 脚本),不到20 毫秒即可完成。

在 Ubuntu 上:
time kak -e q大约需要450 毫秒
time kak -n -e q,再次低于20 毫秒

在削减脂肪并删除一些启动脚本之后,我确实看到两个操作系统的改进与删除的数量成比例。

我使用UnixBench运行了一些基准测试,发现两个系统之间的主要差异体现在“进程创建”和“shell 脚本”测试中。

shell 脚本测试测量进程每分钟可以启动并获取 shell 脚本的一组(一个、两个、四个和八个并发副本)的次数,其中 shell 脚本对数据文件应用一系列转换。

这是相关的输出。“每秒循环次数”的单位越多越好:

Process creation (1 parallel copy of tests)
Arch:    3,822
Ubuntu:  5,297
Process creation (4 parallel copies of tests)
Arch:   18,935
Ubuntu: 30,341

Shell Scripts (1 concurrent) (1 parallel copy of tests)
Arch:      972
Ubuntu:  5,141
Shell Scripts (1 concurrent) (4 parallel copies of tests)
Arch:    7,697
Ubuntu: 24,942

Shell Scripts (8 concurrent) (1 parallel copy of tests)
Arch:      807
Ubuntu:  2,257
Shell Scripts (8 concurrent) (4 parallel copies of tests)
Arch:    1,289
Ubuntu:  3,001
Run Code Online (Sandbox Code Playgroud)

可以看到Ubuntu系统的性能要好得多。

我已经使用不同的登录 shell、终端模拟器、重新编译 kakoune、删除不需要的软件来清理磁盘等进行了测试。我确信这是瓶颈。

我的问题是:我可以做些什么来进一步研究这个问题并提高Arch Linux系统的性能以匹配Ubuntu?我应该考虑调整内核吗?

补充笔记:

  • 两个系统都使用相同类型的文件系统 (ext4)
  • 我更倾向于使用 Archlinux 系统,并且注意到性能随着时间的推移而下降
  • Arch 位于 /dev/sda1 上,大小约为 200GB。Ubuntu 位于 /dev/sda2,~500GB。1TB 硬盘。
  • 拱门uname -aLinux ark 4.14.13-1-ARCH #1 SMP PREEMPT Wed Jan 10 11:14:50 UTC 2018 x86_64 GNU/Linux
  • 乌班图uname -aLinux sierra 4.4.0-62-generic #83-Ubuntu SMP Wed Jan 18 14:10:15 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

谢谢

ilk*_*chu 1

Debian 和 Ubuntu 使用 dash as /bin/sh,它比 Bash 更快一些:

$ time for x in {1..1000} ; do /bin/bash -c 'true' ; done                                                                                                                                                                                                                                                      
real    0m1.894s

$ time for x in {1..1000} ; do /bin/sh -c 'true' ; done 
real    0m1.057s
Run Code Online (Sandbox Code Playgroud)

这与您的数字大致相同的面积(按比例)。

在 Debian 和 Ubuntu 中更改/bin/sh为 dash 而不是 Bash 很大程度上是因为性能:

切换默认 shell 的主要原因是效率。bash 是一个优秀的全功能 shell...但是,与 dash 相比,它相当大且启动和运行速度慢。

https://wiki.ubuntu.com/DashAsBinSh