-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Draft] Parametrize 2 Js/Fs benchmarks #5490
Draft
mprimi
wants to merge
1
commit into
nats-io:main
Choose a base branch
from
mprimi:marco/parametrize_filestore_benchmarks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6949,59 +6949,108 @@ func TestFileStoreRecoverWithRemovesAndNoIndexDB(t *testing.T) { | |
/////////////////////////////////////////////////////////////////////////// | ||
|
||
func Benchmark_FileStoreSelectMsgBlock(b *testing.B) { | ||
// We use small block size to create lots of blocks for this test. | ||
fs, err := newFileStore( | ||
FileStoreConfig{StoreDir: b.TempDir(), BlockSize: 128}, | ||
StreamConfig{Name: "zzz", Subjects: []string{"*"}, Storage: FileStorage}) | ||
require_NoError(b, err) | ||
defer fs.Stop() | ||
const Seed = 123456 | ||
cases := []struct { | ||
blockSize uint64 | ||
msgSize int | ||
msgCount int | ||
}{ | ||
{128, 100, 1000}, | ||
{128, 1000, 1000}, // 10X msg size from base case | ||
{128, 100, 10000}, // 10X msg count from base case | ||
} | ||
|
||
for _, params := range cases { | ||
|
||
b.Run( | ||
fmt.Sprintf("blockSize:%d,msgSize:%d,msgCount:%d", params.blockSize, params.msgSize, params.msgCount), | ||
func(b *testing.B) { | ||
fs, err := newFileStore( | ||
FileStoreConfig{StoreDir: b.TempDir(), BlockSize: params.blockSize}, | ||
StreamConfig{Name: "zzz", Subjects: []string{"*"}, Storage: FileStorage}) | ||
require_NoError(b, err) | ||
defer fs.Stop() | ||
|
||
rng := rand.New(rand.NewSource(Seed)) | ||
|
||
// Add in a bunch of blocks. | ||
msg := make([]byte, params.msgSize) | ||
for i := 0; i < params.msgCount; i++ { | ||
rng.Read(msg) | ||
_, _, err := fs.StoreMsg("A", nil, msg) | ||
require_NoError(b, err) | ||
} | ||
if fs.numMsgBlocks() < params.msgCount { | ||
b.Fatalf("Expected at least 1000 blocks, got %d", fs.numMsgBlocks()) | ||
} | ||
|
||
subj, msg := "A", bytes.Repeat([]byte("ABC"), 33) // ~100bytes | ||
b.SetBytes(int64(params.msgSize)) | ||
|
||
// Add in a bunch of blocks. | ||
for i := 0; i < 1000; i++ { | ||
fs.StoreMsg(subj, nil, msg) | ||
} | ||
if fs.numMsgBlocks() < 1000 { | ||
b.Fatalf("Expected at least 1000 blocks, got %d", fs.numMsgBlocks()) | ||
} | ||
fs.mu.RLock() | ||
defer fs.mu.RUnlock() | ||
|
||
fs.mu.RLock() | ||
defer fs.mu.RUnlock() | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
_, mb := fs.selectMsgBlockWithIndex(1 + uint64(i%params.msgCount)) | ||
if mb == nil { | ||
b.Fatalf("Expected a non-nil mb") | ||
} | ||
} | ||
b.StopTimer() | ||
}, | ||
) | ||
|
||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
_, mb := fs.selectMsgBlockWithIndex(1) | ||
if mb == nil { | ||
b.Fatalf("Expected a non-nil mb") | ||
} | ||
} | ||
b.StopTimer() | ||
} | ||
|
||
func Benchmark_FileStoreLoadNextMsgSameFilterAsStream(b *testing.B) { | ||
fs, err := newFileStore( | ||
FileStoreConfig{StoreDir: b.TempDir()}, | ||
StreamConfig{Name: "zzz", Subjects: []string{"foo.*"}, Storage: FileStorage}) | ||
require_NoError(b, err) | ||
defer fs.Stop() | ||
|
||
// Small om purpose. | ||
msg := []byte("ok") | ||
const Seed = 123456 | ||
cases := []struct { | ||
msgSize int | ||
msgCount int | ||
distinctSubjects int | ||
}{ | ||
{10, 100_000, 1024}, | ||
{100, 1000, 1024}, // 10X msg size from base case | ||
{10, 1_000_000, 10240}, // 10X number of distinct subjects | ||
} | ||
|
||
for _, params := range cases { | ||
|
||
b.Run( | ||
fmt.Sprintf("msgSize:%d,msgCount:%d,subjects:%d", params.msgSize, params.msgCount, params.distinctSubjects), | ||
func(b *testing.B) { | ||
|
||
fs, err := newFileStore( | ||
FileStoreConfig{StoreDir: b.TempDir()}, | ||
StreamConfig{Name: "zzz", Subjects: []string{"foo.*"}, Storage: FileStorage}) | ||
require_NoError(b, err) | ||
defer fs.Stop() | ||
|
||
rng := rand.New(rand.NewSource(Seed)) | ||
|
||
// Add in a bunch of msgs | ||
msg := make([]byte, params.msgSize) | ||
for i := 0; i < 100_000; i++ { | ||
rng.Read(msg) | ||
subj := fmt.Sprintf("foo.%d", rng.Intn(params.distinctSubjects)) | ||
_, _, err := fs.StoreMsg(subj, nil, msg) | ||
require_NoError(b, err) | ||
} | ||
|
||
// Add in a bunch of msgs | ||
for i := 0; i < 100_000; i++ { | ||
subj := fmt.Sprintf("foo.%d", rand.Intn(1024)) | ||
fs.StoreMsg(subj, nil, msg) | ||
} | ||
b.SetBytes(int64(params.msgSize)) | ||
|
||
b.ResetTimer() | ||
b.ResetTimer() | ||
|
||
var smv StoreMsg | ||
for i := 0; i < b.N; i++ { | ||
// Needs to start at ~1 to show slowdown. | ||
_, _, err := fs.LoadNextMsg("foo.*", true, 10, &smv) | ||
require_NoError(b, err) | ||
var smv StoreMsg | ||
for i := 0; i < b.N; i++ { | ||
// Needs to start at ~1 to show slowdown. | ||
_, _, err := fs.LoadNextMsg("foo.*", true, 10, &smv) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the hardcoded There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not for this one. |
||
require_NoError(b, err) | ||
} | ||
}, | ||
) | ||
} | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
n.b. this was always set to 1 in the original benchmark, now it rolls around, could also be random
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the value has meaning for the test or benchmark I try to call it out.