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

test: Querying files from a large number of files takes time #507

Merged
merged 1 commit into from
Jan 4, 2024
Merged
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
47 changes: 47 additions & 0 deletions piecestorage/filestore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import (
"crypto/rand"
"fmt"
"io"
rand2 "math/rand"
"os"
path2 "path"
"path/filepath"
"testing"
"time"

"github.com/google/uuid"

Expand All @@ -24,6 +26,7 @@ func TestReWrite(t *testing.T) {
name := "market-test-tmp"
filePath := path2.Join(path, name)
_ = os.Remove(filePath)
defer os.RemoveAll(path) // nolint

ctx := context.TODO()
ifs, err := NewFsPieceStorage(&config.FsPieceStorage{ReadOnly: false, Path: path})
Expand Down Expand Up @@ -130,3 +133,47 @@ func TestReWrite(t *testing.T) {
require.Error(t, err)
assert.Nil(t, mounterReader)
}

func TestLargeFile(t *testing.T) {
path := path2.Join(os.TempDir(), "market-test-tmp")
_ = os.MkdirAll(path, os.ModePerm)
defer os.RemoveAll(path) // nolint

ctx := context.TODO()
ifs, err := NewFsPieceStorage(&config.FsPieceStorage{ReadOnly: false, Path: path})
require.NoErrorf(t, err, "open file storage")

for i := 0; i < 100; i++ {
if i%2 == 0 {
tmpDir := fmt.Sprintf("tmp_%d", i)
require.NoError(t, os.MkdirAll(filepath.Join(path, tmpDir), os.ModePerm))
for j := 0; j < 3000; j++ {
assert.NoError(t, os.WriteFile(filepath.Join(path, tmpDir, fmt.Sprintf("tmp_%d_%d", i, j)), []byte("test"), os.ModePerm))
}
continue
}
for j := 0; j < 600; j++ {
assert.NoError(t, os.WriteFile(filepath.Join(path, fmt.Sprintf("%d_%d", i, j)), []byte("test"), os.ModePerm))
}
}

var fileName string
for i := 0; i < 100; i += 3 {
if i%2 == 0 {
fileName = fmt.Sprintf("tmp_%d_%d", i, rand2.Intn(3000))
} else {
fileName = fmt.Sprintf("%d_%d", i, rand2.Intn(600))
}

start := time.Now()
_, err = ifs.GetMountReader(ctx, fileName)
require.NoError(t, err)
fmt.Println("file name", fileName, "took", time.Since(start))
}

start := time.Now()
list, err := ifs.ListResourceIds(ctx)
require.NoError(t, err)
require.Len(t, list, 180000, fmt.Sprintf("not match %d", len(list)))
fmt.Println("list took", time.Since(start))
}
Loading