Skip to content

Commit

Permalink
rocksdb: use ptcmalloc in dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrus committed Nov 10, 2023
1 parent 9475fa4 commit a4c796f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
22 changes: 17 additions & 5 deletions docker/oasis-core-dev/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ RUN apt-get update -qq && apt-get upgrade -qq && apt-get install -qq \
libseccomp-dev \
bubblewrap \
# Compression libs for RocksDB.
libsnappy-dev libbz2-dev liblz4-dev libzstd-dev && \
libsnappy-dev libbz2-dev liblz4-dev libzstd-dev \
# tcmalloc for RocksDB.
libgoogle-perftools-dev && \
apt-get autoclean && apt-get autoremove && rm -rf /var/cache/apt/archives/* && \
# for linting Git commits
pip install gitlint
Expand Down Expand Up @@ -85,7 +87,7 @@ RUN wget https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz && \
go install mvdan.cc/gofumpt@${GOFUMPT_VERSION} && \
go install golang.org/x/tools/cmd/goimports@${GOIMPORTS_VERSION}

# Install jemalloc (used by BadgerDB).
# Install jemalloc for BadgerDB ('je_' API prefix).
RUN wget -O jemalloc.tar.bz2 \
https://github.com/jemalloc/jemalloc/releases/download/${JEMALLOC_VERSION}/jemalloc-${JEMALLOC_VERSION}.tar.bz2 && \
# Ensure checksum matches.
Expand All @@ -101,15 +103,25 @@ RUN wget -O jemalloc.tar.bz2 \
cd .. && rm jemalloc.tar.bz2 && rm -rf jemalloc-${JEMALLOC_VERSION}

# Install RocksDB.
# https://github.com/facebook/rocksdb/blob/main/INSTALL.md
RUN wget -q https://github.com/facebook/rocksdb/archive/v${ROCKSDB_VERSION}.tar.gz && \
# Ensure checksum matches.
echo "${ROCKSDB_CHECKSUM} v${ROCKSDB_VERSION}.tar.gz" | sha256sum -c && \
tar -zxf v${ROCKSDB_VERSION}.tar.gz && \
cd rocksdb-${ROCKSDB_VERSION} && \
# TODO: clashes with jemalloc used by BadgerDB.
# In production it's recomended to use either tcmalloc or jemalloc instead of ptmalloc:
# https://blog.cloudflare.com/the-effect-of-switching-to-tcmalloc-on-rocksdb-memory-use/
# However RocksDB jemalloc requirement clashes with BadgerDB (RocksDB requires it without 'je_' prefix).
# Using tcmalloc next to badgerdb's jemalloc also causes problems. Therefore we default to ptmalloc for
# the docker container. If/when RocksDB becomes the prefered database, we should default to building
# BadgerDB without jemalloc and use tcmalloc/jemalloc here.
#
# Disable jemalloc as it is used by default if found on the system.
ROCKSDB_DISABLE_JEMALLOC=1 \
# For 64-bit x86 the `PORTABLE=haswell` is a reasonable compromise, which supports many or most
# of the available optimizations while still being compatible with most processors made since
# roughly 2013. https://github.com/facebook/rocksdb/blob/main/INSTALL.md
DEBUG_LEVEL=0 ROCKSDB_DISABLE_JEMALLOC=1 PORTABLE=haswell make -j4 shared_lib && \
# roughly 2013.
PORTABLE=haswell \
DEBUG_LEVEL=0 make -j4 shared_lib && \
make install-shared && ldconfig && \
cd .. && rm -rf v${ROCKSDB_VERSION}.tar.gz rocksdb-${ROCKSDB_VERSION}
7 changes: 4 additions & 3 deletions go/storage/mkvs/db/rocksdb/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,17 @@ func (ba *rocksdbBatch) Commit(root node.Root) error {
if err != nil {
return err
}
// Check if oldRootsMeta was updated in this batch.
// TODO: could this be avoided?

// Check if oldRootsMeta was updated in this batch. Since we don't see the
// batch updates, until the batch is applied.
wbIter := ba.bat.NewIterator()
for {
if !wbIter.Next() {
break
}
rec := wbIter.Record()
if bytes.Equal(rec.Key, rootsMetadataKeyFmt.Encode(ba.oldRoot.Version)) {
if rec.Type == grocksdb.WriteBatchValueRecord {
if rec.Type == grocksdb.WriteBatchCFValueRecord {
if err = cbor.Unmarshal(rec.Value, &oldRootsMeta); err != nil {
panic(err)
}
Expand Down
2 changes: 2 additions & 0 deletions go/storage/mkvs/db/rocksdb/rocksdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func createCheckpoint(ctx context.Context, require *require.Assertions, dir stri
nodeKeys[string(it.Key())] = struct{}{}
}
}
return nil
})
}
loadNodes(rocksdb.cfIOTree)
Expand Down Expand Up @@ -148,6 +149,7 @@ func verifyNodes(require *require.Assertions, rocksdb *rocksdbNodeDB, version ui
require.Equal(true, ok, "unexpected node in db")
delete(notVisited, string(key))
}
return nil
})
}
checkNodes(rocksdb.cfIOTree)
Expand Down

0 comments on commit a4c796f

Please sign in to comment.