From d884f96553701b6576430d5dadd012c2de3d7d0d Mon Sep 17 00:00:00 2001 From: Brannon King Date: Fri, 24 Sep 2021 13:25:27 -0400 Subject: [PATCH] set all pebble DB's to 2k handles, set process RLimit --- claimtrie/block/blockrepo/pebble.go | 2 +- claimtrie/chain/chainrepo/pebble.go | 2 +- claimtrie/config/config.go | 22 +++++++++++++++++++ claimtrie/merkletrie/merkletrierepo/pebble.go | 2 +- claimtrie/node/noderepo/pebble.go | 2 +- claimtrie/temporal/temporalrepo/pebble.go | 2 +- database/ffldb/blockio.go | 2 +- database/ffldb/db.go | 9 ++++---- 8 files changed, 33 insertions(+), 10 deletions(-) diff --git a/claimtrie/block/blockrepo/pebble.go b/claimtrie/block/blockrepo/pebble.go index 6b57d767..8bf0b1d2 100644 --- a/claimtrie/block/blockrepo/pebble.go +++ b/claimtrie/block/blockrepo/pebble.go @@ -16,7 +16,7 @@ type Pebble struct { func NewPebble(path string) (*Pebble, error) { - db, err := pebble.Open(path, nil) + db, err := pebble.Open(path, &pebble.Options{MaxOpenFiles: 2000}) repo := &Pebble{db: db} return repo, errors.Wrapf(err, "unable to open %s", path) diff --git a/claimtrie/chain/chainrepo/pebble.go b/claimtrie/chain/chainrepo/pebble.go index 51c89272..4100d6ac 100644 --- a/claimtrie/chain/chainrepo/pebble.go +++ b/claimtrie/chain/chainrepo/pebble.go @@ -17,7 +17,7 @@ type Pebble struct { func NewPebble(path string) (*Pebble, error) { - db, err := pebble.Open(path, &pebble.Options{BytesPerSync: 64 << 20}) + db, err := pebble.Open(path, &pebble.Options{BytesPerSync: 64 << 20, MaxOpenFiles: 2000}) repo := &Pebble{db: db} return repo, errors.Wrapf(err, "open %s", path) diff --git a/claimtrie/config/config.go b/claimtrie/config/config.go index 73e2fb33..3e223ca0 100644 --- a/claimtrie/config/config.go +++ b/claimtrie/config/config.go @@ -2,11 +2,33 @@ package config import ( "path/filepath" + "syscall" "github.com/lbryio/lbcd/claimtrie/param" btcutil "github.com/lbryio/lbcutil" ) +func init() { + // ensure that we have enough file handles + var rLimit syscall.Rlimit + err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit) + if err != nil { + panic("Error getting File Handle RLimit: " + err.Error()) + } + minRequiredFileHandles := uint64(24000) // seven databases and they each require ~2000, plus a few more to be safe + if rLimit.Max < minRequiredFileHandles { + panic("Error increasing File Handle RLimit: increasing file handle limit requires " + + "unavailable privileges. Allow at least 24000 handles.") + } + if rLimit.Cur < minRequiredFileHandles { + rLimit.Cur = minRequiredFileHandles + err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit) + if err != nil { + panic("Error setting File Handle RLimit to 24000: " + err.Error()) + } + } +} + var DefaultConfig = Config{ Params: param.MainNet, diff --git a/claimtrie/merkletrie/merkletrierepo/pebble.go b/claimtrie/merkletrie/merkletrierepo/pebble.go index 1c1d6f4f..c903794e 100644 --- a/claimtrie/merkletrie/merkletrierepo/pebble.go +++ b/claimtrie/merkletrie/merkletrierepo/pebble.go @@ -31,7 +31,7 @@ func NewPebble(path string) (*Pebble, error) { // } //}() - db, err := pebble.Open(path, &pebble.Options{Cache: cache, BytesPerSync: 32 << 20}) + db, err := pebble.Open(path, &pebble.Options{Cache: cache, BytesPerSync: 32 << 20, MaxOpenFiles: 2000}) repo := &Pebble{db: db} return repo, errors.Wrapf(err, "unable to open %s", path) diff --git a/claimtrie/node/noderepo/pebble.go b/claimtrie/node/noderepo/pebble.go index 3fed905b..a13dda82 100644 --- a/claimtrie/node/noderepo/pebble.go +++ b/claimtrie/node/noderepo/pebble.go @@ -15,7 +15,7 @@ type Pebble struct { func NewPebble(path string) (*Pebble, error) { - db, err := pebble.Open(path, &pebble.Options{Cache: pebble.NewCache(64 << 20), BytesPerSync: 4 << 20}) + db, err := pebble.Open(path, &pebble.Options{Cache: pebble.NewCache(64 << 20), BytesPerSync: 8 << 20, MaxOpenFiles: 2000}) repo := &Pebble{db: db} return repo, errors.Wrapf(err, "unable to open %s", path) diff --git a/claimtrie/temporal/temporalrepo/pebble.go b/claimtrie/temporal/temporalrepo/pebble.go index 9882a83c..f7b083dc 100644 --- a/claimtrie/temporal/temporalrepo/pebble.go +++ b/claimtrie/temporal/temporalrepo/pebble.go @@ -15,7 +15,7 @@ type Pebble struct { func NewPebble(path string) (*Pebble, error) { - db, err := pebble.Open(path, &pebble.Options{Cache: pebble.NewCache(16 << 20)}) + db, err := pebble.Open(path, &pebble.Options{Cache: pebble.NewCache(16 << 20), MaxOpenFiles: 2000}) repo := &Pebble{db: db} return repo, errors.Wrapf(err, "unable to open %s", path) diff --git a/database/ffldb/blockio.go b/database/ffldb/blockio.go index ae71a891..2ed4eccf 100644 --- a/database/ffldb/blockio.go +++ b/database/ffldb/blockio.go @@ -37,7 +37,7 @@ const ( // maxOpenFiles is the max number of open files to maintain in the // open blocks cache. Note that this does not include the current // write file, so there will typically be one more than this value open. - maxOpenFiles = 25 + maxOpenFiles = 40 // maxBlockFileSize is the maximum size for each file used to store // blocks. diff --git a/database/ffldb/db.go b/database/ffldb/db.go index 31dda789..181a6a4c 100644 --- a/database/ffldb/db.go +++ b/database/ffldb/db.go @@ -2001,10 +2001,11 @@ func openDB(dbPath string, network wire.BitcoinNet, create bool) (database.DB, e // Open the metadata database (will create it if needed). opts := opt.Options{ - ErrorIfExist: create, - Strict: opt.DefaultStrict, - Compression: opt.NoCompression, - Filter: filter.NewBloomFilter(10), + ErrorIfExist: create, + Strict: opt.DefaultStrict, + Compression: opt.NoCompression, + Filter: filter.NewBloomFilter(10), + OpenFilesCacheCapacity: 2000, } ldb, err := leveldb.OpenFile(metadataDbPath, &opts) if err != nil {