diff --git a/db/bulkconnect.go b/db/bulkconnect.go index 7a32d720..2746f3b1 100644 --- a/db/bulkconnect.go +++ b/db/bulkconnect.go @@ -1,6 +1,7 @@ package db import ( + "sync/atomic" "time" "github.com/golang/glog" @@ -250,7 +251,8 @@ func (b *BulkConnect) connectBlockBitcoinType(block *bchain.Block, storeBlockTxs return err } if bac > b.bulkAddressesCount { - glog.Info("rocksdb: height ", b.height, ", stored ", bac, " addresses, done in ", time.Since(start)) + oversizeSkipped := atomic.SwapUint64(&b.d.addrContractsCacheState.oversizeSkipped, 0) + glog.Info("rocksdb: height ", b.height, ", stored ", bac, " addresses, oversize_skipped=", oversizeSkipped, ", done in ", time.Since(start)) } } if storeAddressesChan != nil { @@ -358,7 +360,8 @@ func (b *BulkConnect) connectBlockEthereumType(block *bchain.Block, storeBlockTx return err } if bac > b.bulkAddressesCount { - glog.Info("rocksdb: height ", b.height, ", stored ", bac, " addresses, done in ", time.Since(start)) + oversizeSkipped := atomic.SwapUint64(&b.d.addrContractsCacheState.oversizeSkipped, 0) + glog.Info("rocksdb: height ", b.height, ", stored ", bac, " addresses, oversize_skipped=", oversizeSkipped, ", done in ", time.Since(start)) } } else { // if there are blockSpecificData, store them @@ -425,7 +428,8 @@ func (b *BulkConnect) Close() error { if err := b.d.WriteBatch(wb); err != nil { return err } - glog.Info("rocksdb: height ", b.height, ", stored ", bac, " addresses, done in ", time.Since(start)) + oversizeSkipped := atomic.SwapUint64(&b.d.addrContractsCacheState.oversizeSkipped, 0) + glog.Info("rocksdb: height ", b.height, ", stored ", bac, " addresses, oversize_skipped=", oversizeSkipped, ", done in ", time.Since(start)) if storeTxAddressesChan != nil { if err := <-storeTxAddressesChan; err != nil { return err diff --git a/db/rocksdb.go b/db/rocksdb.go index 525ded75..523ace7d 100644 --- a/db/rocksdb.go +++ b/db/rocksdb.go @@ -57,8 +57,8 @@ const ( addressBalanceDetailUTXOIndexed = 2 ) -const addrContractsCacheMinSize = 300_000 // limit for caching address contracts in memory to speed up indexing -const addrContractsCacheAlwaysSize = 300_000 +const addrContractsCacheMinSize = 100_000 // limit for caching address contracts in memory to speed up indexing +const addrContractsSkipSize = 100_000 const addrContractsCacheHotMinScore = 2.0 const addrContractsHotHalfLife = 45 * time.Minute const addrContractsHotEvictAfter = 8 * time.Hour @@ -179,7 +179,7 @@ func NewRocksDB(path string, cacheSize, maxOpenFiles int, parser bchain.BlockCha hot: make(map[string]*addrContractsHotEntry), hotSeen: make(map[string]struct{}), minSizeBytes: addrContractsCacheMinSize, - alwaysSizeBytes: addrContractsCacheAlwaysSize, + alwaysSizeBytes: addrContractsSkipSize, hotMinScore: addrContractsCacheHotMinScore, hotHalfLife: addrContractsHotHalfLife, hotEvictAfter: addrContractsHotEvictAfter, diff --git a/docs/env.md b/docs/env.md index 6908530c..139b1dde 100644 --- a/docs/env.md +++ b/docs/env.md @@ -11,10 +11,10 @@ Some behavior of Blockbook can be modified by environment variables. The variabl - `_ALLOWED_RPC_CALL_TO` - Addresses to which `rpcCall` websocket requests can be made, as a comma-separated list. If omitted, `rpcCall` is enabled for all addresses. - `_ADDR_CONTRACTS_CACHE_MIN_SIZE` - Default: `300000` + Default: `100000` Description: Minimum packed size (bytes) to consider addressContracts hotness/caching. Accepts bytes or `K/M/G/T` suffixes (e.g. `300000`, `300K`, `1MiB`). - `_ADDR_CONTRACTS_CACHE_ALWAYS_SIZE` - Default: `300000` + Default: `100000` Description: Always cache addressContracts above this packed size (bytes). Accepts bytes or `K/M/G/T` suffixes. - `_ADDR_CONTRACTS_CACHE_HOT_MIN_SCORE` Default: `2`