Skip to content

Commit 218389b

Browse files
peffgitster
authored andcommitted
p5302: count up to online-cpus for thread tests
When PERF_EXTRA is enabled, p5302 checks the performance of index-pack with various numbers of threads. This can be useful for deciding what the default should be (which is currently capped at 3 threads based on the results of this script). However, we only go up to 8 threads, and modern machines may have more. Let's get the number of CPUs from test-tool, and test various numbers of threads between one and that maximum. Note that the current tests aren't all identical, as we have to set GIT_FORCE_THREADS for the --threads=1 test (which measures the overhead of starting a single worker thread versus the "0" case of using the main thread). To keep the loop simple, we'll keep the "0" case out of it, and set GIT_FORCE_THREADS=1 for all of the other cases (it's a noop for all but the "1" case, since numbers higher than 1 would always need threads). Note also that we could skip running "test-tool" if PERF_EXTRA isn't set. However, there's some small value in knowing the number of threads, so that we can mark each test as skipped in the output. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4727425 commit 218389b

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

t/perf/p5302-pack-index.sh

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,36 @@ test_expect_success 'repack' '
1313
export PACK
1414
'
1515

16-
test_perf PERF_EXTRA 'index-pack 0 threads' '
17-
rm -rf repo.git &&
18-
git init --bare repo.git &&
19-
GIT_DIR=repo.git git index-pack --threads=1 --stdin < $PACK
16+
# Rather than counting up and doubling each time, count down from the endpoint,
17+
# halving each time. That ensures that our final test uses as many threads as
18+
# CPUs, even if it isn't a power of 2.
19+
test_expect_success 'set up thread-counting tests' '
20+
t=$(test-tool online-cpus) &&
21+
threads= &&
22+
while test $t -gt 0
23+
do
24+
threads="$t $threads"
25+
t=$((t / 2))
26+
done
2027
'
2128

22-
test_perf PERF_EXTRA 'index-pack 1 thread ' '
23-
rm -rf repo.git &&
24-
git init --bare repo.git &&
25-
GIT_DIR=repo.git GIT_FORCE_THREADS=1 git index-pack --threads=1 --stdin < $PACK
26-
'
27-
28-
test_perf PERF_EXTRA 'index-pack 2 threads' '
29-
rm -rf repo.git &&
30-
git init --bare repo.git &&
31-
GIT_DIR=repo.git git index-pack --threads=2 --stdin < $PACK
32-
'
33-
34-
test_perf PERF_EXTRA 'index-pack 4 threads' '
29+
test_perf PERF_EXTRA 'index-pack 0 threads' '
3530
rm -rf repo.git &&
3631
git init --bare repo.git &&
37-
GIT_DIR=repo.git git index-pack --threads=4 --stdin < $PACK
32+
GIT_DIR=repo.git git index-pack --threads=1 --stdin < $PACK
3833
'
3934

40-
test_perf PERF_EXTRA 'index-pack 8 threads' '
41-
rm -rf repo.git &&
42-
git init --bare repo.git &&
43-
GIT_DIR=repo.git git index-pack --threads=8 --stdin < $PACK
44-
'
35+
for t in $threads
36+
do
37+
THREADS=$t
38+
export THREADS
39+
test_perf PERF_EXTRA "index-pack $t threads" '
40+
rm -rf repo.git &&
41+
git init --bare repo.git &&
42+
GIT_DIR=repo.git GIT_FORCE_THREADS=1 \
43+
git index-pack --threads=$THREADS --stdin <$PACK
44+
'
45+
done
4546

4647
test_perf 'index-pack default number of threads' '
4748
rm -rf repo.git &&

0 commit comments

Comments
 (0)