Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: benchmark for parallel deletion #344

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ benchmark:
'gdu -npc ~' 'gdu -gnpc ~' 'gdu -npc --use-storage ~'
sudo cpupower frequency-set -g schedutil

benchmark-deletion:
hyperfine \
--export-markdown=bench-delete.md \
--prepare 'cd test; git init . ; fallocate -l 1G .git/info/file ; dd if=/dev/urandom of=.git/refs/file bs=64M count=8 iflag=fullblock ; dd if=/dev/urandom of=.git/objects/file bs=64M count=8 iflag=fullblock ; cd ..' \
'go run ./cmd/deleter/main.go ./test/.git' \
'go run ./cmd/deleter/main.go --parallel ./test/.git'

clean:
go mod tidy
-rm coverage.txt
Expand Down
4 changes: 4 additions & 0 deletions bench-delete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|:---|---:|---:|---:|---:|
| `go run ./cmd/deleter/main.go ./test/.git` | 840.3 ± 648.5 | 504.2 | 2137.6 | 1.00 |
| `go run ./cmd/deleter/main.go --parallel ./test/.git` | 902.1 ± 885.1 | 476.1 | 3168.0 | 1.07 ± 1.34 |
109 changes: 109 additions & 0 deletions cmd/deleter/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package main

import (
"flag"
"fmt"
"io"
"os"
"path/filepath"
"runtime/trace"
"time"

"github.com/dundee/gdu/v5/pkg/fs"
"github.com/dundee/gdu/v5/pkg/remove"
)

func main() {
inParallel := flag.Bool("parallel", false, "Delete in parallel")
tracing := flag.Bool("trace", false, "Collect CPU trace")
flag.Parse()
args := flag.Args()

if len(args) < 1 {
fmt.Println("Usage: [--parallel] directory_to_delete")
return
}

if info, err := os.Stat(args[0]); os.IsNotExist(err) {
fmt.Println("Path does not exist")
return
} else if !info.IsDir() {
fmt.Println("Path is not directory")
return
}
path, err := filepath.Abs(args[0])
if err != nil {
fmt.Println("Cannot convert to absolute: ", err.Error())
}

deleter := remove.RemoveItemFromDir
if *inParallel {
deleter = remove.RemoveItemFromDirParallel
}

if *tracing {
f, err := os.Create("trace.out")
if err != nil {
fmt.Println("Trace file cannot be created: ", err.Error())
return
}
trace.Start(f)

Check failure on line 50 in cmd/deleter/main.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `trace.Start` is not checked (errcheck)
}

err = deleter(NewDeletedItem(""), NewDeletedItem(path))
if err != nil {
fmt.Println("Failed with: ", err.Error())
}
trace.Stop()
}

func NewDeletedItem(path string) fs.Item {
return &DeletedItem{
Path: path,
}
}

type DeletedItem struct {
Path string
}

func (p *DeletedItem) GetPath() string {
return p.Path
}
func (p *DeletedItem) GetFilesLocked() fs.Files {
var items []fs.Item
entries, err := os.ReadDir(p.Path)
if err != nil {
panic(err)
}

for _, entry := range entries {
path := filepath.Join(p.Path, entry.Name())
items = append(items, NewDeletedItem(path))
}
return items
}
func (p *DeletedItem) IsDir() bool { return true }
func (f *DeletedItem) RemoveFile(item fs.Item) {}

func (p *DeletedItem) GetName() string { panic("must not be called") }
func (p *DeletedItem) GetFlag() rune { panic("must not be called") }
func (p *DeletedItem) GetSize() int64 { panic("must not be called") }
func (p *DeletedItem) GetType() string { panic("must not be called") }
func (p *DeletedItem) GetUsage() int64 { panic("must not be called") }
func (p *DeletedItem) GetMtime() time.Time { panic("must not be called") }
func (p *DeletedItem) GetItemCount() int { panic("must not be called") }
func (p *DeletedItem) GetParent() fs.Item { panic("must not be called") }
func (p *DeletedItem) SetParent(fs.Item) { panic("must not be called") }
func (p *DeletedItem) GetMultiLinkedInode() uint64 { panic("must not be called") }
func (p *DeletedItem) EncodeJSON(writer io.Writer, topLevel bool) error { panic("must not be called") }
func (p *DeletedItem) UpdateStats(linkedItems fs.HardLinkedItems) { panic("must not be called") }
func (p *DeletedItem) AddFile(fs.Item) { panic("must not be called") }
func (p *DeletedItem) GetFiles() fs.Files { panic("must not be called") }
func (p *DeletedItem) RLock() func() { panic("must not be called") }
func (p *DeletedItem) SetFiles(fs.Files) { panic("must not be called") }
func (p *DeletedItem) GetItemStats(
linkedItems fs.HardLinkedItems,
) (int, int64, int64) {
panic("must not be called")
}
Binary file added trace-parallel.out
Binary file not shown.
Binary file added trace-single.out
Binary file not shown.
Loading