Skip to content

Instantly share code, notes, and snippets.

@irfansharif
Created June 8, 2017 22:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save irfansharif/3d710beea17655c41f95741d51367cf0 to your computer and use it in GitHub Desktop.
Save irfansharif/3d710beea17655c41f95741d51367cf0 to your computer and use it in GitHub Desktop.
func BenchmarkBatchCommitSameEng(b *testing.B) {
for _, valueSize := range []int{1 << 10, 1 << 12, 1 << 14, 1 << 16, 1 << 18, 1 << 20} {
b.Run(fmt.Sprintf("vs=%d", valueSize), func(b *testing.B) {
rng, _ := randutil.NewPseudoRand()
value := roachpb.MakeValueFromBytes(randutil.RandBytes(rng, valueSize))
keyBuf := append(make([]byte, 0, 64), []byte("key-")...)
eng := setupMVCCRocksDB(b, fmt.Sprintf("batch_commit_same_%d", valueSize))
defer func() {
if err := os.RemoveAll(fmt.Sprintf("batch_commit_same_%d", valueSize)); err != nil {
b.Fatal(err)
}
}()
defer eng.Close()
b.SetBytes(int64(valueSize))
b.ResetTimer()
for i := 0; i < b.N; i++ {
{
batch := eng.NewWriteOnlyBatch()
key := roachpb.Key(encoding.EncodeUvarintAscending(keyBuf[:4], uint64(i)))
ts := hlc.Timestamp{WallTime: timeutil.Now().UnixNano()}
if err := MVCCBlindPut(context.Background(), batch, nil, key, ts, value, nil); err != nil {
b.Fatalf("failed put: %s", err)
}
if err := batch.Commit(true); err != nil {
b.Fatal(err)
}
batch.Close()
}
{
batch := eng.NewWriteOnlyBatch()
key := roachpb.Key(encoding.EncodeUvarintAscending(keyBuf[:4], uint64(i+b.N)))
ts := hlc.Timestamp{WallTime: timeutil.Now().UnixNano()}
if err := MVCCBlindPut(context.Background(), batch, nil, key, ts, value, nil); err != nil {
b.Fatalf("failed put: %s", err)
}
if err := batch.Commit(false); err != nil {
b.Fatal(err)
}
batch.Close()
}
}
b.StopTimer()
})
}
}
func BenchmarkBatchCommitDedicatedEng(b *testing.B) {
for _, valueSize := range []int{1 << 10, 1 << 12, 1 << 14, 1 << 16, 1 << 18, 1 << 20} {
b.Run(fmt.Sprintf("vs=%d", valueSize), func(b *testing.B) {
rng, _ := randutil.NewPseudoRand()
value := roachpb.MakeValueFromBytes(randutil.RandBytes(rng, valueSize))
keyBuf := append(make([]byte, 0, 64), []byte("key-")...)
engA := setupMVCCRocksDB(b, fmt.Sprintf("batch_commit_dedicated_%d_a", valueSize))
defer func() {
if err := os.RemoveAll(fmt.Sprintf("batch_commit_dedicated_%d_a", valueSize)); err != nil {
b.Fatal(err)
}
}()
defer engA.Close()
engB := setupMVCCRocksDB(b, fmt.Sprintf("batch_commit_dedicated_%d_b", valueSize))
defer func() {
if err := os.RemoveAll(fmt.Sprintf("batch_commit_dedicated_%d_b", valueSize)); err != nil {
b.Fatal(err)
}
}()
defer engB.Close()
b.SetBytes(int64(valueSize))
b.ResetTimer()
for i := 0; i < b.N; i++ {
{
batch := engA.NewWriteOnlyBatch()
key := roachpb.Key(encoding.EncodeUvarintAscending(keyBuf[:4], uint64(i)))
ts := hlc.Timestamp{WallTime: timeutil.Now().UnixNano()}
if err := MVCCBlindPut(context.Background(), batch, nil, key, ts, value, nil); err != nil {
b.Fatalf("failed put: %s", err)
}
if err := batch.Commit(true); err != nil {
b.Fatal(err)
}
batch.Close()
}
{
batch := engB.NewWriteOnlyBatch()
key := roachpb.Key(encoding.EncodeUvarintAscending(keyBuf[:4], uint64(i+b.N)))
ts := hlc.Timestamp{WallTime: timeutil.Now().UnixNano()}
if err := MVCCBlindPut(context.Background(), batch, nil, key, ts, value, nil); err != nil {
b.Fatalf("failed put: %s", err)
}
if err := batch.Commit(false); err != nil {
b.Fatal(err)
}
batch.Close()
}
}
b.StopTimer()
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment