Skip to contentSkip to conversation

Is Git multithreaded ?

DISCUSSION Jeff King 2 participants 3 messages Jun 15, 2016 2 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

Hi list,

I wonder if Git is multithreaded ? For example, during a commit, does it process the files one after one, or does it use a set of threads, say 10, to process 10 files in parrallel ?

In the Git_Guide (http://wiki.sourcemage.org/Git_Guide.html), I can read this :

"T/o enable aut-detection for number of threads to use (good for multi-CPU or multi-core computers) for packing repositories, use: /////

////

///$ git config --global pack.threads "0"/ "

But it is not a lot explanatory (to me). In particular, if Git is multithreded and can be configured regarding the number of workers, I wonder in which operations it uses it ?

A clear view of this may be of interrest for hooks or filters that may use a daemon, in order to not have this daemon be a bottle-neck. It would make sense to start as many workers in the daemon that there are authorized ones in Git.

Cheers,

Laurent.

author
#2 lore raw
Quoted 1 line · Laurent Alebarde

I wonder if Git is multithreaded ?

A few selected operations are multi-threaded if you compile with thread support (i.e., do not set NO_PTHREADS when you build).

Quoted 3 lines

For example, during a commit, does it process the files one after one, or does it use a set of threads, say 10, to process 10 files in parrallel ?

Commit is not multi-threaded, for example.

Quoted 5 lines

In the Git_Guide (http://wiki.sourcemage.org/Git_Guide.html), I can read this :

"T/o enable aut-detection for number of threads to use (good for multi-CPU or multi-core computers) for packing repositories, use:

But object packing (used during fetch/push, and during git-gc) is multi-threaded (at least the delta compression portion of it is).

Quoted 3 lines

But it is not a lot explanatory (to me). In particular, if Git is multithreded and can be configured regarding the number of workers, I wonder in which operations it uses it ?

There is no master list, and the set of threaded operations changes from version to version. If you have a clone of the git source code, you can find the places where threads are used with

git grep NO_PTHREADS

as every threaded spot also has a single-threaded variant.

The current list is something like:

- finding delta candidates during pack-objects (gc, server side of fetch, client side of push); controlled by pack.threads, which defaults to "number of CPUs you have"

- resolving received objects in index-pack via fetch; controlled by pack.threads

- git grep on a working tree (I do not recall the details, but I think grepping a commit actually ends up slower when parallel); I do not think there is config to control this

- when stat()-ing files to refresh the index. This is not about parallel CPU performance, but about reducing latency on slow filesystems (e.g., NFS) by pipelining requests; controlled by core.preloadindex, which defaults to "false"

- git may fork to perform certain asynchronous operations (e.g., during a fetch, one process runs pack-objects to create the output, and the other speaks the git protocol, mostly just passing through the output to the client. On systems with threads, some of these operations are performed using a thread rather than fork. This is not about CPU performance, but about keeping the code simple (and cannot be controlled with config).

I hope that helps.

-Peff

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw

Yes it does help ! Thanks a lot Peff for your very complete answer.

Cheers,

Laurent.

Quoted 1 line · Jeff King

I hope that helps. -Peff