Skip to content

Commit

Permalink
Use default MaxDownloadParallelism based on number of CPU cores (#2047)
Browse files Browse the repository at this point in the history
* Use default value based on number of CPU cores

* renames
  • Loading branch information
sethiay authored Jun 27, 2024
1 parent dd1542d commit ef2179c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions internal/config/config_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package config
import (
"fmt"
"math"
"runtime"
"time"
)

Expand Down Expand Up @@ -112,3 +113,7 @@ func ListCacheTtlSecsToDuration(secs int64) time.Duration {

return time.Duration(secs * int64(time.Second))
}

func DefaultMaxParallelDownloads() int {
return max(16, 2*runtime.NumCPU())
}
4 changes: 4 additions & 0 deletions internal/config/config_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,7 @@ func Test_ListCacheTtlSecsToDuration_InvalidCall(t *testing.T) {
// Calling with invalid argument to trigger panic.
ListCacheTtlSecsToDuration(-3)
}

func Test_DefaultMaxParallelDownloads(t *testing.T) {
assert.GreaterOrEqual(t, DefaultMaxParallelDownloads(), 16)
}
3 changes: 1 addition & 2 deletions internal/config/mount_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ const (
DefaultEnableParallelDownloads = false
DefaultDownloadChunkSizeMB = 25
DefaultParallelDownloadsPerFile = 10
DefaultMaxParallelDownloads = -1
)

type WriteConfig struct {
Expand Down Expand Up @@ -188,7 +187,7 @@ func NewMountConfig() *MountConfig {
MaxSizeMB: DefaultFileCacheMaxSizeMB,
EnableParallelDownloads: DefaultEnableParallelDownloads,
ParallelDownloadsPerFile: DefaultParallelDownloadsPerFile,
MaxParallelDownloads: DefaultMaxParallelDownloads,
MaxParallelDownloads: DefaultMaxParallelDownloads(),
DownloadChunkSizeMB: DefaultDownloadChunkSizeMB,
EnableCRC: DefaultEnableCRC,
}
Expand Down
2 changes: 1 addition & 1 deletion internal/config/yaml_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func validateDefaultConfig(t *testing.T, mountConfig *MountConfig) {
assert.False(t, mountConfig.FileCacheConfig.CacheFileForRangeRead)
assert.False(t, mountConfig.FileCacheConfig.EnableParallelDownloads)
assert.Equal(t, 10, mountConfig.FileCacheConfig.ParallelDownloadsPerFile)
assert.Equal(t, -1, mountConfig.FileCacheConfig.MaxParallelDownloads)
assert.GreaterOrEqual(t, mountConfig.FileCacheConfig.MaxParallelDownloads, 16)
assert.Equal(t, 25, mountConfig.FileCacheConfig.DownloadChunkSizeMB)
assert.True(t, mountConfig.FileCacheConfig.EnableCRC)
assert.Equal(t, 1, mountConfig.GCSConnection.GRPCConnPoolSize)
Expand Down

0 comments on commit ef2179c

Please sign in to comment.