-
Notifications
You must be signed in to change notification settings - Fork 32
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
feat(blockstore): benchmarks #275
Open
dadepo
wants to merge
22
commits into
main
Choose a base branch
from
dade/blockstore-benchmark
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.
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
2db1e1b
Added benchWriteSmall benchmark
dadepo b8ef631
updated test data
dadepo e9eb195
Added benchReadSequential
dadepo baa2fd8
Rename test file
dadepo 6f46e71
Added benchReadRandom
dadepo fd8952a
Set c allocator
dadepo a7e6bfb
typo
dadepo fe078fb
Check in test data
dadepo 439100b
Update test name
dadepo 7f3c380
Reuse ledger.insert_shred.insertShredsForTest
dadepo 4d55ccd
Add benchSerializeWriteBincode
dadepo 8c80082
Update title
dadepo 4528620
Add benchReadBincode
dadepo 5fa8282
Moved ledger benchmark to own file
dadepo ab2086b
Typo fix
dadepo 077cda2
Fmt
dadepo 692d561
import via the root source
dadepo 44fa660
camelCase for functions
dadepo cc8ac6c
Merge branch 'main' into dade/blockstore-benchmark
dadepo dbcd012
Pass std.heap.c_allocator to TestState in ledger benchmark
dadepo b84cc5c
Drop benchShreds in favour of re-using testShreds
dadepo dcccd63
Remove unused imports
dadepo 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
Binary file not shown.
Binary file not shown.
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
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 |
---|---|---|
@@ -0,0 +1,162 @@ | ||
const std = @import("std"); | ||
const sig = @import("../sig.zig"); | ||
const ledger_tests = @import("./tests.zig"); | ||
const ledger = @import("lib.zig"); | ||
|
||
const Reward = ledger.transaction_status.Reward; | ||
const Rewards = ledger.transaction_status.Rewards; | ||
const RewardType = ledger.transaction_status.RewardType; | ||
const Pubkey = sig.core.Pubkey; | ||
const TestState = ledger_tests.TestState; | ||
const TestDB = ledger_tests.TestDB; | ||
|
||
const schema = ledger.schema.schema; | ||
const deinitShreds = ledger_tests.deinitShreds; | ||
const testShreds = ledger_tests.testShreds; | ||
|
||
const test_shreds_dir = sig.TEST_DATA_DIR ++ "/shreds"; | ||
const State = TestState("global"); | ||
const DB = TestDB("global"); | ||
|
||
fn createRewards(allocator: std.mem.Allocator, count: usize) !Rewards { | ||
var rng = std.Random.DefaultPrng.init(100); | ||
const rand = rng.random(); | ||
var rewards: Rewards = Rewards.init(allocator); | ||
for (0..count) |i| { | ||
try rewards.append(Reward{ | ||
.pubkey = &Pubkey.random(rand).data, | ||
.lamports = @intCast(42 + i), | ||
.post_balance = std.math.maxInt(u64), | ||
.reward_type = RewardType.Fee, | ||
.commission = null, | ||
}); | ||
} | ||
return rewards; | ||
} | ||
|
||
pub const BenchmarLegder = struct { | ||
pub const min_iterations = 5; | ||
pub const max_iterations = 5; | ||
|
||
// Analogous to [bench_write_small](https://github.com/anza-xyz/agave/blob/cfd393654f84c36a3c49f15dbe25e16a0269008d/ledger/benches/blockstore.rs#L59) | ||
pub fn benchWriteSmall() !u64 { | ||
const allocator = std.heap.c_allocator; | ||
var state = try State.init(allocator, "bench write small"); | ||
defer state.deinit(); | ||
var inserter = try state.shredInserter(); | ||
|
||
const prefix = "agave.blockstore.bench_write_small."; | ||
const shreds = try testShreds(std.heap.c_allocator, prefix ++ "shreds.bin"); | ||
defer inline for (.{shreds}) |slice| { | ||
deinitShreds(allocator, slice); | ||
}; | ||
|
||
const is_repairs = try inserter.allocator.alloc(bool, shreds.len); | ||
defer inserter.allocator.free(is_repairs); | ||
for (0..shreds.len) |i| { | ||
is_repairs[i] = false; | ||
} | ||
|
||
var timer = try std.time.Timer.start(); | ||
_ = try inserter.insertShreds(shreds, is_repairs, null, false, null); | ||
return timer.read(); | ||
} | ||
|
||
// Analogous to [bench_read_sequential]https://github.com/anza-xyz/agave/blob/cfd393654f84c36a3c49f15dbe25e16a0269008d/ledger/benches/blockstore.rs#L78 | ||
pub fn benchReadSequential() !u64 { | ||
const allocator = std.heap.c_allocator; | ||
var state = try State.init(allocator, "bentch read sequential"); | ||
defer state.deinit(); | ||
var inserter = try state.shredInserter(); | ||
var reader = try state.reader(); | ||
|
||
const prefix = "agave.blockstore.bench_read."; | ||
const shreds = try testShreds(std.heap.c_allocator, prefix ++ "shreds.bin"); | ||
defer inline for (.{shreds}) |slice| { | ||
deinitShreds(allocator, slice); | ||
}; | ||
|
||
const total_shreds = shreds.len; | ||
|
||
_ = try ledger.insert_shred.insertShredsForTest(&inserter, shreds); | ||
|
||
const slot: u32 = 0; | ||
const num_reads = total_shreds / 15; | ||
|
||
var rng = std.Random.DefaultPrng.init(100); | ||
|
||
var timer = try std.time.Timer.start(); | ||
const start_index = rng.random().intRangeAtMost(u32, 0, @intCast(total_shreds)); | ||
for (start_index..start_index + num_reads) |i| { | ||
const shred_index = i % total_shreds; | ||
_ = try reader.getDataShred(slot, shred_index); | ||
} | ||
return timer.read(); | ||
} | ||
|
||
// Analogous to [bench_read_random]https://github.com/anza-xyz/agave/blob/92eca1192b055d896558a78759d4e79ab4721ff1/ledger/benches/blockstore.rs#L103 | ||
pub fn benchReadRandom() !u64 { | ||
const allocator = std.heap.c_allocator; | ||
var state = try State.init(allocator, "bench read randmom"); | ||
defer state.deinit(); | ||
var inserter = try state.shredInserter(); | ||
var reader = try state.reader(); | ||
|
||
const prefix = "agave.blockstore.bench_read."; | ||
const shreds = try testShreds(std.heap.c_allocator, prefix ++ "shreds.bin"); | ||
defer inline for (.{shreds}) |slice| { | ||
deinitShreds(allocator, slice); | ||
}; | ||
|
||
const total_shreds = shreds.len; | ||
_ = try ledger.insert_shred.insertShredsForTest(&inserter, shreds); | ||
|
||
const slot: u32 = 0; | ||
|
||
var rng = std.Random.DefaultPrng.init(100); | ||
|
||
var indices = try std.ArrayList(u32).initCapacity(inserter.allocator, total_shreds); | ||
defer indices.deinit(); | ||
for (total_shreds) |_| { | ||
indices.appendAssumeCapacity(rng.random().uintAtMost(u32, @intCast(total_shreds))); | ||
} | ||
|
||
var timer = try std.time.Timer.start(); | ||
for (indices.items) |shred_index| { | ||
_ = try reader.getDataShred(slot, shred_index); | ||
} | ||
return timer.read(); | ||
} | ||
|
||
// Analogous to [bench_serialize_write_bincode](https://github.com/anza-xyz/agave/blob/9c2098450ca7e5271e3690277992fbc910be27d0/ledger/benches/protobuf.rs#L88) | ||
pub fn benchSerializeWriteBincode() !u64 { | ||
const allocator = std.heap.c_allocator; | ||
var state = try State.init(allocator, "bench serialize write bincode"); | ||
defer state.deinit(); | ||
const slot: u32 = 0; | ||
|
||
var rewards: Rewards = try createRewards(allocator, 100); | ||
var timer = try std.time.Timer.start(); | ||
try state.db.put(schema.rewards, slot, .{ | ||
.rewards = try rewards.toOwnedSlice(), | ||
.num_partitions = null, | ||
}); | ||
return timer.read(); | ||
} | ||
|
||
pub fn benchReadBincode() !u64 { | ||
const allocator = std.heap.c_allocator; | ||
var state = try State.init(allocator, "bench read bincode"); | ||
defer state.deinit(); | ||
const slot: u32 = 1; | ||
|
||
var rewards: Rewards = try createRewards(allocator, 100); | ||
try state.db.put(schema.rewards, slot, .{ | ||
.rewards = try rewards.toOwnedSlice(), | ||
.num_partitions = null, | ||
}); | ||
var timer = try std.time.Timer.start(); | ||
_ = try state.db.getBytes(schema.rewards, slot); | ||
return timer.read(); | ||
} | ||
}; |
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
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
Oops, something went wrong.
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.
This can be used as
ledger.transaction_status
and does not require the file to be imported.Currently our convention is that you only import root source files from the current module. For example you can import
sig.zig
if you're in the sig project, and you can importlib.zig
from the current folder. But all other imports go through the decls defined by those imports.This is definitely up for discussion. If you'd like to adopt a different convention, I'm happy to discuss it. But if you have no preference, let's import this transaction_status the ledger decl.
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.
I think Importing via the root source file is indeed better. Updated in 692d561