【问题标题】:git-grep not using multiple threadsgit-grep 不使用多个线程
【发布时间】:2019-04-16 10:18:11
【问题描述】:

我正在尝试使用git grep 来搜索一个非常大的存储库的所有修订版。我使用的命令是:

$ git rev-list --all | xargs git grep -I --threads 10 --line-number \
  --only-matching "SomeString"

我在mac上使用的是最新的正式版git:

$ git --version
git version 2.19.1

这需要很长时间,查看活动监视器 git 只使用一个线程。但是docs 说它应该默认使用 8。它只使用一个带有或不带有--threads <num> 选项的线程。我也没有任何其他可以覆盖此设置的配置集:

$ git config --list
credential.helper=osxkeychain
user.name=****
user.email=****

任何想法我错过了什么?其他人可以使用git-grep 并确认他们看到了多个线程吗?

感谢您的帮助

【问题讨论】:

    标签: git grep xargs git-grep


    【解决方案1】:

    我想知道是不是因为您使用的是| xargs,它等待stdin 上的输入。由于git rev-list 的输出是单个流,xargs 默认只使用一个进程:

    -P max-procs, --max-procs=max-procs
                  Run up to max-procs processes at a time; **the default is 1**.  If
                  max-procs is 0, xargs will run as many processes as possible
                  at a time.
    

    所以尝试使用上面的标志来增加它:

    git rev-list --all | xargs -P 10 git grep -I --threads 1 --line-number \
        --only-matching "SomeString"
    

    这将产生多个git greps,而不是使git grep 能够使用多个线程,因此是一种功能性的答案。

    【讨论】:

    • 我怀疑应该是xargs -P 10 git grep -I --threads 1
    • @phd 是的,这更有意义。我会更新;谢谢!不过,这仅提供了一个功能上近似的解决方案,因为 git grep 实际上不会是多线程的,这可能会对 OP 运行的架构产生影响。
    • @Chris 输出可能是交错的? - 我也在想这个。老实说,我不确定。 (无论如何,试一试,但我现在还不接受 - 留一些时间让其他人贡献更聪明的东西)。
    • @msanford 是的,我现在正在运行测试。以前大约需要8个小时。笔记本电脑听起来像是即将起飞,所以现在肯定会耗尽资源。怀疑你的方法会快很多,完成后会回复结果。如果有人在传递这么多参数时知道如何使用 git 的内部线程,也会推迟接受一段时间。
    • 准备接受这个答案。它将时间从 8 小时缩短到一个多小时。
    【解决方案2】:

    分配给xargs 的线程数将取决于git grep 使用的线程数。

    git grep 以前默认为 8。

    但是:

    使用 Git 2.26(2020 年第一季度),这是现在的核心数。

    commit f1928f0commit 70a9fefcommit 1184a95commit 6c30762commit c441ea4commit d799242commit 1d1729ccommit 31877c9commit b1fc9dacommit faf123ccommit faf123c987654332 @(2020 年 1 月 16 日)Matheus Tavares (matheustavares)
    (由 Junio C Hamano -- gitster -- 合并到 commit 56ceb64,2020 年 2 月 14 日)

    grep:没有。核心数作为默认编号。线程数

    签字人:Matheus Tavares

    --threads没有指定时,git grep默认使用8个线程。

    对于内核较少的机器,这个固定数字可能太多,而对于内核较多的机器,这个固定数字可能太少。
    因此,改为使用机器中可用的逻辑内核数,这似乎会带来最佳的整体性能。

    以下测量值对应于铬存储库中 30 次 git grep 执行的平均经过时间,置信区间为 95%(每组 30 次在 2 次预热运行后执行)。
    正则表达式 1 是“abcd[02]”,正则表达式 2 是“(static|extern) (int|double) \*”。

    (在 'git gc' 执行之后,Chromium 在提交 03ae96f(“在 DSF=2 处添加过滤器测试”,04-06-2019)的回购。)

          |          Working tree         |           Object Store
    ------|-------------------------------|--------------------------------
     #ths |  Regex 1      |  Regex 2      |   Regex 1      |   Regex 2
    ------|---------------|---------------|----------------|---------------
      32  |  2.92s ± 0.01 |  3.72s ± 0.21 |   5.36s ± 0.01 |   6.07s ± 0.01
      16  |  2.84s ± 0.01 |  3.57s ± 0.21 |   5.05s ± 0.01 |   5.71s ± 0.01
       8  |  2.53s ± 0.00 |  3.24s ± 0.21 |   4.86s ± 0.01 |   5.48s ± 0.01
       4  |  2.43s ± 0.02 |  3.22s ± 0.20 |   5.22s ± 0.02 |   6.03s ± 0.02
       2  |  3.06s ± 0.20 |  4.52s ± 0.01 |   7.52s ± 0.01 |   9.06s ± 0.01
       1  |  6.16s ± 0.01 |  9.25s ± 0.02 |  14.10s ± 0.01 |  17.22s ± 0.01
    

    上述测试是在运行 Debian 10.0 的台式机上进行的,该台式机配备 Intel(R) Xeon(R) CPU E3-1230 V2(4 核 w/超线程)、32GB RAM 和 7200 rpm、SATA 3.1 HDD。

    下面,我们在一台配备 SSD 的机器上重复测试:配备 Intel(R) i7-7700HQ(4 核 w/超线程)和 16GB RAM 的 Manjaro 笔记本电脑:

          |          Working tree          |           Object Store
    ------|--------------------------------|--------------------------------
     #ths |  Regex 1      |  Regex 2       |   Regex 1      |   Regex 2
    ------|---------------|----------------|----------------|---------------
      32  |  3.29s ± 0.21 |   4.30s ± 0.01 |   6.30s ± 0.01 |   7.30s ± 0.02
      16  |  3.19s ± 0.20 |   4.14s ± 0.02 |   5.91s ± 0.01 |   6.83s ± 0.01
       8  |  2.90s ± 0.04 |   3.82s ± 0.20 |   5.70s ± 0.02 |   6.53s ± 0.01
       4  |  2.84s ± 0.02 |   3.77s ± 0.20 |   6.19s ± 0.02 |   7.18s ± 0.02
       2  |  3.73s ± 0.21 |   5.57s ± 0.02 |   9.28s ± 0.01 |  11.22s ± 0.01
       1  |  7.48s ± 0.02 |  11.36s ± 0.03 |  17.75s ± 0.01 |  21.87s ± 0.08
    

    【讨论】:

      猜你喜欢
      • 2019-04-12
      • 2015-01-13
      • 1970-01-01
      • 2013-01-24
      • 1970-01-01
      • 2020-05-10
      • 1970-01-01
      • 2023-01-13
      • 1970-01-01
      相关资源
      最近更新 更多