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 3f69784
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
18 changes: 14 additions & 4 deletions docker/oasis-core-dev/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,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 +101,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 warning on line 107 in go/storage/mkvs/db/rocksdb/batch.go

View check run for this annotation

Codecov / codecov/patch

go/storage/mkvs/db/rocksdb/batch.go#L107

Added line #L107 was not covered by tests
}
// 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)

Check warning on line 121 in go/storage/mkvs/db/rocksdb/batch.go

View check run for this annotation

Codecov / codecov/patch

go/storage/mkvs/db/rocksdb/batch.go#L121

Added line #L121 was not covered by tests
}
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 3f69784

Please sign in to comment.