Skip to content

Commit

Permalink
Use mmap storage in test for performance
Browse files Browse the repository at this point in the history
  • Loading branch information
anacrolix committed Jun 27, 2024
1 parent c981f5a commit 4da2fbf
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tests/peers-bootstrapping/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"path/filepath"
"time"

_ "github.com/anacrolix/envpprof"
"github.com/anacrolix/envpprof"
"github.com/anacrolix/log"
"github.com/anacrolix/sync"
"github.com/dustin/go-humanize"
Expand All @@ -18,6 +18,7 @@ import (
"github.com/anacrolix/torrent"
"github.com/anacrolix/torrent/bencode"
"github.com/anacrolix/torrent/metainfo"
"github.com/anacrolix/torrent/storage"
)

func assertNil(x any) {
Expand All @@ -37,6 +38,7 @@ func newClientConfig() *torrent.ClientConfig {
}

func main() {
defer envpprof.Stop()
tmpDir, err := os.MkdirTemp("", "peers-bootstrapping")
assertNil(err)
slog.Info("made temp dir", slog.String("tmpDir", tmpDir))
Expand All @@ -56,7 +58,7 @@ func main() {
var clients []*torrent.Client
var torrents []*torrent.Torrent
clientConfig := newClientConfig()
clientConfig.DataDir = sourceDir
clientConfig.DefaultStorage = storage.NewMMap(sourceDir)
initialClient, err := torrent.NewClient(clientConfig)
assertNil(err)
clientIndex := 0
Expand Down Expand Up @@ -91,7 +93,7 @@ func main() {
clientIndex := clientIndex
storageDir := filepath.Join(tmpDir, fmt.Sprintf("client%v", clientIndex))
clientConfig := newClientConfig()
clientConfig.DataDir = storageDir
clientConfig.DefaultStorage = storage.NewMMap(storageDir)
clientConfig.Logger = log.Default.WithValues(slog.Int("clientIndex", clientIndex))
//clientConfig.Logger.Levelf(log.Critical, "test")
client, err := torrent.NewClient(clientConfig)
Expand Down Expand Up @@ -132,4 +134,5 @@ func main() {
humanize.Bytes(uint64(read.Int64())),
)
}
assertNil(os.RemoveAll(tmpDir))
}

0 comments on commit 4da2fbf

Please sign in to comment.