Created
June 9, 2017 14:30
-
-
Save irfansharif/70d138e638600693935c924be5df8178 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func BenchmarkBatchCommitInterleaved(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-")...) | |
b.SetBytes(int64(valueSize)) | |
engA := setupMVCCRocksDB(b, fmt.Sprintf("batch_commit_interleaved_%d_a", valueSize)) | |
defer func() { | |
if err := os.RemoveAll(fmt.Sprintf("batch_commit_interleaved_%d_a", valueSize)); err != nil { | |
b.Fatal(err) | |
} | |
}() | |
defer engA.Close() | |
engB := setupMVCCRocksDB(b, fmt.Sprintf("batch_commit_interleaved_%d_b", valueSize)) | |
defer func() { | |
if err := os.RemoveAll(fmt.Sprintf("batch_commit_interleaved_%d_b", valueSize)); err != nil { | |
b.Fatal(err) | |
} | |
}() | |
defer engB.Close() | |
b.ResetTimer() | |
for i := 0; i < b.N; i++ { | |
batchA := engA.NewWriteOnlyBatch() | |
key := roachpb.Key(encoding.EncodeUvarintAscending(keyBuf[:4], uint64(i))) | |
ts := hlc.Timestamp{WallTime: timeutil.Now().UnixNano()} | |
if err := MVCCBlindPut(context.Background(), batchA, nil, key, ts, value, nil); err != nil { | |
b.Fatalf("failed put: %s", err) | |
} | |
if err := batchA.Commit(true); err != nil { | |
b.Fatal(err) | |
} | |
batchA.Close() | |
batchB := engB.NewWriteOnlyBatch() | |
key = roachpb.Key(encoding.EncodeUvarintAscending(keyBuf[:4], uint64(i))) | |
ts = hlc.Timestamp{WallTime: timeutil.Now().UnixNano()} | |
if err := MVCCBlindPut(context.Background(), batchB, nil, key, ts, value, nil); err != nil { | |
b.Fatalf("failed put: %s", err) | |
} | |
if err := batchB.Commit(false); err != nil { | |
b.Fatal(err) | |
} | |
batchB.Close() | |
} | |
b.StopTimer() | |
}) | |
} | |
} | |
func BenchmarkBatchCommitSequential(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-")...) | |
b.SetBytes(int64(valueSize)) | |
engA := setupMVCCRocksDB(b, fmt.Sprintf("batch_commit_sequential_%d_a", valueSize)) | |
defer func() { | |
if err := os.RemoveAll(fmt.Sprintf("batch_commit_sequential_%d_a", valueSize)); err != nil { | |
b.Fatal(err) | |
} | |
}() | |
defer engA.Close() | |
engB := setupMVCCRocksDB(b, fmt.Sprintf("batch_commit_sequential_%d_b", valueSize)) | |
defer func() { | |
if err := os.RemoveAll(fmt.Sprintf("batch_commit_sequential_%d_b", valueSize)); err != nil { | |
b.Fatal(err) | |
} | |
}() | |
defer engB.Close() | |
b.ResetTimer() | |
for i := 0; i < b.N; i++ { | |
batchA := engA.NewWriteOnlyBatch() | |
key := roachpb.Key(encoding.EncodeUvarintAscending(keyBuf[:4], uint64(i))) | |
ts := hlc.Timestamp{WallTime: timeutil.Now().UnixNano()} | |
if err := MVCCBlindPut(context.Background(), batchA, nil, key, ts, value, nil); err != nil { | |
b.Fatalf("failed put: %s", err) | |
} | |
if err := batchA.Commit(true); err != nil { | |
b.Fatal(err) | |
} | |
batchA.Close() | |
} | |
for i := 0; i < b.N; i++ { | |
batchB := engB.NewWriteOnlyBatch() | |
key := roachpb.Key(encoding.EncodeUvarintAscending(keyBuf[:4], uint64(i))) | |
ts := hlc.Timestamp{WallTime: timeutil.Now().UnixNano()} | |
if err := MVCCBlindPut(context.Background(), batchB, nil, key, ts, value, nil); err != nil { | |
b.Fatalf("failed put: %s", err) | |
} | |
if err := batchB.Commit(false); err != nil { | |
b.Fatal(err) | |
} | |
batchB.Close() | |
} | |
b.StopTimer() | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment