diff --git a/swarm/storage/dpa.go b/swarm/storage/dpa.go index 3f66a73c9e..7f5a821f9f 100644 --- a/swarm/storage/dpa.go +++ b/swarm/storage/dpa.go @@ -35,8 +35,9 @@ implementation for storage or retrieval. */ const ( - singletonSwarmDbCapacity = 50000 - singletonSwarmCacheCapacity = 500 + defaultLDBCapacity = 50000 // capacity for LevelDB + defaultCacheCapacity = 500 // capacity for in-memory chunks' cache + defaultChunkRequestsCacheCapacity = 50000 // capacity for container holding outgoing requests for chunks. should be set to LevelDB capacity ) var ( @@ -66,13 +67,13 @@ func NewLocalDPA(datadir string, basekey []byte) (*DPA, error) { hash := MakeHashFunc("SHA3") - dbStore, err := NewLDBStore(datadir, hash, singletonSwarmDbCapacity, func(k Key) (ret uint8) { return uint8(Proximity(basekey[:], k[:])) }) + dbStore, err := NewLDBStore(datadir, hash, defaultLDBCapacity, func(k Key) (ret uint8) { return uint8(Proximity(basekey[:], k[:])) }) if err != nil { return nil, err } return NewDPA(&LocalStore{ - memStore: NewMemStore(dbStore, singletonSwarmCacheCapacity, singletonSwarmDbCapacity), + memStore: NewMemStore(dbStore, defaultCacheCapacity, defaultChunkRequestsCacheCapacity), DbStore: dbStore, }, NewDPAParams()), nil } diff --git a/swarm/storage/dpa_test.go b/swarm/storage/dpa_test.go index c1601807a3..e5eebfe37d 100644 --- a/swarm/storage/dpa_test.go +++ b/swarm/storage/dpa_test.go @@ -39,7 +39,7 @@ func testDpaRandom(toEncrypt bool, t *testing.T) { defer tdb.close() db := tdb.LDBStore db.setCapacity(50000) - memStore := NewMemStore(db, defaultCacheCapacity, defaultCacheCapacity) + memStore := NewMemStore(db, defaultCacheCapacity, defaultChunkRequestsCacheCapacity) localStore := &LocalStore{ memStore: memStore, DbStore: db, @@ -68,7 +68,7 @@ func testDpaRandom(toEncrypt bool, t *testing.T) { } ioutil.WriteFile("/tmp/slice.bzz.16M", slice, 0666) ioutil.WriteFile("/tmp/result.bzz.16M", resultSlice, 0666) - localStore.memStore = NewMemStore(db, defaultCacheCapacity, defaultCacheCapacity) + localStore.memStore = NewMemStore(db, defaultCacheCapacity, defaultChunkRequestsCacheCapacity) resultReader = dpa.Retrieve(key) for i := range resultSlice { resultSlice[i] = 0 diff --git a/swarm/storage/localstore.go b/swarm/storage/localstore.go index 908a10c704..b2d4ef7616 100644 --- a/swarm/storage/localstore.go +++ b/swarm/storage/localstore.go @@ -60,19 +60,19 @@ func NewLocalStore(hash SwarmHasher, params *StoreParams, basekey []byte, mockSt return nil, err } return &LocalStore{ - memStore: NewMemStore(dbStore, params.CacheCapacity, singletonSwarmDbCapacity), + memStore: NewMemStore(dbStore, params.CacheCapacity, defaultChunkRequestsCacheCapacity), DbStore: dbStore, }, nil } func NewTestLocalStoreForAddr(path string, basekey []byte) (*LocalStore, error) { hasher := MakeHashFunc("SHA3") - dbStore, err := NewLDBStore(path, hasher, singletonSwarmDbCapacity, func(k Key) (ret uint8) { return uint8(Proximity(basekey[:], k[:])) }) + dbStore, err := NewLDBStore(path, hasher, defaultLDBCapacity, func(k Key) (ret uint8) { return uint8(Proximity(basekey[:], k[:])) }) if err != nil { return nil, err } localStore := &LocalStore{ - memStore: NewMemStore(dbStore, singletonSwarmDbCapacity, singletonSwarmDbCapacity), + memStore: NewMemStore(dbStore, defaultCacheCapacity, defaultChunkRequestsCacheCapacity), DbStore: dbStore, } return localStore, nil diff --git a/swarm/storage/memstore_lrucache.go b/swarm/storage/memstore_lrucache.go index cf560886e0..0c851c0fe8 100644 --- a/swarm/storage/memstore_lrucache.go +++ b/swarm/storage/memstore_lrucache.go @@ -26,10 +26,6 @@ import ( lru "github.com/hashicorp/golang-lru" ) -const ( - defaultCacheCapacity = 5000 -) - type MemStore struct { cache *lru.Cache requests *lru.Cache @@ -124,7 +120,7 @@ func (m *MemStore) setCapacity(n int) { if n <= 0 { m.disabled = true } else { - m = NewMemStore(nil, uint(n), singletonSwarmDbCapacity) + m = NewMemStore(nil, uint(n), defaultChunkRequestsCacheCapacity) } } diff --git a/swarm/storage/memstore_test.go b/swarm/storage/memstore_test.go index 74ce657c73..9146b298c3 100644 --- a/swarm/storage/memstore_test.go +++ b/swarm/storage/memstore_test.go @@ -19,7 +19,7 @@ package storage import "testing" func newTestMemStore() *MemStore { - return NewMemStore(nil, defaultCacheCapacity, singletonSwarmDbCapacity) + return NewMemStore(nil, defaultCacheCapacity, defaultChunkRequestsCacheCapacity) } func testMemStoreRandom(n int, processors int, chunksize int, t *testing.T) { diff --git a/swarm/storage/resource.go b/swarm/storage/resource.go index 304232142f..1b06fba39e 100644 --- a/swarm/storage/resource.go +++ b/swarm/storage/resource.go @@ -897,13 +897,13 @@ func NewTestResourceHandler(datadir string, ethClient headerGetter, validator Re path := filepath.Join(datadir, DbDirName) basekey := make([]byte, 32) hasher := MakeHashFunc(SHA3Hash) - dbStore, err := NewLDBStore(path, hasher, singletonSwarmDbCapacity, func(k Key) (ret uint8) { return uint8(Proximity(basekey[:], k[:])) }) + dbStore, err := NewLDBStore(path, hasher, defaultLDBCapacity, func(k Key) (ret uint8) { return uint8(Proximity(basekey[:], k[:])) }) dbStore.SetTrusted() if err != nil { return nil, err } localStore := &LocalStore{ - memStore: NewMemStore(dbStore, singletonSwarmCacheCapacity, singletonSwarmDbCapacity), + memStore: NewMemStore(dbStore, defaultCacheCapacity, defaultChunkRequestsCacheCapacity), DbStore: dbStore, } resourceChunkStore := NewResourceChunkStore(localStore, nil)