From: Matt Joiner <anacrolix@gmail.com>
Date: Thu, 27 Jun 2024 05:49:13 +0000 (+1000)
Subject: Use mmap storage in test for performance
X-Git-Tag: v1.57.0~22
X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=4da2fbf3c70cf893b6ff37b05108e629a316631c;p=btrtrc.git

Use mmap storage in test for performance
---

diff --git a/tests/peers-bootstrapping/main.go b/tests/peers-bootstrapping/main.go
index 4114c5c3..2e0b3822 100644
--- a/tests/peers-bootstrapping/main.go
+++ b/tests/peers-bootstrapping/main.go
@@ -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"
@@ -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) {
@@ -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))
@@ -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
@@ -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)
@@ -132,4 +134,5 @@ func main() {
 			humanize.Bytes(uint64(read.Int64())),
 		)
 	}
+	assertNil(os.RemoveAll(tmpDir))
 }