Skip to content

Commit

Permalink
Improve HardlinkDir performance
Browse files Browse the repository at this point in the history
  • Loading branch information
airhorns committed May 6, 2024
1 parent 332fe4e commit fed2e39
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ test-fuzz: export DL_SKIP_SSL_VERIFICATION=1
test-fuzz: reset-db
go run cmd/fuzz-test/main.go --host $(GRPC_HOST) --iterations 1000 --projects 5

bench: export DB_URI = postgres://$(DB_USER):$(DB_PASS)@$(DB_HOST):5432/dl_tests
bench: migrate
cd test && go test -bench . -run=^#

reset-db: migrate
psql $(DB_URI) -c "truncate dl.objects; truncate dl.contents; truncate dl.projects; truncate dl.cache_versions;"

Expand Down
25 changes: 25 additions & 0 deletions test/hardlink_dir_benchmark_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package test

import (
"fmt"
"os"
"path"
"testing"

"github.com/gadget-inc/dateilager/internal/files"
)

func BenchmarkHardlinkDir(b *testing.B) {
wd, err := os.Getwd()
if err != nil {
b.Error(err)
}

bigDir := path.Join(wd, "../node_modules")
tmpDir := emptyTmpDir(b)
defer os.RemoveAll(tmpDir)

for n := 0; n < b.N; n++ {
files.HardlinkDir(bigDir, path.Join(tmpDir, "node_modules", fmt.Sprintf("%d", n)))

Check failure on line 23 in test/hardlink_dir_benchmark_test.go

View workflow job for this annotation

GitHub Actions / golangci

Error return value of `files.HardlinkDir` is not checked (errcheck)
}
}
6 changes: 4 additions & 2 deletions test/shared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,11 @@ func writeFile(t *testing.T, dir string, path string, content string) {
require.NoError(t, err, "write file %v", path)
}

func emptyTmpDir(t *testing.T) string {
func emptyTmpDir(t testing.TB) string {
dir, err := os.MkdirTemp("", "dateilager_tests_")
require.NoError(t, err, "create temp dir")
if err != nil {
t.Fatal(err)
}

return dir
}
Expand Down

0 comments on commit fed2e39

Please sign in to comment.