Skip to content

Commit

Permalink
perf: Add low-level memory ops benchmark (#3551)
Browse files Browse the repository at this point in the history
```
$ bazel run //rs/memory_tracker:memory_ops_bench -- par_iter/threads:8
mmap/par_iter/threads:8/ops:100
                        time:   [1.2654 ms 1.2795 ms 1.2949 ms]
                        thrpt:  [77.227 Kelem/s 78.157 Kelem/s 79.028 Kelem/s]
mmap_mprotect/par_iter/threads:8/ops:100
                        time:   [1.8608 ms 1.8774 ms 1.8937 ms]
                        thrpt:  [52.808 Kelem/s 53.264 Kelem/s 53.740 Kelem/s]
mmap_mprotect_read/par_iter/threads:8/ops:100
                        time:   [4.9503 ms 4.9797 ms 5.0087 ms]
                        thrpt:  [19.965 Kelem/s 20.081 Kelem/s 20.201 Kelem/s]
mmap_mprotect_write/par_iter/threads:8/ops:100
                        time:   [9.0569 ms 9.1043 ms 9.1522 ms]
                        thrpt:  [10.926 Kelem/s 10.984 Kelem/s 11.041 Kelem/s]
mmap_mprotect_read_write/par_iter/threads:8/ops:100
                        time:   [19.574 ms 19.694 ms 19.815 ms]
                        thrpt:  [5.0466 Kelem/s 5.0778 Kelem/s 5.1087 Kelem/s]
mmap_read_write/par_iter/threads:8/ops:100
                        time:   [19.455 ms 19.597 ms 19.733 ms]
                        thrpt:  [5.0676 Kelem/s 5.1028 Kelem/s 5.1400 Kelem/s]
file_read_write/par_iter/threads:8/ops:100
                        time:   [315.32 µs 317.05 µs 318.70 µs]
                        thrpt:  [313.77 Kelem/s 315.41 Kelem/s 317.14 Kelem/s]
```
  • Loading branch information
berestovskyy authored Feb 5, 2025
1 parent a21f470 commit 7cd54f4
Show file tree
Hide file tree
Showing 11 changed files with 382 additions and 7 deletions.
57 changes: 56 additions & 1 deletion Cargo.Bazel.Fuzzing.json.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"checksum": "6bed8641f4af14470e0877f17b229644fb9c504d547b34b773230c601c91046b",
"checksum": "4ae7b3c97aa8a5afd939403aaa5919e419cc497d77a0fef55b643a99ef0c998b",
"crates": {
"abnf 0.12.0": {
"name": "abnf",
Expand Down Expand Up @@ -20147,6 +20147,10 @@
"id": "maxminddb 0.24.0",
"target": "maxminddb"
},
{
"id": "memmap2 0.9.5",
"target": "memmap2"
},
{
"id": "metrics-proxy 0.1.0",
"target": "metrics_proxy"
Expand Down Expand Up @@ -43410,6 +43414,56 @@
],
"license_file": "LICENSE-APACHE"
},
"memmap2 0.9.5": {
"name": "memmap2",
"version": "0.9.5",
"package_url": "https://github.com/RazrFalcon/memmap2-rs",
"repository": {
"Http": {
"url": "https://static.crates.io/crates/memmap2/0.9.5/download",
"sha256": "fd3f7eed9d3848f8b98834af67102b720745c4ec028fcd0aa0239277e7de374f"
}
},
"targets": [
{
"Library": {
"crate_name": "memmap2",
"crate_root": "src/lib.rs",
"srcs": {
"allow_empty": true,
"include": [
"**/*.rs"
]
}
}
}
],
"library_target_name": "memmap2",
"common_attrs": {
"compile_data_glob": [
"**"
],
"deps": {
"common": [],
"selects": {
"cfg(unix)": [
{
"id": "libc 0.2.158",
"target": "libc"
}
]
}
},
"edition": "2018",
"version": "0.9.5"
},
"license": "MIT OR Apache-2.0",
"license_ids": [
"Apache-2.0",
"MIT"
],
"license_file": "LICENSE-APACHE"
},
"memoffset 0.6.5": {
"name": "memoffset",
"version": "0.6.5",
Expand Down Expand Up @@ -91421,6 +91475,7 @@
"mach2 0.4.2",
"maplit 1.0.2",
"maxminddb 0.24.0",
"memmap2 0.9.5",
"metrics-proxy 0.1.0",
"minicbor 0.19.1",
"minicbor-derive 0.13.0",
Expand Down
12 changes: 11 additions & 1 deletion Cargo.Bazel.Fuzzing.toml.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3345,6 +3345,7 @@ dependencies = [
"mach2",
"maplit",
"maxminddb",
"memmap2 0.9.5",
"metrics-proxy",
"minicbor",
"minicbor-derive",
Expand Down Expand Up @@ -7185,6 +7186,15 @@ dependencies = [
"libc",
]

[[package]]
name = "memmap2"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd3f7eed9d3848f8b98834af67102b720745c4ec028fcd0aa0239277e7de374f"
dependencies = [
"libc",
]

[[package]]
name = "memoffset"
version = "0.6.5"
Expand Down Expand Up @@ -11454,7 +11464,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fac08504d60cf5bdffeb8a6a028f1a4868a5da1098bb19eb46239440039163fb"
dependencies = [
"debugid",
"memmap2",
"memmap2 0.5.10",
"stable_deref_trait",
"uuid",
]
Expand Down
57 changes: 56 additions & 1 deletion Cargo.Bazel.json.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"checksum": "33919baeab8c98c77bdaab8b898698318b1076055c731d76e84d3e185ddb2c74",
"checksum": "ac36051bb3fd1c488e3c6fdbdfc95fff29f3760abf119cb1fa2e1d829f1251f8",
"crates": {
"abnf 0.12.0": {
"name": "abnf",
Expand Down Expand Up @@ -19975,6 +19975,10 @@
"id": "maxminddb 0.24.0",
"target": "maxminddb"
},
{
"id": "memmap2 0.9.5",
"target": "memmap2"
},
{
"id": "metrics-proxy 0.1.0",
"target": "metrics_proxy"
Expand Down Expand Up @@ -43250,6 +43254,56 @@
],
"license_file": "LICENSE-APACHE"
},
"memmap2 0.9.5": {
"name": "memmap2",
"version": "0.9.5",
"package_url": "https://github.com/RazrFalcon/memmap2-rs",
"repository": {
"Http": {
"url": "https://static.crates.io/crates/memmap2/0.9.5/download",
"sha256": "fd3f7eed9d3848f8b98834af67102b720745c4ec028fcd0aa0239277e7de374f"
}
},
"targets": [
{
"Library": {
"crate_name": "memmap2",
"crate_root": "src/lib.rs",
"srcs": {
"allow_empty": true,
"include": [
"**/*.rs"
]
}
}
}
],
"library_target_name": "memmap2",
"common_attrs": {
"compile_data_glob": [
"**"
],
"deps": {
"common": [],
"selects": {
"cfg(unix)": [
{
"id": "libc 0.2.158",
"target": "libc"
}
]
}
},
"edition": "2018",
"version": "0.9.5"
},
"license": "MIT OR Apache-2.0",
"license_ids": [
"Apache-2.0",
"MIT"
],
"license_file": "LICENSE-APACHE"
},
"memoffset 0.6.5": {
"name": "memoffset",
"version": "0.6.5",
Expand Down Expand Up @@ -91334,6 +91388,7 @@
"mach2 0.4.2",
"maplit 1.0.2",
"maxminddb 0.24.0",
"memmap2 0.9.5",
"metrics-proxy 0.1.0",
"minicbor 0.19.1",
"minicbor-derive 0.13.0",
Expand Down
12 changes: 11 additions & 1 deletion Cargo.Bazel.toml.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3334,6 +3334,7 @@ dependencies = [
"mach2",
"maplit",
"maxminddb",
"memmap2 0.9.5",
"metrics-proxy",
"minicbor",
"minicbor-derive",
Expand Down Expand Up @@ -7176,6 +7177,15 @@ dependencies = [
"libc",
]

[[package]]
name = "memmap2"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd3f7eed9d3848f8b98834af67102b720745c4ec028fcd0aa0239277e7de374f"
dependencies = [
"libc",
]

[[package]]
name = "memoffset"
version = "0.6.5"
Expand Down Expand Up @@ -11450,7 +11460,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e0e9bc48b3852f36a84f8d0da275d50cb3c2b88b59b9ec35fdd8b7fa239e37d"
dependencies = [
"debugid",
"memmap2",
"memmap2 0.5.10",
"stable_deref_trait",
"uuid",
]
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,7 @@ libflate = "2.1.0"
libnss = "0.5.0"
local-ip-address = "0.5.6"
macaddr = "1.0"
memmap2 = "0.9.5"
minicbor = { version = "0.19.1", features = ["alloc", "derive"] }
minicbor-derive = "0.13.0"
mockall = "0.13.0"
Expand Down
3 changes: 3 additions & 0 deletions bazel/external_crates.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,9 @@ def external_crates_repository(name, cargo_lockfile, lockfile, sanitizers_enable
"macaddr": crate.spec(
version = "^1.0",
),
"memmap2": crate.spec(
version = "^0.9.5",
),
"mach2": crate.spec(
# Wasmtime depends on 0.4.2 but specifies 0.4.1.
# Enforce 0.4.2 using a dummy dependency until
Expand Down
13 changes: 13 additions & 0 deletions rs/memory_tracker/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,16 @@ rust_bench(
"@crate_index//:criterion",
] + DEPENDENCIES,
)

rust_bench(
name = "memory_ops_bench",
testonly = True,
srcs = ["benches/memory_ops.rs"],
data = ["benches/test-data/64KiB.txt"],
deps = [
# Keep sorted.
"@crate_index//:criterion",
"@crate_index//:memmap2",
"@crate_index//:rayon",
] + DEPENDENCIES,
)
12 changes: 9 additions & 3 deletions rs/memory_tracker/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[package]
name = "memory_tracker"
version.workspace = true
authors.workspace = true
edition.workspace = true
description.workspace = true
documentation.workspace = true
edition.workspace = true
name = "memory_tracker"
version.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -25,9 +25,15 @@ sigsegv_handler_checksum = []
[dev-dependencies]
criterion = { workspace = true }
ic-types = { path = "../types/types" }
memmap2 = { workspace = true }
proptest = { workspace = true }
rayon = { workspace = true }
tempfile = { workspace = true }

[[bench]]
harness = false
name = "traps"

[[bench]]
harness = false
name = "memory_ops"
Loading

0 comments on commit 7cd54f4

Please sign in to comment.