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

Add a loop to read 5 times from kernel cache and take minimum listing time #2574

Merged
merged 2 commits into from
Oct 10, 2024
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package list_large_dir_test

import (
"math"
"os"
"path"
"strconv"
Expand Down Expand Up @@ -164,21 +165,31 @@ func TestListDirectoryWithTwelveThousandFiles(t *testing.T) {
endTime := time.Now()
validateDirectoryWithTwelveThousandFiles(objs, t)
firstListTime := endTime.Sub(startTime)

// Listing the directory a second time should retrieve the response from the kernel cache.
startTime = time.Now()
objs, err = os.ReadDir(dirPath)
if err != nil {
t.Errorf("Error in listing directory: %v", err)
minSecondListTime := time.Duration(math.MaxInt64)
for i := 0; i < 5; i++ {
startTime = time.Now()
objs, err = os.ReadDir(dirPath)
if err != nil {
t.Errorf("Error in listing directory: %v", err)
vipnydav marked this conversation as resolved.
Show resolved Hide resolved
}
endTime = time.Now()
validateDirectoryWithTwelveThousandFiles(objs, t)
secondListTime := endTime.Sub(startTime)

// Update the minimum listing time for the second listing
if secondListTime < minSecondListTime {
minSecondListTime = secondListTime
}
}
endTime = time.Now()
validateDirectoryWithTwelveThousandFiles(objs, t)
secondListTime := endTime.Sub(startTime)

// Fetching data from the kernel for the second list will be faster.
assert.Less(t, secondListTime, firstListTime)
assert.Less(t, minSecondListTime, firstListTime)
// The second directory listing should be 2 times better performant since it
// will be retrieved from the kernel cache.
assert.Less(t, 2*secondListTime, firstListTime)
assert.Less(t, 2*minSecondListTime, firstListTime)

// Clear the data after testing.
setup.RunScriptForTestData("testdata/delete_objects.sh", testDirPathOnBucket)
}
Expand All @@ -189,6 +200,7 @@ func TestListDirectoryWithTwelveThousandFilesAndHundredExplicitDir(t *testing.T)
testDirPath := path.Join(setup.MntDir(), DirectoryForListLargeFileTests)
testDirPathOnBucket := path.Join(setup.TestBucket(), DirectoryForListLargeFileTests)
dirPath := path.Join(testDirPath, DirectoryWithTwelveThousandFiles)

// Create hundred explicit directories.
createHundredExplicitDir(dirPath, t)

Expand All @@ -201,21 +213,31 @@ func TestListDirectoryWithTwelveThousandFilesAndHundredExplicitDir(t *testing.T)
endTime := time.Now()
validateDirectoryWithTwelveThousandFilesAndHundredExplicitDirectory(objs, t)
firstListTime := endTime.Sub(startTime)

// Listing the directory a second time should retrieve the response from the kernel cache.
startTime = time.Now()
objs, err = os.ReadDir(dirPath)
if err != nil {
t.Errorf("Error in listing directory: %v", err)
minSecondListTime := time.Duration(math.MaxInt64)
for i := 0; i < 5; i++ {
startTime = time.Now()
vipnydav marked this conversation as resolved.
Show resolved Hide resolved
objs, err = os.ReadDir(dirPath)
if err != nil {
t.Errorf("Error in listing directory: %v", err)
}
endTime = time.Now()
validateDirectoryWithTwelveThousandFilesAndHundredExplicitDirectory(objs, t)
secondListTime := endTime.Sub(startTime)

// Update the minimum listing time for the second listing
if secondListTime < minSecondListTime {
minSecondListTime = secondListTime
}
}
endTime = time.Now()
validateDirectoryWithTwelveThousandFilesAndHundredExplicitDirectory(objs, t)
secondListTime := endTime.Sub(startTime)

// Fetching data from the kernel for the second list will be faster.
assert.Less(t, secondListTime, firstListTime)
assert.Less(t, minSecondListTime, firstListTime)
// The second directory listing should be 2 times better performant since it
// will be retrieved from the kernel cache.
assert.Less(t, 2*secondListTime, firstListTime)
assert.Less(t, 2*minSecondListTime, firstListTime)

// Clear the bucket after testing.
setup.RunScriptForTestData("testdata/delete_objects.sh", testDirPathOnBucket)
}
Expand All @@ -226,6 +248,7 @@ func TestListDirectoryWithTwelveThousandFilesAndHundredExplicitDirAndHundredImpl
testDirPath := path.Join(setup.MntDir(), DirectoryForListLargeFileTests)
testDirPathOnBucket := path.Join(setup.TestBucket(), DirectoryForListLargeFileTests)
dirPath := path.Join(testDirPath, DirectoryWithTwelveThousandFiles)

// Create hundred explicit directories.
createHundredExplicitDir(dirPath, t)
subDirPath := path.Join(testDirPathOnBucket, DirectoryWithTwelveThousandFiles)
Expand All @@ -240,21 +263,31 @@ func TestListDirectoryWithTwelveThousandFilesAndHundredExplicitDirAndHundredImpl
endTime := time.Now()
validateDirectoryWithTwelveThousandFilesHundredExplicitDirAndHundredImplicitDir(objs, t)
firstListTime := endTime.Sub(startTime)

// Listing the directory a second time should retrieve the response from the kernel cache.
startTime = time.Now()
objs, err = os.ReadDir(dirPath)
if err != nil {
t.Errorf("Error in listing directory: %v", err)
minSecondListTime := time.Duration(math.MaxInt64)
for i := 0; i < 5; i++ {
startTime = time.Now()
objs, err = os.ReadDir(dirPath)
if err != nil {
t.Errorf("Error in listing directory: %v", err)
}
endTime = time.Now()
validateDirectoryWithTwelveThousandFilesHundredExplicitDirAndHundredImplicitDir(objs, t)
secondListTime := endTime.Sub(startTime)

// Update the minimum listing time for the second listing
if secondListTime < minSecondListTime {
minSecondListTime = secondListTime
}
}
endTime = time.Now()
validateDirectoryWithTwelveThousandFilesHundredExplicitDirAndHundredImplicitDir(objs, t)
secondListTime := endTime.Sub(startTime)

// Fetching data from the kernel for the second list will be faster.
assert.Less(t, secondListTime, firstListTime)
assert.Less(t, minSecondListTime, firstListTime)
// The second directory listing should be 2 times better performant since it
// will be retrieved from the kernel cache.
assert.Less(t, 2*secondListTime, firstListTime)
assert.Less(t, 2*minSecondListTime, firstListTime)

// Clear the bucket after testing.
setup.RunScriptForTestData("testdata/delete_objects.sh", testDirPathOnBucket)
}
Loading