From 270c10bbe7a1c53c1a937ac4810649dcbeb078c3 Mon Sep 17 00:00:00 2001 From: Tatsuya Kawano Date: Tue, 8 Aug 2023 17:02:30 +0800 Subject: [PATCH 1/8] Fix Clippy warnings clippy 0.1.72 (d8fd588afa2 2023-08-03) --- src/cache/hashlink.rs | 5 +---- src/cache/mini_moka_driver/sync_cache.rs | 2 +- src/cache/mini_moka_driver/unsync_cache.rs | 2 +- src/cache/moka_driver/async_cache.rs | 4 ++-- src/cache/moka_driver/sync_cache.rs | 4 ++-- src/cache/moka_driver/sync_segmented.rs | 4 ++-- src/cache/quick_cache.rs | 2 +- 7 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/cache/hashlink.rs b/src/cache/hashlink.rs index 794d846..684f3ab 100644 --- a/src/cache/hashlink.rs +++ b/src/cache/hashlink.rs @@ -28,10 +28,7 @@ impl HashLink { Self { config: Arc::new(config.clone()), - cache: Arc::new(Mutex::new(LruCache::with_hasher( - capacity, - DefaultHasher::default(), - ))), + cache: Arc::new(Mutex::new(LruCache::with_hasher(capacity, DefaultHasher))), } } diff --git a/src/cache/mini_moka_driver/sync_cache.rs b/src/cache/mini_moka_driver/sync_cache.rs index 3a2d3c1..1c2d5ba 100644 --- a/src/cache/mini_moka_driver/sync_cache.rs +++ b/src/cache/mini_moka_driver/sync_cache.rs @@ -39,7 +39,7 @@ impl MiniMokSyncCache { Self { config: Arc::new(config.clone()), - cache: builder.build_with_hasher(DefaultHasher::default()), + cache: builder.build_with_hasher(DefaultHasher), } } diff --git a/src/cache/mini_moka_driver/unsync_cache.rs b/src/cache/mini_moka_driver/unsync_cache.rs index 8b38e6a..35378cb 100644 --- a/src/cache/mini_moka_driver/unsync_cache.rs +++ b/src/cache/mini_moka_driver/unsync_cache.rs @@ -31,7 +31,7 @@ impl MiniMokaUnsyncCache { Self { config: config.clone(), - cache: builder.build_with_hasher(DefaultHasher::default()), + cache: builder.build_with_hasher(DefaultHasher), } } diff --git a/src/cache/moka_driver/async_cache.rs b/src/cache/moka_driver/async_cache.rs index 28f6ca9..288ff3c 100644 --- a/src/cache/moka_driver/async_cache.rs +++ b/src/cache/moka_driver/async_cache.rs @@ -123,7 +123,7 @@ impl MokaAsyncCache { #[cfg(feature = "moka-v08")] { - cache = builder.build_with_hasher(DefaultHasher::default()); + cache = builder.build_with_hasher(DefaultHasher); eviction_counters = None; } @@ -143,7 +143,7 @@ impl MokaAsyncCache { eviction_counters = None; } - cache = builder.build_with_hasher(DefaultHasher::default()); + cache = builder.build_with_hasher(DefaultHasher); } (cache, eviction_counters) diff --git a/src/cache/moka_driver/sync_cache.rs b/src/cache/moka_driver/sync_cache.rs index b7afff9..41ae3f2 100644 --- a/src/cache/moka_driver/sync_cache.rs +++ b/src/cache/moka_driver/sync_cache.rs @@ -122,7 +122,7 @@ impl MokaSyncCache { #[cfg(feature = "moka-v08")] { - cache = builder.build_with_hasher(DefaultHasher::default()); + cache = builder.build_with_hasher(DefaultHasher); eviction_counters = None; } @@ -155,7 +155,7 @@ impl MokaSyncCache { eviction_counters = None; } - cache = builder.build_with_hasher(DefaultHasher::default()); + cache = builder.build_with_hasher(DefaultHasher); } (cache, eviction_counters) diff --git a/src/cache/moka_driver/sync_segmented.rs b/src/cache/moka_driver/sync_segmented.rs index 48f37f2..deaddad 100644 --- a/src/cache/moka_driver/sync_segmented.rs +++ b/src/cache/moka_driver/sync_segmented.rs @@ -129,7 +129,7 @@ impl MokaSegmentedCache { #[cfg(feature = "moka-v08")] { - cache = builder.build_with_hasher(DefaultHasher::default()); + cache = builder.build_with_hasher(DefaultHasher); eviction_counters = None; } @@ -162,7 +162,7 @@ impl MokaSegmentedCache { eviction_counters = None; } - cache = builder.build_with_hasher(DefaultHasher::default()); + cache = builder.build_with_hasher(DefaultHasher); } (cache, eviction_counters) diff --git a/src/cache/quick_cache.rs b/src/cache/quick_cache.rs index f00821e..1cca4fc 100644 --- a/src/cache/quick_cache.rs +++ b/src/cache/quick_cache.rs @@ -46,7 +46,7 @@ impl QuickCache { cache: ::quick_cache::sync::Cache::with_options( options, CustomWeighter(config.size_aware), - DefaultHasher::default(), + DefaultHasher, ) .into(), } From 5cbc1972fd66df4b71f51d3b86f44488f75453f2 Mon Sep 17 00:00:00 2001 From: Tatsuya Kawano Date: Tue, 8 Aug 2023 17:11:24 +0800 Subject: [PATCH 2/8] Bump the version to 0.10.0. Support moka v0.12.x --- CHANGELOG.md | 7 + Cargo.lock | 607 ++++++++++++++------------- Cargo.toml | 24 +- src/cache.rs | 2 +- src/cache/moka_driver/async_cache.rs | 33 +- src/lib.rs | 14 +- src/main.rs | 14 +- 7 files changed, 395 insertions(+), 306 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f52379..4a51b41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Mokabench — Change Log +## Version 0.10.0 + +### Added + +- Added support for moka v0.12. ([#??](gh-pull-????)) + + ## Version 0.9.0 ### Added diff --git a/Cargo.lock b/Cargo.lock index d18d7fa..a401398 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,16 +3,20 @@ version = 3 [[package]] -name = "ahash" -version = "0.7.6" +name = "addr2line" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +checksum = "f4fa78e18c64fce05e902adecd7a5eed15a5e0a3439f7b0e169f0252214865e3" dependencies = [ - "getrandom", - "once_cell", - "version_check", + "gimli", ] +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + [[package]] name = "ahash" version = "0.8.3" @@ -25,11 +29,17 @@ dependencies = [ "version_check", ] +[[package]] +name = "allocator-api2" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" + [[package]] name = "anyhow" -version = "1.0.71" +version = "1.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8" +checksum = "3b13c32d80ecc7ab747b80c3784bce54ee8a7a0cc4fbda9bf4cda2cf6fe90854" [[package]] name = "async-io" @@ -45,7 +55,7 @@ dependencies = [ "log", "parking", "polling", - "rustix", + "rustix 0.37.23", "slab", "socket2", "waker-fn", @@ -62,23 +72,26 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.68" +version = "0.1.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842" +checksum = "cc6dde6e4ed435a4c1ee4e73592f5ba9da2151af10076cc04858746af9352d09" dependencies = [ "proc-macro2", "quote", - "syn 2.0.15", + "syn", ] [[package]] name = "atomic" -version = "0.5.1" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b88d82667eca772c4aa12f0f1348b3ae643424c8876448f3f7bd5787032e234c" -dependencies = [ - "autocfg", -] +checksum = "c59bdb34bc650a32731b31bd8f0829cc15d24a708ee31559e0bb34f2bc320cba" + +[[package]] +name = "atomic-waker" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1181e1e0d1fce796a03db1ae795d67167da795f9cf4a39c37589e85ef57f26d3" [[package]] name = "atty" @@ -97,17 +110,38 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "backtrace" +version = "0.3.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4319208da049c43661739c5fade2ba182f09d1dc2299b32298d3a31692b17e12" +dependencies = [ + "addr2line", + "cc", + "cfg-if 1.0.0", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + [[package]] name = "bitflags" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42" + [[package]] name = "bumpalo" -version = "3.12.1" +version = "3.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b1ce199063694f33ffb7dd4e0ee620741495c32833cde5aa08f02a0bf96f0c8" +checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" [[package]] name = "bytecount" @@ -117,18 +151,18 @@ checksum = "2c676a478f63e9fa2dd5368a42f28bba0d6c560b775f38583c8bbaa7fcd67c9c" [[package]] name = "camino" -version = "1.1.4" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c530edf18f37068ac2d977409ed5cd50d53d73bc653c7647b48eb78976ac9ae2" +checksum = "c59e92b5a388f549b863a7bea62612c09f24c8393560709a54558a9abdfb3b9c" dependencies = [ "serde", ] [[package]] name = "cargo-platform" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbdb825da8a5df079a43676dbe042702f1707b1109f713a01420fbb4cc71fa27" +checksum = "2cfa25e60aea747ec7e1124f238816749faa93759c6ff5b31f1ccdda137f4479" dependencies = [ "serde", ] @@ -148,9 +182,12 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.79" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +checksum = "305fe645edc1442a0fa8b6726ba61d422798d37a52e12eaecf4b022ebbb88f01" +dependencies = [ + "libc", +] [[package]] name = "cfg-if" @@ -171,7 +208,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" dependencies = [ "atty", - "bitflags", + "bitflags 1.3.2", "clap_lex", "indexmap", "strsim", @@ -194,7 +231,7 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62ec6771ecfa0762d24683ee5a32ad78487a3d3afdc0fb8cae19d2c5deb50b7c" dependencies = [ - "crossbeam-utils 0.8.15", + "crossbeam-utils 0.8.16", ] [[package]] @@ -204,7 +241,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" dependencies = [ "cfg-if 1.0.0", - "crossbeam-utils 0.8.15", + "crossbeam-utils 0.8.16", ] [[package]] @@ -224,14 +261,14 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.9.14" +version = "0.9.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46bd5f3f85273295a9d14aedfb86f6aadbff6d8f5295c4a9edb08e819dcf5695" +checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7" dependencies = [ "autocfg", "cfg-if 1.0.0", - "crossbeam-utils 0.8.15", - "memoffset 0.8.0", + "crossbeam-utils 0.8.16", + "memoffset 0.9.0", "scopeguard", ] @@ -248,21 +285,21 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.15" +version = "0.8.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b" +checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" dependencies = [ "cfg-if 1.0.0", ] [[package]] name = "dashmap" -version = "5.4.0" +version = "5.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907076dfda823b0b36d2a1bb5f90c96660a5bbcd7729e10727f07858f22c4edc" +checksum = "6943ae99c34386c84a470c499d3414f66502a41340aa895406e0d2e4a207b91d" dependencies = [ "cfg-if 1.0.0", - "hashbrown 0.12.3", + "hashbrown 0.14.0", "lock_api", "once_cell", "parking_lot_core", @@ -270,19 +307,19 @@ dependencies = [ [[package]] name = "either" -version = "1.8.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] name = "errno" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" +checksum = "6b30f669a7961ef1631673d2766cc92f52d64f7ef354d4fe0ddfd30ed52f0f4f" dependencies = [ "errno-dragonfly", "libc", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -319,6 +356,12 @@ dependencies = [ "instant", ] +[[package]] +name = "fastrand" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764" + [[package]] name = "futures-core" version = "0.3.28" @@ -337,7 +380,7 @@ version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce" dependencies = [ - "fastrand", + "fastrand 1.9.0", "futures-core", "futures-io", "memchr", @@ -354,7 +397,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.15", + "syn", ] [[package]] @@ -379,15 +422,21 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.9" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c85e1d9ab2eadba7e5040d4e09cbd6d072b76a557ad64e797c2cb9d4da21d7e4" +checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" dependencies = [ "cfg-if 1.0.0", "libc", "wasi 0.11.0+wasi-snapshot-preview1", ] +[[package]] +name = "gimli" +version = "0.27.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e" + [[package]] name = "glob" version = "0.3.1" @@ -399,9 +448,6 @@ name = "hashbrown" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" -dependencies = [ - "ahash 0.7.6", -] [[package]] name = "hashbrown" @@ -410,37 +456,38 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" [[package]] -name = "hashlink" -version = "0.8.1" +name = "hashbrown" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69fe1fcf8b4278d860ad0548329f892a3631fb63f82574df68275f34cdbe0ffa" +checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" dependencies = [ - "hashbrown 0.12.3", + "ahash", + "allocator-api2", ] [[package]] -name = "hermit-abi" -version = "0.1.19" +name = "hashlink" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +checksum = "312f66718a2d7789ffef4f4b7b213138ed9f1eb3aa1d0d82fc99f88fb3ffd26f" dependencies = [ - "libc", + "hashbrown 0.14.0", ] [[package]] name = "hermit-abi" -version = "0.2.6" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" dependencies = [ "libc", ] [[package]] name = "hermit-abi" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" +checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" [[package]] name = "indexmap" @@ -463,35 +510,35 @@ dependencies = [ [[package]] name = "io-lifetimes" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c66c74d2ae7e79a5a8f7ac924adbe38ee42a859c6539ad869eb51f0b52dc220" +checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" dependencies = [ - "hermit-abi 0.3.1", + "hermit-abi 0.3.2", "libc", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] name = "itertools" -version = "0.10.5" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" dependencies = [ "either", ] [[package]] name = "itoa" -version = "1.0.6" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" +checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" [[package]] name = "js-sys" -version = "0.3.61" +version = "0.3.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" +checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" dependencies = [ "wasm-bindgen", ] @@ -504,21 +551,27 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.142" +version = "0.2.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a987beff54b60ffa6d51982e1aa1146bc42f19bd26be28b0586f252fccf5317" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" [[package]] name = "linux-raw-sys" -version = "0.3.7" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ece97ea872ece730aed82664c424eb4c8291e1ff2480247ccf7409044bc6479f" +checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" + +[[package]] +name = "linux-raw-sys" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57bcfdad1b858c2db7c38303a6d2ad4dfaf5eb53dfeb0910128b2c26d6158503" [[package]] name = "lock_api" -version = "0.4.9" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" +checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" dependencies = [ "autocfg", "scopeguard", @@ -526,12 +579,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.17" +version = "0.4.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" -dependencies = [ - "cfg-if 1.0.0", -] +checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" [[package]] name = "mach" @@ -574,21 +624,21 @@ dependencies = [ [[package]] name = "memoffset" -version = "0.8.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1" +checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" dependencies = [ "autocfg", ] [[package]] name = "mini-moka" -version = "0.10.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cafc5ec7807288595f9c20c86e6ce6d262b722f61e0547fe7e6e6e6451b58d5" +checksum = "452ebc1428a585e31e637b928b76355ef2fd72d765b2530d72fe475e514cd1eb" dependencies = [ "crossbeam-channel", - "crossbeam-utils 0.8.15", + "crossbeam-utils 0.8.16", "dashmap", "skeptic", "smallvec", @@ -596,6 +646,15 @@ dependencies = [ "triomphe", ] +[[package]] +name = "miniz_oxide" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" +dependencies = [ + "adler", +] + [[package]] name = "moka" version = "0.8.6" @@ -606,7 +665,7 @@ dependencies = [ "async-lock", "crossbeam-channel", "crossbeam-epoch 0.8.2", - "crossbeam-utils 0.8.15", + "crossbeam-utils 0.8.16", "dashmap", "futures-util", "num_cpus", @@ -624,21 +683,21 @@ dependencies = [ [[package]] name = "moka" -version = "0.9.7" +version = "0.9.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19b9268097a2cf211ac9955b1cc95e80fa84fff5c2d13ba292916445dc8a311f" +checksum = "b28455ac4363046076054a7e9cfbd7f168019c29dba32a625f59fc0aeffaaea4" dependencies = [ "async-io", "async-lock", "crossbeam-channel", - "crossbeam-epoch 0.9.14", - "crossbeam-utils 0.8.15", + "crossbeam-epoch 0.9.15", + "crossbeam-utils 0.8.16", "dashmap", "futures-util", "num_cpus", "once_cell", "parking_lot", - "quanta 0.10.1", + "quanta 0.11.1", "rustc_version", "scheduled-thread-pool", "skeptic", @@ -651,20 +710,20 @@ dependencies = [ [[package]] name = "moka" -version = "0.10.2" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0d3b8e76a2e4b17de765db9432e377a171c42fbe0512b8bc860ff1bfe2e273b" +checksum = "0be0a3dd6fe7c99233c2b1476e703147fb7516c68dce585b19b51efc08fe93d8" dependencies = [ "async-io", "async-lock", "crossbeam-channel", - "crossbeam-epoch 0.9.14", - "crossbeam-utils 0.8.15", + "crossbeam-epoch 0.9.15", + "crossbeam-utils 0.8.16", "futures-util", "num_cpus", "once_cell", "parking_lot", - "quanta 0.11.0", + "quanta 0.11.1", "rustc_version", "scheduled-thread-pool", "skeptic", @@ -677,20 +736,42 @@ dependencies = [ [[package]] name = "moka" -version = "0.11.0" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "934030d03f6191edbb4ba16835ccdb80d560788ac686570a8e2986a0fb59ded8" +checksum = "fa6e72583bf6830c956235bff0d5afec8cf2952f579ebad18ae7821a917d950f" dependencies = [ "async-io", "async-lock", "crossbeam-channel", - "crossbeam-epoch 0.9.14", - "crossbeam-utils 0.8.15", + "crossbeam-epoch 0.9.15", + "crossbeam-utils 0.8.16", "futures-util", - "num_cpus", "once_cell", "parking_lot", - "quanta 0.11.0", + "quanta 0.11.1", + "rustc_version", + "scheduled-thread-pool", + "skeptic", + "smallvec", + "tagptr", + "thiserror", + "triomphe", + "uuid", +] + +[[package]] +name = "moka" +version = "0.12.0-beta.1" +dependencies = [ + "async-lock", + "async-trait", + "crossbeam-channel", + "crossbeam-epoch 0.9.15", + "crossbeam-utils 0.8.16", + "futures-util", + "once_cell", + "parking_lot", + "quanta 0.11.1", "rustc_version", "scheduled-thread-pool", "skeptic", @@ -703,7 +784,7 @@ dependencies = [ [[package]] name = "mokabench" -version = "0.9.0" +version = "0.10.0" dependencies = [ "anyhow", "async-io", @@ -714,10 +795,11 @@ dependencies = [ "hashlink", "itertools", "mini-moka", - "moka 0.10.2", - "moka 0.11.0", + "moka 0.10.4", + "moka 0.11.3", + "moka 0.12.0-beta.1", "moka 0.8.6", - "moka 0.9.7", + "moka 0.9.9", "parking_lot", "quick_cache", "stretto", @@ -728,25 +810,34 @@ dependencies = [ [[package]] name = "num_cpus" -version = "1.15.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi 0.2.6", + "hermit-abi 0.3.2", "libc", ] +[[package]] +name = "object" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bda667d9f2b5051b8833f59f3bf748b28ef54f850f4fcb389a252aa383866d1" +dependencies = [ + "memchr", +] + [[package]] name = "once_cell" -version = "1.17.1" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] name = "os_str_bytes" -version = "6.5.0" +version = "6.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ceedf44fb00f2d1984b0bc98102627ce622e083e49a5bacdb3e514fa4238e267" +checksum = "4d5d9eb14b174ee9aa2ef96dc2b94637a2d4b6e7cb873c7e171f0c20c6cf3eac" [[package]] name = "parking" @@ -766,22 +857,22 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.7" +version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" +checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" dependencies = [ "cfg-if 1.0.0", "libc", - "redox_syscall 0.2.16", + "redox_syscall", "smallvec", - "windows-sys 0.45.0", + "windows-targets", ] [[package]] name = "pin-project-lite" -version = "0.2.9" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" +checksum = "2c516611246607d0c04186886dbb3a754368ef82c79e9827a802c6d836dd111c" [[package]] name = "pin-utils" @@ -796,13 +887,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b2d323e8ca7996b3e23126511a523f7e62924d93ecd5ae73b333815b0eb3dce" dependencies = [ "autocfg", - "bitflags", + "bitflags 1.3.2", "cfg-if 1.0.0", "concurrent-queue", "libc", "log", "pin-project-lite", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -813,20 +904,20 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.56" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" dependencies = [ "unicode-ident", ] [[package]] name = "pulldown-cmark" -version = "0.9.2" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d9cc634bc78768157b5cbfe988ffcd1dcba95cd2b2f03a88316c08c6d00ed63" +checksum = "77a1a2f1f0a7ecff9c31abbe177637be0e97a0aef46cf8738ece09327985d998" dependencies = [ - "bitflags", + "bitflags 1.3.2", "memchr", "unicase", ] @@ -837,7 +928,7 @@ version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b7e31331286705f455e56cca62e0e717158474ff02b7936c1fa596d983f4ae27" dependencies = [ - "crossbeam-utils 0.8.15", + "crossbeam-utils 0.8.16", "libc", "mach", "once_cell", @@ -849,11 +940,11 @@ dependencies = [ [[package]] name = "quanta" -version = "0.11.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cc73c42f9314c4bdce450c77e6f09ecbddefbeddb1b5979ded332a3913ded33" +checksum = "a17e662a7a8291a865152364c20c7abc5e60486ab2001e8ec10b24862de0b9ab" dependencies = [ - "crossbeam-utils 0.8.15", + "crossbeam-utils 0.8.16", "libc", "mach2", "once_cell", @@ -869,16 +960,16 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "539169dc3bed0d6c3982dddb746a3d8907ec50863d9d1bbe3a5bcd413e53e805" dependencies = [ - "ahash 0.8.3", + "ahash", "hashbrown 0.13.2", "parking_lot", ] [[package]] name = "quote" -version = "1.0.26" +version = "1.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" +checksum = "50f3b39ccfb720540debaa0164757101c08ecb8d326b15358ce76a62c7e85965" dependencies = [ "proc-macro2", ] @@ -919,26 +1010,23 @@ version = "10.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c297679cb867470fa8c9f67dbba74a78d78e3e98d7cf2b08d6d71540f797332" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] name = "redox_syscall" -version = "0.2.16" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] -name = "redox_syscall" -version = "0.3.5" +name = "rustc-demangle" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" -dependencies = [ - "bitflags", -] +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" [[package]] name = "rustc_version" @@ -951,23 +1039,36 @@ dependencies = [ [[package]] name = "rustix" -version = "0.37.19" +version = "0.37.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acf8729d8542766f1b2cf77eb034d52f40d375bb8b615d0b147089946e16613d" +checksum = "4d69718bf81c6127a49dc64e44a742e8bb9213c0ff8869a22c308f84c1d4ab06" dependencies = [ - "bitflags", + "bitflags 1.3.2", "errno", "io-lifetimes", "libc", - "linux-raw-sys", - "windows-sys 0.48.0", + "linux-raw-sys 0.3.8", + "windows-sys", +] + +[[package]] +name = "rustix" +version = "0.38.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "172891ebdceb05aa0005f533a6cbfca599ddd7d966f6f5d4d9b2e70478e70399" +dependencies = [ + "bitflags 2.3.3", + "errno", + "libc", + "linux-raw-sys 0.4.5", + "windows-sys", ] [[package]] name = "ryu" -version = "1.0.13" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" +checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" [[package]] name = "same-file" @@ -989,9 +1090,9 @@ dependencies = [ [[package]] name = "scopeguard" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "seahash" @@ -1001,38 +1102,38 @@ checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" [[package]] name = "semver" -version = "1.0.17" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed" +checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" dependencies = [ "serde", ] [[package]] name = "serde" -version = "1.0.160" +version = "1.0.183" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb2f3770c8bce3bcda7e149193a069a0f4365bda1fa5cd88e03bca26afc1216c" +checksum = "32ac8da02677876d532745a130fc9d8e6edfa81a269b107c5b00829b91d8eb3c" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.160" +version = "1.0.183" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df" +checksum = "aafe972d60b0b9bee71a91b92fee2d4fb3c9d7e8f6b179aa99f27203d99a4816" dependencies = [ "proc-macro2", "quote", - "syn 2.0.15", + "syn", ] [[package]] name = "serde_json" -version = "1.0.96" +version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "057d394a50403bcac12672b2b18fb387ab6d289d957dab67dd201875391e52f1" +checksum = "076066c5f1078eac5b722a31827a8832fe108bed65dfa75e233c89f8206e976c" dependencies = [ "itoa", "ryu", @@ -1065,9 +1166,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" [[package]] name = "socket2" @@ -1109,20 +1210,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.15" +version = "2.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822" +checksum = "04361975b3f5e348b2189d8dc55bc942f278b2d482a6a0365de5bdd62d351567" dependencies = [ "proc-macro2", "quote", @@ -1137,15 +1227,15 @@ checksum = "7b2093cf4c8eb1e67749a6762251bc9cd836b6fc171623bd0a9d324d37af2417" [[package]] name = "tempfile" -version = "3.5.0" +version = "3.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9fbec84f381d5795b08656e4912bec604d162bff9291d6189a78f4c8ab87998" +checksum = "dc02fddf48964c42031a0b3fe0428320ecf3a73c401040fc0096f97794310651" dependencies = [ "cfg-if 1.0.0", - "fastrand", - "redox_syscall 0.3.5", - "rustix", - "windows-sys 0.45.0", + "fastrand 2.0.0", + "redox_syscall", + "rustix 0.38.7", + "windows-sys", ] [[package]] @@ -1165,35 +1255,35 @@ checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" [[package]] name = "thiserror" -version = "1.0.40" +version = "1.0.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" +checksum = "611040a08a0439f8248d1990b111c95baa9c704c805fa1f62104b39655fd7f90" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.40" +version = "1.0.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" +checksum = "090198534930841fab3a5d1bb637cde49e339654e606195f8d9c76eeb081dc96" dependencies = [ "proc-macro2", "quote", - "syn 2.0.15", + "syn", ] [[package]] name = "tokio" -version = "1.28.0" +version = "1.29.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3c786bf8134e5a3a166db9b29ab8f48134739014a3eca7bc6bfa95d673b136f" +checksum = "532826ff75199d5833b9d2c5fe410f29235e25704ee5f0ef599fb51c21f4a4da" dependencies = [ "autocfg", + "backtrace", "num_cpus", "pin-project-lite", "tokio-macros", - "windows-sys 0.48.0", ] [[package]] @@ -1204,14 +1294,14 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.15", + "syn", ] [[package]] name = "triomphe" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1ee9bd9239c339d714d657fac840c6d2a4f9c45f4f9ec7b0975113458be78db" +checksum = "0eee8098afad3fb0c54a9007aab6804558410503ad676d4633f9c2559a00ac0f" dependencies = [ "serde", "stable_deref_trait", @@ -1228,15 +1318,15 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.8" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" +checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" [[package]] name = "uuid" -version = "1.3.2" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dad5567ad0cf5b760e5665964bec1b47dfd077ba8a2544b513f3556d3d239a2" +checksum = "79daa5ed5740825c40b389c5e50312b9c86df53fccd33f281df655642b43869d" dependencies = [ "getrandom", ] @@ -1277,9 +1367,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.84" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" +checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" dependencies = [ "cfg-if 1.0.0", "wasm-bindgen-macro", @@ -1287,24 +1377,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.84" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" +checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 1.0.109", + "syn", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.84" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" +checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1312,28 +1402,28 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.84" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" +checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.84" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" +checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" [[package]] name = "web-sys" -version = "0.3.61" +version = "0.3.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e33b99f4b23ba3eec1a53ac264e35a755f00e966e0065077d6027c0f575b0b97" +checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" dependencies = [ "js-sys", "wasm-bindgen", @@ -1341,10 +1431,11 @@ dependencies = [ [[package]] name = "wg" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc4a87eca0e149703202bc625506b908d94f620dfbfbad7aac3402b2868f0043" +checksum = "f390449c16e0679435fc97a6b49d24e67f09dd05fea1de54db1b60902896d273" dependencies = [ + "atomic-waker", "parking_lot", "triomphe", ] @@ -1380,132 +1471,66 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows-sys" -version = "0.45.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" -dependencies = [ - "windows-targets 0.42.2", -] - [[package]] name = "windows-sys" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows-targets 0.48.0", + "windows-targets", ] [[package]] name = "windows-targets" -version = "0.42.2" +version = "0.48.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" dependencies = [ - "windows_aarch64_gnullvm 0.42.2", - "windows_aarch64_msvc 0.42.2", - "windows_i686_gnu 0.42.2", - "windows_i686_msvc 0.42.2", - "windows_x86_64_gnu 0.42.2", - "windows_x86_64_gnullvm 0.42.2", - "windows_x86_64_msvc 0.42.2", -] - -[[package]] -name = "windows-targets" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" -dependencies = [ - "windows_aarch64_gnullvm 0.48.0", - "windows_aarch64_msvc 0.48.0", - "windows_i686_gnu 0.48.0", - "windows_i686_msvc 0.48.0", - "windows_x86_64_gnu 0.48.0", - "windows_x86_64_gnullvm 0.48.0", - "windows_x86_64_msvc 0.48.0", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" - [[package]] name = "windows_aarch64_gnullvm" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" -[[package]] -name = "windows_aarch64_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" - [[package]] name = "windows_aarch64_msvc" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" -[[package]] -name = "windows_i686_gnu" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" - [[package]] name = "windows_i686_gnu" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" -[[package]] -name = "windows_i686_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" - [[package]] name = "windows_i686_msvc" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" -[[package]] -name = "windows_x86_64_gnu" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" - [[package]] name = "windows_x86_64_gnu" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" - [[package]] name = "windows_x86_64_gnullvm" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" -[[package]] -name = "windows_x86_64_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" - [[package]] name = "windows_x86_64_msvc" version = "0.48.0" diff --git a/Cargo.toml b/Cargo.toml index 1a0feac..2c3e7b1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,13 +1,14 @@ [package] name = "mokabench" -version = "0.9.0" +version = "0.10.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] -default = ["moka-v011"] +default = ["moka-v012"] +moka-v012 = ["moka012"] moka-v011 = ["moka011"] moka-v010 = ["moka010"] moka-v09 = ["moka09"] @@ -24,7 +25,7 @@ async-trait = "0.1.64" clap = "3.2.23" crossbeam-channel = "0.5.6" futures-util = "0.3.26" -itertools = "0.10.5" +itertools = "0.11.0" parking_lot = "0.12.1" thiserror = "1.0.38" xxhash-rust = { version = "0.8.6", features = ["xxh3"] } @@ -38,25 +39,34 @@ mini-moka = { optional = true, version = "0.10.0" } quick_cache = { optional = true, version = "0.2.1" } stretto = { optional = true, version = "0.7.1" } +[dependencies.moka012] +package = "moka" +optional = true +# version = "0.12.0" +# git = "https://github.com/moka-rs/moka" +# branch = "main" +path = "../moka" +features = ["future"] + [dependencies.moka011] package = "moka" optional = true -version = "0.11.0" +version = "0.11.3" # git = "https://github.com/moka-rs/moka" -# branch = "master" +# branch = "main" # path = "../moka" features = ["future"] [dependencies.moka010] package = "moka" optional = true -version = "0.10.2" +version = "0.10.4" features = ["future"] [dependencies.moka09] package = "moka" optional = true -version = "0.9.7" +version = "0.9.9" features = ["future", "dash"] [dependencies.moka08] diff --git a/src/cache.rs b/src/cache.rs index 82f14c1..4c1d20e 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -150,7 +150,7 @@ const VALUE_LEN: usize = 128; pub(crate) fn make_value(config: &Config, key: usize, req_id: usize) -> Value { let policy_weight = if config.size_aware { - let mut hasher = DefaultHasher::default().build_hasher(); + let mut hasher = DefaultHasher.build_hasher(); req_id.hash(&mut hasher); // len will be [4 .. 2^16) (hasher.finish() as u16).max(4) as u32 diff --git a/src/cache/moka_driver/async_cache.rs b/src/cache/moka_driver/async_cache.rs index 288ff3c..ca453ba 100644 --- a/src/cache/moka_driver/async_cache.rs +++ b/src/cache/moka_driver/async_cache.rs @@ -127,7 +127,28 @@ impl MokaAsyncCache { eviction_counters = None; } - #[cfg(not(feature = "moka-v08"))] + #[cfg(feature = "moka-v012")] + { + use crate::moka::future::FutureExt; + + if config.is_eviction_listener_enabled() { + let c0 = Arc::new(EvictionCounters::default()); + let c1 = Arc::clone(&c0); + + builder = builder.eviction_listener(move |_k, _v, cause| { + c1.increment(cause); + async {}.boxed() + }); + + eviction_counters = Some(c0); + } else { + eviction_counters = None; + } + + cache = builder.build_with_hasher(DefaultHasher); + } + + #[cfg(any(feature = "moka-v011", feature = "moka-v010", feature = "moka-v09"))] { if config.is_eviction_listener_enabled() { let c0 = Arc::new(EvictionCounters::default()); @@ -149,7 +170,13 @@ impl MokaAsyncCache { (cache, eviction_counters) } - fn get(&self, key: usize) -> bool { + #[cfg(feature = "moka-v012")] + async fn get(&self, key: usize) -> bool { + self.cache.get(&key).await.is_some() + } + + #[cfg(not(feature = "moka-v012"))] + async fn get(&self, key: usize) -> bool { self.cache.get(&key).is_some() } @@ -170,7 +197,7 @@ where let mut req_id = entry.line_number(); for block in entry.range() { - if self.get(block) { + if self.get(block).await { counters.read_hit(); } else { self.insert(block, req_id).await; diff --git a/src/lib.rs b/src/lib.rs index 9d38328..b4f2282 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,9 +1,14 @@ #[cfg(all( - feature = "moka-v011", - any(feature = "moka-v010", feature = "moka-v09", feature = "moka-v08") + feature = "moka-v012", + any( + feature = "moka-v011", + feature = "moka-v010", + feature = "moka-v09", + feature = "moka-v08" + ) ))] compile_error!( - "You cannot enable `moka-v010`, `moka-v09` and/or `moka-v8` features while `moka-v011` is enabled.\n\ + "You cannot enable `moka-v011`, `moka-v010`, `moka-v09` and/or `moka-v8` features while `moka-v012` is enabled.\n\ You might need `--no-default-features`." ); @@ -11,6 +16,9 @@ use std::io::prelude::*; use std::sync::Arc; use std::{fs::File, io::BufReader, time::Instant}; +#[cfg(feature = "moka-v012")] +pub(crate) use moka012 as moka; + #[cfg(feature = "moka-v011")] pub(crate) use moka011 as moka; diff --git a/src/main.rs b/src/main.rs index 7150b8e..6544dcd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -99,7 +99,19 @@ async fn run_with_capacity(config: &Config, capacity: usize) -> anyhow::Result<( } for num_clients in num_clients_slice { - if config.eviction_listener == RemovalNotificationMode::Immediate { + if cfg!(feature = "moka-v012") + && config.eviction_listener == RemovalNotificationMode::Queued + { + eprintln!( + "WARNING: eviction_listener = \"queued\" is not supported by \ + the async cache. \"immediate\" mode will be used for it." + ); + } else if cfg!(any( + feature = "moka-v09", + feature = "moka-v010", + feature = "moka-v011" + )) && config.eviction_listener == RemovalNotificationMode::Immediate + { eprintln!( "WARNING: eviction_listener = \"immediate\" is not supported by \ the async cache. \"queued\" mode will be used for it." From e12f7b1e3c17526c36a118791a18e21dac8e868a Mon Sep 17 00:00:00 2001 From: Tatsuya Kawano Date: Sat, 12 Aug 2023 20:35:10 +0800 Subject: [PATCH 3/8] Support async-std --- Cargo.lock | 208 +++++++++++++++++++++++---- Cargo.toml | 18 ++- README.md | 19 ++- src/async_rt_helper.rs | 57 ++++++++ src/cache/moka_driver/async_cache.rs | 3 +- src/lib.rs | 15 +- src/main.rs | 14 ++ 7 files changed, 294 insertions(+), 40 deletions(-) create mode 100644 src/async_rt_helper.rs diff --git a/Cargo.lock b/Cargo.lock index a401398..4db1c24 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -41,6 +41,56 @@ version = "1.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b13c32d80ecc7ab747b80c3784bce54ee8a7a0cc4fbda9bf4cda2cf6fe90854" +[[package]] +name = "async-attributes" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3203e79f4dd9bdda415ed03cf14dae5a2bf775c683a00f94e9cd1faf0f596e5" +dependencies = [ + "quote", + "syn 1.0.109", +] + +[[package]] +name = "async-channel" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81953c529336010edd6d8e358f886d9581267795c61b19475b71314bffa46d35" +dependencies = [ + "concurrent-queue", + "event-listener", + "futures-core", +] + +[[package]] +name = "async-executor" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fa3dc5f2a8564f07759c008b9109dc0d39de92a88d5588b8a5036d286383afb" +dependencies = [ + "async-lock", + "async-task", + "concurrent-queue", + "fastrand 1.9.0", + "futures-lite", + "slab", +] + +[[package]] +name = "async-global-executor" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1b6f5d7df27bd294849f8eec66ecfc63d11814df7a4f5d74168a2394467b776" +dependencies = [ + "async-channel", + "async-executor", + "async-io", + "async-lock", + "blocking", + "futures-lite", + "once_cell", +] + [[package]] name = "async-io" version = "1.13.0" @@ -63,22 +113,55 @@ dependencies = [ [[package]] name = "async-lock" -version = "2.7.0" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa24f727524730b077666307f2734b4a1a1c57acb79193127dcc8914d5242dd7" +checksum = "287272293e9d8c41773cec55e365490fe034813a2f172f502d6ddcf75b2f582b" dependencies = [ "event-listener", ] +[[package]] +name = "async-std" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62565bb4402e926b29953c785397c6dc0391b7b446e45008b0049eb43cec6f5d" +dependencies = [ + "async-attributes", + "async-channel", + "async-global-executor", + "async-io", + "async-lock", + "crossbeam-utils 0.8.16", + "futures-channel", + "futures-core", + "futures-io", + "futures-lite", + "gloo-timers", + "kv-log-macro", + "log", + "memchr", + "once_cell", + "pin-project-lite", + "pin-utils", + "slab", + "wasm-bindgen-futures", +] + +[[package]] +name = "async-task" +version = "4.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc7ab41815b3c653ccd2978ec3255c81349336702dfdf62ee6f7069b12a3aae" + [[package]] name = "async-trait" -version = "0.1.72" +version = "0.1.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc6dde6e4ed435a4c1ee4e73592f5ba9da2151af10076cc04858746af9352d09" +checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.28", ] [[package]] @@ -133,9 +216,24 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.3.3" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42" +checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" + +[[package]] +name = "blocking" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77231a1c8f801696fc0123ec6150ce92cffb8e164a02afb9c8ddee0e9b65ad65" +dependencies = [ + "async-channel", + "async-lock", + "async-task", + "atomic-waker", + "fastrand 1.9.0", + "futures-lite", + "log", +] [[package]] name = "bumpalo" @@ -362,6 +460,15 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764" +[[package]] +name = "futures-channel" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" +dependencies = [ + "futures-core", +] + [[package]] name = "futures-core" version = "0.3.28" @@ -397,7 +504,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.28", ] [[package]] @@ -443,6 +550,18 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" +[[package]] +name = "gloo-timers" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b995a66bb87bebce9a0f4a95aed01daca4872c050bfcb21653361c03bc35e5c" +dependencies = [ + "futures-channel", + "futures-core", + "js-sys", + "wasm-bindgen", +] + [[package]] name = "hashbrown" version = "0.12.3" @@ -543,6 +662,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "kv-log-macro" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" +dependencies = [ + "log", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -579,9 +707,12 @@ dependencies = [ [[package]] name = "log" -version = "0.4.19" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +dependencies = [ + "value-bag", +] [[package]] name = "mach" @@ -788,6 +919,7 @@ version = "0.10.0" dependencies = [ "anyhow", "async-io", + "async-std", "async-trait", "clap", "crossbeam-channel", @@ -870,9 +1002,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c516611246607d0c04186886dbb3a754368ef82c79e9827a802c6d836dd111c" +checksum = "12cc1b0bf1727a77a54b6654e7b5f1af8604923edc8b81885f8ec92f9e3f0a05" [[package]] name = "pin-utils" @@ -1053,11 +1185,11 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.7" +version = "0.38.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "172891ebdceb05aa0005f533a6cbfca599ddd7d966f6f5d4d9b2e70478e70399" +checksum = "19ed4fa021d81c8392ce04db050a3da9a60299050b7ae1cf482d862b54a7218f" dependencies = [ - "bitflags 2.3.3", + "bitflags 2.4.0", "errno", "libc", "linux-raw-sys 0.4.5", @@ -1126,7 +1258,7 @@ checksum = "aafe972d60b0b9bee71a91b92fee2d4fb3c9d7e8f6b179aa99f27203d99a4816" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.28", ] [[package]] @@ -1208,6 +1340,17 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "syn" version = "2.0.28" @@ -1234,7 +1377,7 @@ dependencies = [ "cfg-if 1.0.0", "fastrand 2.0.0", "redox_syscall", - "rustix 0.38.7", + "rustix 0.38.8", "windows-sys", ] @@ -1270,16 +1413,15 @@ checksum = "090198534930841fab3a5d1bb637cde49e339654e606195f8d9c76eeb081dc96" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.28", ] [[package]] name = "tokio" -version = "1.29.1" +version = "1.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "532826ff75199d5833b9d2c5fe410f29235e25704ee5f0ef599fb51c21f4a4da" +checksum = "2d3ce25f50619af8b0aec2eb23deebe84249e19e2ddd393a6e16e3300a6dadfd" dependencies = [ - "autocfg", "backtrace", "num_cpus", "pin-project-lite", @@ -1294,7 +1436,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.28", ] [[package]] @@ -1331,6 +1473,12 @@ dependencies = [ "getrandom", ] +[[package]] +name = "value-bag" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d92ccd67fb88503048c01b59152a04effd0782d035a83a6d256ce6085f08f4a3" + [[package]] name = "version_check" version = "0.9.4" @@ -1386,10 +1534,22 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 2.0.28", "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c02dbc21516f9f1f04f187958890d7e6026df8d16540b7ad9492bc34a67cea03" +dependencies = [ + "cfg-if 1.0.0", + "js-sys", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "wasm-bindgen-macro" version = "0.2.87" @@ -1408,7 +1568,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.28", "wasm-bindgen-backend", "wasm-bindgen-shared", ] diff --git a/Cargo.toml b/Cargo.toml index 2c3e7b1..1a68b30 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,18 +6,21 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] -default = ["moka-v012"] +default = ["moka-v012", "rt-tokio"] -moka-v012 = ["moka012"] -moka-v011 = ["moka011"] -moka-v010 = ["moka010"] -moka-v09 = ["moka09"] -moka-v08 = ["moka08"] +moka-v012 = ["dep:moka012"] +moka-v011 = ["dep:moka011"] +moka-v010 = ["dep:moka010"] +moka-v09 = ["dep:moka09"] +moka-v08 = ["dep:moka08"] hashlink = ["dep:hashlink"] mini-moka = ["dep:mini-moka"] quick_cache = ["dep:quick_cache"] stretto = ["dep:stretto"] +rt-tokio = ["dep:tokio"] +rt-async-std = ["dep:async-std"] + [dependencies] anyhow = "1.0.56" async-io = "1.12.0" @@ -31,7 +34,8 @@ thiserror = "1.0.38" xxhash-rust = { version = "0.8.6", features = ["xxh3"] } # Async Runtime -tokio = { version = "1.25.0", features = ["rt-multi-thread", "macros" ] } +tokio = { optional = true, version = "1.25.0", features = ["rt-multi-thread", "macros" ] } +async-std = { optional = true, version = "1.12.0", features = ["attributes"] } # Cache implementations hashlink = { optional = true, version = "0.8.1" } diff --git a/README.md b/README.md index 7c152f0..934c5cc 100644 --- a/README.md +++ b/README.md @@ -45,12 +45,15 @@ For example: $ cargo build --release -F mini-moka,quick_cache ## Disable the latest version of Moka, but enable v0.9.x. -$ cargo build --release --no-default-features -F moka-v09 +$ cargo build --release --no-default-features -F moka-v09,rt-tokio ``` +**Features to select cache products:** + | Feature | Enabled Cache Product | |:--------------|:----------------------| -| `moka-v010` | [Moka](https://crates.io/crates/moka) v0.11.x (Enabled by default) | +| `moka-v012` | [Moka](https://crates.io/crates/moka) v0.12.x (Enabled by default) | +| `moka-v011` | Moka v0.11.x | | `moka-v010` | Moka v0.10.x | | `moka-v09` | Moka v0.9.x | | `moka-v08` | Moka v0.8.x | @@ -59,10 +62,18 @@ $ cargo build --release --no-default-features -F moka-v09 | `quick_cache` | [quick_cache](https://crates.io/crates/quick_cache) | | `stretto` | [Stretto](https://crates.io/crates/stretto) | +**Features to select async runtime:** + +| Feature | Enabled Cache Product | +|:---------------|:----------------------| +| `rt-tokio` | [Tokio](https://crates.io/crates/tokio) (Enabled by default) | +| `rt-async-std` | [async-std](https://crates.io/crates/async-std) | + NOTES: -- `moka-v011` is enabled by default. -- `moka-v011`, `moka-v010`, `moka-v09` and `moka-v08` are mutually exclusive. +- `moka-v012` and `rt-tokio` are enabled by default. +- `moka-v012`, `moka-v011`, `moka-v010`, `moka-v09` and `moka-v08` are mutually + exclusive. - `mini-moka` cannot be enabled when `moka-v09` or `moka-v08` is enabled. diff --git a/src/async_rt_helper.rs b/src/async_rt_helper.rs new file mode 100644 index 0000000..2f1b85c --- /dev/null +++ b/src/async_rt_helper.rs @@ -0,0 +1,57 @@ +#[cfg(all( + feature = "rt-tokio", + feature = "rt-async-std" +))] +compile_error!( + "You cannot enable both `rt-tokio` and `rt-async-std` features at the same time." +); + +#[cfg(all( + not(feature = "rt-tokio"), + not(feature = "rt-async-std") +))] +compile_error!( + "You must enable one of the `rt-tokio` and `rt-async-std` features." +); + +#[cfg(feature = "rt-tokio")] +use rt_tokio as rt; + +#[cfg(feature = "rt-async-std")] +use rt_async_std as rt; + +pub(crate) use rt::{spawn, yield_now}; + +#[cfg(feature = "rt-tokio")] +mod rt_tokio { + use std::future::Future; + use tokio::task::JoinHandle; + + pub(crate) fn spawn(future: T) -> JoinHandle where + T: Future + Send + 'static, + T::Output: Send + 'static, + { + tokio::spawn(future) + } + + pub(crate) async fn yield_now() { + tokio::task::yield_now().await; + } +} + +#[cfg(feature = "rt-async-std")] +mod rt_async_std { + use std::future::Future; + use async_std::task::JoinHandle; + + pub(crate) fn spawn(future: F) -> JoinHandle where + F: Future + Send + 'static, + T: Send + 'static, + { + async_std::task::spawn(future) + } + + pub(crate) async fn yield_now() { + async_std::task::yield_now().await; + } +} diff --git a/src/cache/moka_driver/async_cache.rs b/src/cache/moka_driver/async_cache.rs index ca453ba..206b48c 100644 --- a/src/cache/moka_driver/async_cache.rs +++ b/src/cache/moka_driver/async_cache.rs @@ -2,6 +2,7 @@ use super::{AsyncGetOrInsertOnce, InitClosureError1, InitClosureError2, InitClos use crate::cache::{Key, Value}; use crate::moka::future::Cache; use crate::{ + async_rt_helper as rt, cache::{self, AsyncCacheDriver, Counters, DefaultHasher}, config::Config, parser::TraceEntry, @@ -253,7 +254,7 @@ where count += 1; if count % 500 == 0 { - tokio::task::yield_now().await; + rt::yield_now().await; } } } diff --git a/src/lib.rs b/src/lib.rs index b4f2282..19ed570 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -31,6 +31,7 @@ pub(crate) use moka09 as moka; #[cfg(feature = "moka-v08")] pub(crate) use moka08 as moka; +mod async_rt_helper; mod cache; pub mod config; mod eviction_counters; @@ -43,6 +44,7 @@ pub(crate) use eviction_counters::EvictionCounters; pub use report::Report; pub use trace_file::TraceFile; +use async_rt_helper as rt; use cache::{ moka_driver::{ async_cache::MokaAsyncCache, sync_cache::MokaSyncCache, sync_segmented::MokaSegmentedCache, @@ -339,7 +341,7 @@ async fn run_multi_tasks( let ch = receive.clone(); let rb = Arc::clone(&report_builder); - tokio::task::spawn(async move { + rt::spawn(async move { let mut report = rb.build(); while let Ok(commands) = ch.recv() { cache::process_commands_async(commands, &mut cache, &mut report).await; @@ -356,9 +358,14 @@ async fn run_multi_tasks( // Merge the reports into one. let mut report = report_builder.build(); report.duration = Some(elapsed); - reports - .iter() - .for_each(|r| report.merge(r.as_ref().expect("Failed"))); + + for r in reports { + #[cfg(feature = "rt-tokio")] + report.merge(&r.expect("Failed")); + + #[cfg(feature = "rt-async-std")] + report.merge(&r); + } if config.is_eviction_listener_enabled() { report.add_eviction_counts(cache_driver.eviction_counters().as_ref().unwrap()); diff --git a/src/main.rs b/src/main.rs index 6544dcd..7750c9a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,9 +7,23 @@ use mokabench::{ use clap::{Arg, Command}; +#[cfg(feature = "rt-tokio")] #[tokio::main] async fn main() -> anyhow::Result<()> { + run("Tokio").await +} + +#[cfg(feature = "rt-async-std")] +#[async_std::main] +async fn main() -> anyhow::Result<()> { + run("async-std").await +} + +async fn run(async_rt_name: &str) -> anyhow::Result<()> { let (trace_files, mut config) = create_config()?; + + println!("Async runtime: {async_rt_name}"); + for trace_file in trace_files { config.trace_file = trace_file; println!("{config:?}"); From c0dff80b8a338cec0e9ea721a44d442d517776f7 Mon Sep 17 00:00:00 2001 From: Tatsuya Kawano Date: Sun, 20 Aug 2023 23:46:34 +0800 Subject: [PATCH 4/8] Update moka async driver for a recent eviction listener change --- Cargo.lock | 82 ++++++++++++++-------------- src/cache/moka_driver/async_cache.rs | 3 - 2 files changed, 41 insertions(+), 44 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4db1c24..494ea18 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -37,9 +37,9 @@ checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" [[package]] name = "anyhow" -version = "1.0.72" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b13c32d80ecc7ab747b80c3784bce54ee8a7a0cc4fbda9bf4cda2cf6fe90854" +checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" [[package]] name = "async-attributes" @@ -161,7 +161,7 @@ checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.29", ] [[package]] @@ -504,7 +504,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.29", ] [[package]] @@ -764,9 +764,9 @@ dependencies = [ [[package]] name = "mini-moka" -version = "0.10.1" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "452ebc1428a585e31e637b928b76355ef2fd72d765b2530d72fe475e514cd1eb" +checksum = "23e0b72e7c9042467008b10279fc732326bd605459ae03bda88825909dd19b56" dependencies = [ "crossbeam-channel", "crossbeam-utils 0.8.16", @@ -1099,9 +1099,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.32" +version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f3b39ccfb720540debaa0164757101c08ecb8d326b15358ce76a62c7e85965" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" dependencies = [ "proc-macro2", ] @@ -1258,14 +1258,14 @@ checksum = "aafe972d60b0b9bee71a91b92fee2d4fb3c9d7e8f6b179aa99f27203d99a4816" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.29", ] [[package]] name = "serde_json" -version = "1.0.104" +version = "1.0.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "076066c5f1078eac5b722a31827a8832fe108bed65dfa75e233c89f8206e976c" +checksum = "693151e1ac27563d6dbcec9dee9fbd5da8539b20fa14ad3752b2e6d363ace360" dependencies = [ "itoa", "ryu", @@ -1353,9 +1353,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.28" +version = "2.0.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04361975b3f5e348b2189d8dc55bc942f278b2d482a6a0365de5bdd62d351567" +checksum = "c324c494eba9d92503e6f1ef2e6df781e78f6a7705a0202d9801b198807d518a" dependencies = [ "proc-macro2", "quote", @@ -1370,9 +1370,9 @@ checksum = "7b2093cf4c8eb1e67749a6762251bc9cd836b6fc171623bd0a9d324d37af2417" [[package]] name = "tempfile" -version = "3.7.1" +version = "3.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc02fddf48964c42031a0b3fe0428320ecf3a73c401040fc0096f97794310651" +checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" dependencies = [ "cfg-if 1.0.0", "fastrand 2.0.0", @@ -1398,29 +1398,29 @@ checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" [[package]] name = "thiserror" -version = "1.0.44" +version = "1.0.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "611040a08a0439f8248d1990b111c95baa9c704c805fa1f62104b39655fd7f90" +checksum = "97a802ec30afc17eee47b2855fc72e0c4cd62be9b4efe6591edde0ec5bd68d8f" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.44" +version = "1.0.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "090198534930841fab3a5d1bb637cde49e339654e606195f8d9c76eeb081dc96" +checksum = "6bb623b56e39ab7dcd4b1b98bb6c8f8d907ed255b18de254088016b27a8ee19b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.29", ] [[package]] name = "tokio" -version = "1.30.0" +version = "1.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d3ce25f50619af8b0aec2eb23deebe84249e19e2ddd393a6e16e3300a6dadfd" +checksum = "17ed6077ed6cd6c74735e21f37eb16dc3935f96878b1fe961074089cc80893f9" dependencies = [ "backtrace", "num_cpus", @@ -1436,7 +1436,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.29", ] [[package]] @@ -1534,7 +1534,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.29", "wasm-bindgen-shared", ] @@ -1568,7 +1568,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.29", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1642,9 +1642,9 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.48.1" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", @@ -1657,45 +1657,45 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_msvc" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_i686_gnu" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_msvc" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_x86_64_gnu" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnullvm" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_msvc" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "xxhash-rust" diff --git a/src/cache/moka_driver/async_cache.rs b/src/cache/moka_driver/async_cache.rs index 206b48c..afb2e0c 100644 --- a/src/cache/moka_driver/async_cache.rs +++ b/src/cache/moka_driver/async_cache.rs @@ -130,15 +130,12 @@ impl MokaAsyncCache { #[cfg(feature = "moka-v012")] { - use crate::moka::future::FutureExt; - if config.is_eviction_listener_enabled() { let c0 = Arc::new(EvictionCounters::default()); let c1 = Arc::clone(&c0); builder = builder.eviction_listener(move |_k, _v, cause| { c1.increment(cause); - async {}.boxed() }); eviction_counters = Some(c0); From 35618a574bd3989e44bbc0198897caeb7fa2141b Mon Sep 17 00:00:00 2001 From: Tatsuya Kawano Date: Sun, 1 Oct 2023 19:53:10 +0800 Subject: [PATCH 5/8] Update moka sync drivers for a recent eviction listener change Also added `yield_now` calls in moka async cache test. --- Cargo.lock | 238 ++++++----- Cargo.toml | 9 +- src/cache/moka_driver.rs | 32 ++ .../async_cache.rs | 36 +- .../sync_cache.rs | 6 +- .../sync_segmented.rs | 6 +- src/cache/moka_driver_v2/async_cache.rs | 390 ++++++++++++++++++ src/cache/moka_driver_v2/sync_cache.rs | 364 ++++++++++++++++ src/cache/moka_driver_v2/sync_segmented.rs | 375 +++++++++++++++++ src/lib.rs | 5 + src/main.rs | 52 +-- 11 files changed, 1344 insertions(+), 169 deletions(-) rename src/cache/{moka_driver => moka_driver_v1}/async_cache.rs (92%) rename src/cache/{moka_driver => moka_driver_v1}/sync_cache.rs (98%) rename src/cache/{moka_driver => moka_driver_v1}/sync_segmented.rs (98%) create mode 100644 src/cache/moka_driver_v2/async_cache.rs create mode 100644 src/cache/moka_driver_v2/sync_cache.rs create mode 100644 src/cache/moka_driver_v2/sync_segmented.rs diff --git a/Cargo.lock b/Cargo.lock index 494ea18..7239d85 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "addr2line" -version = "0.20.0" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4fa78e18c64fce05e902adecd7a5eed15a5e0a3439f7b0e169f0252214865e3" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" dependencies = [ "gimli", ] @@ -64,14 +64,14 @@ dependencies = [ [[package]] name = "async-executor" -version = "1.5.1" +version = "1.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fa3dc5f2a8564f07759c008b9109dc0d39de92a88d5588b8a5036d286383afb" +checksum = "2c1da3ae8dabd9c00f453a329dfe1fb28da3c0a72e2478cdcd93171740c20499" dependencies = [ "async-lock", "async-task", "concurrent-queue", - "fastrand 1.9.0", + "fastrand 2.0.1", "futures-lite", "slab", ] @@ -105,7 +105,7 @@ dependencies = [ "log", "parking", "polling", - "rustix 0.37.23", + "rustix 0.37.24", "slab", "socket2", "waker-fn", @@ -149,9 +149,9 @@ dependencies = [ [[package]] name = "async-task" -version = "4.4.0" +version = "4.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecc7ab41815b3c653ccd2978ec3255c81349336702dfdf62ee6f7069b12a3aae" +checksum = "b9441c6b2fe128a7c2bf680a44c34d0df31ce09e5b7e401fcca3faa483dbc921" [[package]] name = "async-trait" @@ -161,7 +161,7 @@ checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.37", ] [[package]] @@ -172,9 +172,9 @@ checksum = "c59bdb34bc650a32731b31bd8f0829cc15d24a708ee31559e0bb34f2bc320cba" [[package]] name = "atomic-waker" -version = "1.1.1" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1181e1e0d1fce796a03db1ae795d67167da795f9cf4a39c37589e85ef57f26d3" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" [[package]] name = "atty" @@ -195,9 +195,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "backtrace" -version = "0.3.68" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4319208da049c43661739c5fade2ba182f09d1dc2299b32298d3a31692b17e12" +checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" dependencies = [ "addr2line", "cc", @@ -222,24 +222,25 @@ checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" [[package]] name = "blocking" -version = "1.3.1" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77231a1c8f801696fc0123ec6150ce92cffb8e164a02afb9c8ddee0e9b65ad65" +checksum = "94c4ef1f913d78636d78d538eec1f18de81e481f44b1be0a81060090530846e1" dependencies = [ "async-channel", "async-lock", "async-task", - "atomic-waker", - "fastrand 1.9.0", + "fastrand 2.0.1", + "futures-io", "futures-lite", - "log", + "piper", + "tracing", ] [[package]] name = "bumpalo" -version = "3.13.0" +version = "3.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" +checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" [[package]] name = "bytecount" @@ -280,9 +281,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.82" +version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "305fe645edc1442a0fa8b6726ba61d422798d37a52e12eaecf4b022ebbb88f01" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" dependencies = [ "libc", ] @@ -325,9 +326,9 @@ dependencies = [ [[package]] name = "concurrent-queue" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62ec6771ecfa0762d24683ee5a32ad78487a3d3afdc0fb8cae19d2c5deb50b7c" +checksum = "f057a694a54f12365049b0958a1685bb52d567f5593b355fbf685838e873d400" dependencies = [ "crossbeam-utils 0.8.16", ] @@ -392,12 +393,12 @@ dependencies = [ [[package]] name = "dashmap" -version = "5.5.0" +version = "5.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6943ae99c34386c84a470c499d3414f66502a41340aa895406e0d2e4a207b91d" +checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" dependencies = [ "cfg-if 1.0.0", - "hashbrown 0.14.0", + "hashbrown 0.14.1", "lock_api", "once_cell", "parking_lot_core", @@ -411,9 +412,9 @@ checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] name = "errno" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b30f669a7961ef1631673d2766cc92f52d64f7ef354d4fe0ddfd30ed52f0f4f" +checksum = "136526188508e25c6fef639d7927dfb3e0e3084488bf202267829cf7fc23dbdd" dependencies = [ "errno-dragonfly", "libc", @@ -456,9 +457,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764" +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" [[package]] name = "futures-channel" @@ -504,7 +505,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.37", ] [[package]] @@ -540,9 +541,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.27.3" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e" +checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" [[package]] name = "glob" @@ -576,9 +577,9 @@ checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" [[package]] name = "hashbrown" -version = "0.14.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" +checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" dependencies = [ "ahash", "allocator-api2", @@ -586,11 +587,11 @@ dependencies = [ [[package]] name = "hashlink" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "312f66718a2d7789ffef4f4b7b213138ed9f1eb3aa1d0d82fc99f88fb3ffd26f" +checksum = "e8094feaf31ff591f651a2664fb9cfd92bba7a60ce3197265e9482ebe753c8f7" dependencies = [ - "hashbrown 0.14.0", + "hashbrown 0.14.1", ] [[package]] @@ -604,9 +605,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" +checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" [[package]] name = "indexmap" @@ -633,7 +634,7 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" dependencies = [ - "hermit-abi 0.3.2", + "hermit-abi 0.3.3", "libc", "windows-sys", ] @@ -679,9 +680,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.147" +version = "0.2.148" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" +checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b" [[package]] name = "linux-raw-sys" @@ -691,9 +692,9 @@ checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" [[package]] name = "linux-raw-sys" -version = "0.4.5" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57bcfdad1b858c2db7c38303a6d2ad4dfaf5eb53dfeb0910128b2c26d6158503" +checksum = "3852614a3bd9ca9804678ba6be5e3b8ce76dfc902cae004e3e0c44051b6e88db" [[package]] name = "lock_api" @@ -740,9 +741,9 @@ checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" [[package]] name = "memchr" -version = "2.5.0" +version = "2.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c" [[package]] name = "memoffset" @@ -892,7 +893,9 @@ dependencies = [ [[package]] name = "moka" -version = "0.12.0-beta.1" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8dc65d4615c08c8a13d91fd404b5a2a4485ba35b4091e3315cf8798d280c2f29" dependencies = [ "async-lock", "async-trait", @@ -904,7 +907,6 @@ dependencies = [ "parking_lot", "quanta 0.11.1", "rustc_version", - "scheduled-thread-pool", "skeptic", "smallvec", "tagptr", @@ -929,7 +931,7 @@ dependencies = [ "mini-moka", "moka 0.10.4", "moka 0.11.3", - "moka 0.12.0-beta.1", + "moka 0.12.0", "moka 0.8.6", "moka 0.9.9", "parking_lot", @@ -946,15 +948,15 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi 0.3.2", + "hermit-abi 0.3.3", "libc", ] [[package]] name = "object" -version = "0.31.1" +version = "0.32.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bda667d9f2b5051b8833f59f3bf748b28ef54f850f4fcb389a252aa383866d1" +checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" dependencies = [ "memchr", ] @@ -973,9 +975,9 @@ checksum = "4d5d9eb14b174ee9aa2ef96dc2b94637a2d4b6e7cb873c7e171f0c20c6cf3eac" [[package]] name = "parking" -version = "2.1.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14f2252c834a40ed9bb5422029649578e63aa341ac401f74e719dd1afda8394e" +checksum = "e52c774a4c39359c1d1c52e43f73dd91a75a614652c825408eec30c95a9b2067" [[package]] name = "parking_lot" @@ -1002,9 +1004,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.12" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12cc1b0bf1727a77a54b6654e7b5f1af8604923edc8b81885f8ec92f9e3f0a05" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" [[package]] name = "pin-utils" @@ -1012,6 +1014,17 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "piper" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "668d31b1c4eba19242f2088b2bf3316b82ca31082a8335764db4e083db7485d4" +dependencies = [ + "atomic-waker", + "fastrand 2.0.1", + "futures-io", +] + [[package]] name = "polling" version = "2.8.0" @@ -1036,9 +1049,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.66" +version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328" dependencies = [ "unicode-ident", ] @@ -1171,9 +1184,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.37.23" +version = "0.37.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d69718bf81c6127a49dc64e44a742e8bb9213c0ff8869a22c308f84c1d4ab06" +checksum = "4279d76516df406a8bd37e7dff53fd37d1a093f997a3c34a5c21658c126db06d" dependencies = [ "bitflags 1.3.2", "errno", @@ -1185,14 +1198,14 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.8" +version = "0.38.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19ed4fa021d81c8392ce04db050a3da9a60299050b7ae1cf482d862b54a7218f" +checksum = "d2f9da0cbd88f9f09e7814e388301c8414c51c62aa6ce1e4b5c551d49d96e531" dependencies = [ "bitflags 2.4.0", "errno", "libc", - "linux-raw-sys 0.4.5", + "linux-raw-sys 0.4.8", "windows-sys", ] @@ -1234,38 +1247,38 @@ checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" [[package]] name = "semver" -version = "1.0.18" +version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" +checksum = "ad977052201c6de01a8ef2aa3378c4bd23217a056337d1d6da40468d267a4fb0" dependencies = [ "serde", ] [[package]] name = "serde" -version = "1.0.183" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32ac8da02677876d532745a130fc9d8e6edfa81a269b107c5b00829b91d8eb3c" +checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.183" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aafe972d60b0b9bee71a91b92fee2d4fb3c9d7e8f6b179aa99f27203d99a4816" +checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.37", ] [[package]] name = "serde_json" -version = "1.0.105" +version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "693151e1ac27563d6dbcec9dee9fbd5da8539b20fa14ad3752b2e6d363ace360" +checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" dependencies = [ "itoa", "ryu", @@ -1289,18 +1302,18 @@ dependencies = [ [[package]] name = "slab" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" dependencies = [ "autocfg", ] [[package]] name = "smallvec" -version = "1.11.0" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" +checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" [[package]] name = "socket2" @@ -1353,9 +1366,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.29" +version = "2.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c324c494eba9d92503e6f1ef2e6df781e78f6a7705a0202d9801b198807d518a" +checksum = "7303ef2c05cd654186cb250d29049a24840ca25d2747c25c0381c8d9e2f582e8" dependencies = [ "proc-macro2", "quote", @@ -1375,17 +1388,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" dependencies = [ "cfg-if 1.0.0", - "fastrand 2.0.0", + "fastrand 2.0.1", "redox_syscall", - "rustix 0.38.8", + "rustix 0.38.15", "windows-sys", ] [[package]] name = "termcolor" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" +checksum = "6093bad37da69aab9d123a8091e4be0aa4a03e4d601ec641c327398315f62b64" dependencies = [ "winapi-util", ] @@ -1398,22 +1411,22 @@ checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" [[package]] name = "thiserror" -version = "1.0.47" +version = "1.0.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97a802ec30afc17eee47b2855fc72e0c4cd62be9b4efe6591edde0ec5bd68d8f" +checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.47" +version = "1.0.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bb623b56e39ab7dcd4b1b98bb6c8f8d907ed255b18de254088016b27a8ee19b" +checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.37", ] [[package]] @@ -1436,9 +1449,26 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.37", +] + +[[package]] +name = "tracing" +version = "0.1.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +dependencies = [ + "cfg-if 1.0.0", + "pin-project-lite", + "tracing-core", ] +[[package]] +name = "tracing-core" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" + [[package]] name = "triomphe" version = "0.1.9" @@ -1451,18 +1481,18 @@ dependencies = [ [[package]] name = "unicase" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" dependencies = [ "version_check", ] [[package]] name = "unicode-ident" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "uuid" @@ -1487,15 +1517,15 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "waker-fn" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" +checksum = "f3c4517f54858c779bbcbf228f4fca63d121bf85fbecb2dc578cdf4a39395690" [[package]] name = "walkdir" -version = "2.3.3" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36df944cda56c7d8d8b7496af378e6b16de9284591917d307c9b4d313c44e698" +checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee" dependencies = [ "same-file", "winapi-util", @@ -1534,7 +1564,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.37", "wasm-bindgen-shared", ] @@ -1568,7 +1598,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.37", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1618,9 +1648,9 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" dependencies = [ "winapi", ] @@ -1699,6 +1729,6 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "xxhash-rust" -version = "0.8.6" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "735a71d46c4d68d71d4b24d03fdc2b98e38cea81730595801db779c04fe80d70" +checksum = "9828b178da53440fa9c766a3d2f73f7cf5d0ac1fe3980c1e5018d899fd19e07b" diff --git a/Cargo.toml b/Cargo.toml index 1a68b30..56b7de1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,19 +46,16 @@ stretto = { optional = true, version = "0.7.1" } [dependencies.moka012] package = "moka" optional = true -# version = "0.12.0" +version = "0.12.0" # git = "https://github.com/moka-rs/moka" # branch = "main" -path = "../moka" -features = ["future"] +# path = "../moka" +features = ["future", "sync"] [dependencies.moka011] package = "moka" optional = true version = "0.11.3" -# git = "https://github.com/moka-rs/moka" -# branch = "main" -# path = "../moka" features = ["future"] [dependencies.moka010] diff --git a/src/cache/moka_driver.rs b/src/cache/moka_driver.rs index c1256f1..47d633a 100644 --- a/src/cache/moka_driver.rs +++ b/src/cache/moka_driver.rs @@ -3,8 +3,40 @@ use thiserror::Error; use crate::{parser::TraceEntry, Report}; +#[cfg_attr(feature = "moka-v012", path = "moka_driver_v2/async_cache.rs")] +#[cfg_attr( + any( + feature = "moka-v08", + feature = "moka-v09", + feature = "moka-v010", + feature = "moka-v011" + ), + path = "moka_driver_v1/async_cache.rs" +)] pub(crate) mod async_cache; + +#[cfg_attr(feature = "moka-v012", path = "moka_driver_v2/sync_cache.rs")] +#[cfg_attr( + any( + feature = "moka-v08", + feature = "moka-v09", + feature = "moka-v010", + feature = "moka-v011" + ), + path = "moka_driver_v1/sync_cache.rs" +)] pub(crate) mod sync_cache; + +#[cfg_attr(feature = "moka-v012", path = "moka_driver_v2/sync_segmented.rs")] +#[cfg_attr( + any( + feature = "moka-v08", + feature = "moka-v09", + feature = "moka-v010", + feature = "moka-v011" + ), + path = "moka_driver_v1/sync_segmented.rs" +)] pub(crate) mod sync_segmented; pub(crate) trait GetOrInsertOnce { diff --git a/src/cache/moka_driver/async_cache.rs b/src/cache/moka_driver_v1/async_cache.rs similarity index 92% rename from src/cache/moka_driver/async_cache.rs rename to src/cache/moka_driver_v1/async_cache.rs index afb2e0c..9fa401d 100644 --- a/src/cache/moka_driver/async_cache.rs +++ b/src/cache/moka_driver_v1/async_cache.rs @@ -1,3 +1,5 @@ +//! Driver for `moka::future::Cache` v0.11.x or earlier. + use super::{AsyncGetOrInsertOnce, InitClosureError1, InitClosureError2, InitClosureType}; use crate::cache::{Key, Value}; use crate::moka::future::Cache; @@ -124,29 +126,11 @@ impl MokaAsyncCache { #[cfg(feature = "moka-v08")] { - cache = builder.build_with_hasher(DefaultHasher); + cache = builder.build_with_hasher(DefaultHasher::default()); eviction_counters = None; } - #[cfg(feature = "moka-v012")] - { - if config.is_eviction_listener_enabled() { - let c0 = Arc::new(EvictionCounters::default()); - let c1 = Arc::clone(&c0); - - builder = builder.eviction_listener(move |_k, _v, cause| { - c1.increment(cause); - }); - - eviction_counters = Some(c0); - } else { - eviction_counters = None; - } - - cache = builder.build_with_hasher(DefaultHasher); - } - - #[cfg(any(feature = "moka-v011", feature = "moka-v010", feature = "moka-v09"))] + #[cfg(not(feature = "moka-v08"))] { if config.is_eviction_listener_enabled() { let c0 = Arc::new(EvictionCounters::default()); @@ -162,19 +146,13 @@ impl MokaAsyncCache { eviction_counters = None; } - cache = builder.build_with_hasher(DefaultHasher); + cache = builder.build_with_hasher(DefaultHasher::default()); } (cache, eviction_counters) } - #[cfg(feature = "moka-v012")] - async fn get(&self, key: usize) -> bool { - self.cache.get(&key).await.is_some() - } - - #[cfg(not(feature = "moka-v012"))] - async fn get(&self, key: usize) -> bool { + fn get(&self, key: usize) -> bool { self.cache.get(&key).is_some() } @@ -195,7 +173,7 @@ where let mut req_id = entry.line_number(); for block in entry.range() { - if self.get(block).await { + if self.get(block) { counters.read_hit(); } else { self.insert(block, req_id).await; diff --git a/src/cache/moka_driver/sync_cache.rs b/src/cache/moka_driver_v1/sync_cache.rs similarity index 98% rename from src/cache/moka_driver/sync_cache.rs rename to src/cache/moka_driver_v1/sync_cache.rs index 41ae3f2..63f2261 100644 --- a/src/cache/moka_driver/sync_cache.rs +++ b/src/cache/moka_driver_v1/sync_cache.rs @@ -1,3 +1,5 @@ +//! Driver for `moka::sync::Cache` v0.11.x or earlier. + use super::{GetOrInsertOnce, InitClosureError1, InitClosureError2, InitClosureType}; use crate::cache::{Key, Value}; use crate::moka::sync::Cache; @@ -122,7 +124,7 @@ impl MokaSyncCache { #[cfg(feature = "moka-v08")] { - cache = builder.build_with_hasher(DefaultHasher); + cache = builder.build_with_hasher(DefaultHasher::default()); eviction_counters = None; } @@ -155,7 +157,7 @@ impl MokaSyncCache { eviction_counters = None; } - cache = builder.build_with_hasher(DefaultHasher); + cache = builder.build_with_hasher(DefaultHasher::default()); } (cache, eviction_counters) diff --git a/src/cache/moka_driver/sync_segmented.rs b/src/cache/moka_driver_v1/sync_segmented.rs similarity index 98% rename from src/cache/moka_driver/sync_segmented.rs rename to src/cache/moka_driver_v1/sync_segmented.rs index deaddad..a3f205b 100644 --- a/src/cache/moka_driver/sync_segmented.rs +++ b/src/cache/moka_driver_v1/sync_segmented.rs @@ -1,3 +1,5 @@ +//! Driver for `moka::sync::SegmentedCache` v0.11.x or earlier. + use super::{GetOrInsertOnce, InitClosureError1, InitClosureError2, InitClosureType}; use crate::{ cache::{self, CacheDriver, Counters, DefaultHasher, Key, Value}, @@ -129,7 +131,7 @@ impl MokaSegmentedCache { #[cfg(feature = "moka-v08")] { - cache = builder.build_with_hasher(DefaultHasher); + cache = builder.build_with_hasher(DefaultHasher::default()); eviction_counters = None; } @@ -162,7 +164,7 @@ impl MokaSegmentedCache { eviction_counters = None; } - cache = builder.build_with_hasher(DefaultHasher); + cache = builder.build_with_hasher(DefaultHasher::default()); } (cache, eviction_counters) diff --git a/src/cache/moka_driver_v2/async_cache.rs b/src/cache/moka_driver_v2/async_cache.rs new file mode 100644 index 0000000..c698392 --- /dev/null +++ b/src/cache/moka_driver_v2/async_cache.rs @@ -0,0 +1,390 @@ +//! Driver for `moka::future::Cache` v0.12.0 or later. + +use super::{AsyncGetOrInsertOnce, InitClosureError1, InitClosureError2, InitClosureType}; +use crate::cache::{Key, Value}; +use crate::moka::future::Cache; +use crate::{ + async_rt_helper as rt, + cache::{self, AsyncCacheDriver, Counters, DefaultHasher}, + config::Config, + parser::TraceEntry, + report::Report, + EvictionCounters, +}; + +use async_trait::async_trait; +use std::sync::{ + atomic::{AtomicBool, Ordering}, + Arc, +}; + +pub struct MokaAsyncCache { + config: Arc, + cache: Cache, + insert_once_impl: I, + eviction_counters: Option>, +} + +impl Clone for MokaAsyncCache { + fn clone(&self) -> Self { + Self { + config: Arc::clone(&self.config), + cache: self.cache.clone(), + insert_once_impl: self.insert_once_impl.clone(), + eviction_counters: self.eviction_counters.as_ref().map(Arc::clone), + } + } +} + +impl MokaAsyncCache { + pub(crate) fn new(config: &Config, max_cap: u64, init_cap: usize) -> Self { + let (cache, eviction_counters) = Self::create_cache(config, max_cap, init_cap); + let config = Arc::new(config.clone()); + let insert_once_impl = GetWith { + cache: cache.clone(), + config: Arc::clone(&config), + }; + + Self { + config, + cache, + insert_once_impl, + eviction_counters, + } + } +} + +use entry_api::EntryOrInsertWith; + +impl MokaAsyncCache { + pub(crate) fn with_entry_api(config: &Config, max_cap: u64, init_cap: usize) -> Self { + let (cache, eviction_counters) = Self::create_cache(config, max_cap, init_cap); + let config = Arc::new(config.clone()); + let insert_once_impl = EntryOrInsertWith::new(cache.clone(), Arc::clone(&config)); + + Self { + config, + cache, + insert_once_impl, + eviction_counters, + } + } +} + +impl MokaAsyncCache { + fn create_cache( + config: &Config, + max_cap: u64, + init_cap: usize, + ) -> ( + Cache, + Option>, + ) { + let mut builder = Cache::builder() + .max_capacity(max_cap) + .initial_capacity(init_cap); + + if config.per_key_expiration { + use crate::cache::moka_driver::expiry::MokabenchExpiry; + let expiry = MokabenchExpiry::new(config.ttl, config.tti); + builder = builder.expire_after(expiry); + } + + if let Some(ttl) = config.ttl { + if !config.per_key_expiration { + builder = builder.time_to_live(ttl); + } + } + if let Some(tti) = config.tti { + if !config.per_key_expiration { + builder = builder.time_to_idle(tti) + } + } + + if config.invalidate_entries_if { + builder = builder.support_invalidation_closures(); + } + if config.size_aware { + builder = builder.weigher(|_k, (s, _v)| *s); + } + + let cache; + let eviction_counters; + + if config.is_eviction_listener_enabled() { + let c0 = Arc::new(EvictionCounters::default()); + let c1 = Arc::clone(&c0); + + builder = builder.eviction_listener(move |_k, _v, cause| { + c1.increment(cause); + }); + + eviction_counters = Some(c0); + } else { + eviction_counters = None; + } + + cache = builder.build_with_hasher(DefaultHasher); + + (cache, eviction_counters) + } + + async fn get(&self, key: usize) -> bool { + self.cache.get(&key).await.is_some() + } + + async fn insert(&self, key: usize, req_id: usize) { + let value = cache::make_value(&self.config, key, req_id); + cache::sleep_task_for_insertion(&self.config).await; + self.cache.insert(key, value).await; + } +} + +#[async_trait] +impl AsyncCacheDriver for MokaAsyncCache +where + I: AsyncGetOrInsertOnce + Send + Sync, +{ + async fn get_or_insert(&mut self, entry: &TraceEntry, report: &mut Report) { + let mut counters = Counters::default(); + let mut req_id = entry.line_number(); + + for block in entry.range() { + if self.get(block).await { + counters.read_hit(); + } else { + self.insert(block, req_id).await; + counters.inserted(); + counters.read_missed(); + } + req_id += 1; + } + + counters.add_to_report(report); + } + + async fn get_or_insert_once(&mut self, entry: &TraceEntry, report: &mut Report) { + self.insert_once_impl + .get_or_insert_once(entry, report) + .await; + } + + async fn update(&mut self, entry: &TraceEntry, report: &mut Report) { + let mut counters = Counters::default(); + let mut req_id = entry.line_number(); + + for block in entry.range() { + self.insert(block, req_id).await; + counters.inserted(); + req_id += 1; + } + + counters.add_to_report(report); + } + + async fn invalidate(&mut self, entry: &TraceEntry) { + for block in entry.range() { + self.cache.invalidate(&block).await; + } + } + + fn invalidate_all(&mut self) { + self.cache.invalidate_all(); + } + + fn invalidate_entries_if(&mut self, entry: &TraceEntry) { + for block in entry.range() { + self.cache + .invalidate_entries_if(move |_k, (_s, v)| v[0] == (block % 256) as u8) + .expect("invalidate_entries_if failed"); + } + } + + async fn iterate(&mut self) { + let mut count = 0usize; + for _kv in &self.cache { + count += 1; + + if count % 500 == 0 { + rt::yield_now().await; + } + } + } + + fn eviction_counters(&self) -> Option> { + self.eviction_counters.as_ref().map(Arc::clone) + } +} + +// +// GetWith (implements GetOrInsertOnce) +// +#[derive(Clone)] +pub(crate) struct GetWith { + cache: Cache, + config: Arc, +} + +#[async_trait] +impl AsyncGetOrInsertOnce for GetWith { + async fn get_or_insert_once(&self, entry: &TraceEntry, report: &mut Report) { + let mut counters = Counters::default(); + let mut req_id = entry.line_number(); + let is_inserted = Arc::new(AtomicBool::default()); + + for block in entry.range() { + { + let is_inserted2 = Arc::clone(&is_inserted); + match InitClosureType::select(block) { + InitClosureType::GetOrInsert => { + self.get_with(block, req_id, is_inserted2).await + } + ty => self.try_get_with(ty, block, req_id, is_inserted2).await, + } + } + + if is_inserted.load(Ordering::Acquire) { + counters.inserted(); + counters.read_missed(); + is_inserted.store(false, Ordering::Release); + } else { + counters.read_hit(); + } + req_id += 1; + } + + counters.add_to_report(report); + } +} + +impl GetWith { + async fn get_with(&self, key: usize, req_id: usize, is_inserted: Arc) { + self.cache + .get_with(key, async { + cache::sleep_task_for_insertion(&self.config).await; + is_inserted.store(true, Ordering::Release); + cache::make_value(&self.config, key, req_id) + }) + .await; + } + + async fn try_get_with( + &self, + ty: InitClosureType, + key: usize, + req_id: usize, + is_inserted: Arc, + ) { + match ty { + InitClosureType::GetOrTryInsertWithError1 => self + .cache + .try_get_with(key, async { + cache::sleep_task_for_insertion(&self.config).await; + is_inserted.store(true, Ordering::Release); + Ok(cache::make_value(&self.config, key, req_id)) as Result<_, InitClosureError1> + }) + .await + .is_ok(), + InitClosureType::GetOrTyyInsertWithError2 => self + .cache + .try_get_with(key, async { + cache::sleep_task_for_insertion(&self.config).await; + is_inserted.store(true, Ordering::Release); + Ok(cache::make_value(&self.config, key, req_id)) as Result<_, InitClosureError2> + }) + .await + .is_ok(), + _ => unreachable!(), + }; + } +} + +// +// EntryOrInsertWith (implements GetOrInsertOnce) +// +mod entry_api { + use super::*; + + #[derive(Clone)] + pub(crate) struct EntryOrInsertWith { + cache: Cache, + config: Arc, + } + + impl EntryOrInsertWith { + pub(crate) fn new(cache: Cache, config: Arc) -> Self { + Self { cache, config } + } + } + + #[async_trait] + impl AsyncGetOrInsertOnce for EntryOrInsertWith { + async fn get_or_insert_once(&self, entry: &TraceEntry, report: &mut Report) { + let mut counters = Counters::default(); + let mut req_id = entry.line_number(); + + for block in entry.range() { + let is_inserted = match InitClosureType::select(block) { + InitClosureType::GetOrInsert => self.entry_or_insert_with(block, req_id).await, + ty => self.entry_or_try_insert_with(ty, block, req_id).await, + }; + + if is_inserted { + counters.inserted(); + counters.read_missed(); + } else { + counters.read_hit(); + } + req_id += 1; + } + + counters.add_to_report(report); + } + } + + impl EntryOrInsertWith { + async fn entry_or_insert_with(&self, key: usize, req_id: usize) -> bool { + self.cache + .entry(key) + .or_insert_with(async { + cache::sleep_task_for_insertion(&self.config).await; + cache::make_value(&self.config, key, req_id) + }) + .await + .is_fresh() + } + + async fn entry_or_try_insert_with( + &self, + ty: InitClosureType, + key: usize, + req_id: usize, + ) -> bool { + match ty { + InitClosureType::GetOrTryInsertWithError1 => self + .cache + .entry(key) + .or_try_insert_with(async { + cache::sleep_task_for_insertion(&self.config).await; + Ok(cache::make_value(&self.config, key, req_id)) + as Result<_, InitClosureError1> + }) + .await + .unwrap() + .is_fresh(), + InitClosureType::GetOrTyyInsertWithError2 => self + .cache + .entry(key) + .or_try_insert_with(async { + cache::sleep_task_for_insertion(&self.config).await; + Ok(cache::make_value(&self.config, key, req_id)) + as Result<_, InitClosureError2> + }) + .await + .unwrap() + .is_fresh(), + _ => unreachable!(), + } + } + } +} diff --git a/src/cache/moka_driver_v2/sync_cache.rs b/src/cache/moka_driver_v2/sync_cache.rs new file mode 100644 index 0000000..92cafc6 --- /dev/null +++ b/src/cache/moka_driver_v2/sync_cache.rs @@ -0,0 +1,364 @@ +use super::{GetOrInsertOnce, InitClosureError1, InitClosureError2, InitClosureType}; +use crate::cache::{Key, Value}; +use crate::moka::sync::Cache; +use crate::{ + cache::{self, CacheDriver, Counters, DefaultHasher}, + config::Config, + parser::TraceEntry, + report::Report, + EvictionCounters, +}; + +use std::sync::{ + atomic::{AtomicBool, Ordering}, + Arc, +}; + +pub(crate) struct MokaSyncCache { + config: Arc, + cache: Cache, + insert_once_impl: I, + eviction_counters: Option>, +} + +impl Clone for MokaSyncCache { + fn clone(&self) -> Self { + Self { + config: Arc::clone(&self.config), + cache: self.cache.clone(), + insert_once_impl: self.insert_once_impl.clone(), + eviction_counters: self.eviction_counters.as_ref().map(Arc::clone), + } + } +} + +impl MokaSyncCache { + pub(crate) fn new(config: &Config, max_cap: u64, init_cap: usize) -> Self { + let (cache, eviction_counters) = Self::create_cache(config, max_cap, init_cap); + let config = Arc::new(config.clone()); + let insert_once_impl = GetWith { + cache: cache.clone(), + config: Arc::clone(&config), + }; + + Self { + config, + cache, + insert_once_impl, + eviction_counters, + } + } +} + +use entry_api::EntryOrInsertWith; + +impl MokaSyncCache { + pub(crate) fn with_entry_api(config: &Config, max_cap: u64, init_cap: usize) -> Self { + let (cache, eviction_counters) = Self::create_cache(config, max_cap, init_cap); + let config = Arc::new(config.clone()); + let insert_once_impl = EntryOrInsertWith::new(cache.clone(), Arc::clone(&config)); + + Self { + config, + cache, + insert_once_impl, + eviction_counters, + } + } +} + +impl MokaSyncCache { + fn create_cache( + config: &Config, + max_cap: u64, + init_cap: usize, + ) -> ( + Cache, + Option>, + ) { + let mut builder = Cache::builder() + .max_capacity(max_cap) + .initial_capacity(init_cap); + + if config.per_key_expiration { + use crate::cache::moka_driver::expiry::MokabenchExpiry; + let expiry = MokabenchExpiry::new(config.ttl, config.tti); + builder = builder.expire_after(expiry); + } + + if let Some(ttl) = config.ttl { + if !config.per_key_expiration { + builder = builder.time_to_live(ttl); + } + } + if let Some(tti) = config.tti { + if !config.per_key_expiration { + builder = builder.time_to_idle(tti) + } + } + + if config.invalidate_entries_if { + builder = builder.support_invalidation_closures(); + } + if config.size_aware { + builder = builder.weigher(|_k, (s, _v)| *s); + } + + let cache; + let eviction_counters; + + if config.is_eviction_listener_enabled() { + let c0 = Arc::new(EvictionCounters::default()); + let c1 = Arc::clone(&c0); + + builder = builder.eviction_listener(move |_k, _v, cause| { + c1.increment(cause); + }); + + eviction_counters = Some(c0); + } else { + eviction_counters = None; + } + + cache = builder.build_with_hasher(DefaultHasher); + + (cache, eviction_counters) + } + + fn get(&self, key: &usize) -> bool { + self.cache.get(key).is_some() + } + + fn insert(&self, key: usize, req_id: usize) { + let value = cache::make_value(&self.config, key, req_id); + cache::sleep_thread_for_insertion(&self.config); + self.cache.insert(key, value); + } +} + +impl CacheDriver for MokaSyncCache { + fn get_or_insert(&mut self, entry: &TraceEntry, report: &mut Report) { + let mut counters = Counters::default(); + let mut req_id = entry.line_number(); + + for block in entry.range() { + if self.get(&block) { + counters.read_hit(); + } else { + self.insert(block, req_id); + counters.inserted(); + counters.read_missed(); + } + req_id += 1; + } + + counters.add_to_report(report); + } + + fn get_or_insert_once(&mut self, entry: &TraceEntry, report: &mut Report) { + self.insert_once_impl.get_or_insert_once(entry, report); + } + + fn update(&mut self, entry: &TraceEntry, report: &mut Report) { + let mut counters = Counters::default(); + let mut req_id = entry.line_number(); + + for block in entry.range() { + self.insert(block, req_id); + counters.inserted(); + req_id += 1; + } + + counters.add_to_report(report); + } + + fn invalidate(&mut self, entry: &TraceEntry) { + for block in entry.range() { + self.cache.invalidate(&block); + } + } + + fn invalidate_all(&mut self) { + self.cache.invalidate_all(); + } + + fn invalidate_entries_if(&mut self, entry: &TraceEntry) { + for block in entry.range() { + self.cache + .invalidate_entries_if(move |_k, (_s, v)| v[0] == (block % 256) as u8) + .expect("invalidate_entries_if failed"); + } + } + + fn iterate(&mut self) { + let mut count = 0usize; + for _kv in &self.cache { + count += 1; + + if count % 500 == 0 { + std::thread::yield_now(); + } + } + } + + fn eviction_counters(&self) -> Option> { + self.eviction_counters.as_ref().map(Arc::clone) + } +} + +// +// GetWith (implements GetOrInsertOnce) +// +#[derive(Clone)] +pub(crate) struct GetWith { + cache: Cache, + config: Arc, +} + +impl GetOrInsertOnce for GetWith { + fn get_or_insert_once(&self, entry: &TraceEntry, report: &mut Report) { + let mut counters = Counters::default(); + let mut req_id = entry.line_number(); + let is_inserted = Arc::new(AtomicBool::default()); + + for block in entry.range() { + { + let is_inserted2 = Arc::clone(&is_inserted); + match InitClosureType::select(block) { + InitClosureType::GetOrInsert => self.get_with(block, req_id, is_inserted2), + ty => self.try_get_with(ty, block, req_id, is_inserted2), + } + } + + if is_inserted.load(Ordering::Acquire) { + counters.inserted(); + counters.read_missed(); + is_inserted.store(false, Ordering::Release); + } else { + counters.read_hit(); + } + req_id += 1; + } + + counters.add_to_report(report); + } +} + +impl GetWith { + fn get_with(&self, key: usize, req_id: usize, is_inserted: Arc) { + self.cache.get_with(key, || { + cache::sleep_thread_for_insertion(&self.config); + is_inserted.store(true, Ordering::Release); + cache::make_value(&self.config, key, req_id) + }); + } + + fn try_get_with( + &self, + ty: InitClosureType, + key: usize, + req_id: usize, + is_inserted: Arc, + ) { + match ty { + InitClosureType::GetOrTryInsertWithError1 => self + .cache + .try_get_with(key, || { + cache::sleep_thread_for_insertion(&self.config); + is_inserted.store(true, Ordering::Release); + Ok(cache::make_value(&self.config, key, req_id)) as Result<_, InitClosureError1> + }) + .is_ok(), + InitClosureType::GetOrTyyInsertWithError2 => self + .cache + .try_get_with(key, || { + cache::sleep_thread_for_insertion(&self.config); + is_inserted.store(true, Ordering::Release); + Ok(cache::make_value(&self.config, key, req_id)) as Result<_, InitClosureError2> + }) + .is_ok(), + _ => unreachable!(), + }; + } +} + +// +// EntryOrInsertWith (implements GetOrInsertOnce) +// +mod entry_api { + use super::*; + + #[derive(Clone)] + pub(crate) struct EntryOrInsertWith { + cache: Cache, + config: Arc, + } + + impl EntryOrInsertWith { + pub(crate) fn new(cache: Cache, config: Arc) -> Self { + Self { cache, config } + } + } + + impl GetOrInsertOnce for EntryOrInsertWith { + fn get_or_insert_once(&self, entry: &TraceEntry, report: &mut Report) { + let mut counters = Counters::default(); + let mut req_id = entry.line_number(); + + for block in entry.range() { + let is_inserted = match InitClosureType::select(block) { + InitClosureType::GetOrInsert => self.entry_or_insert_with(block, req_id), + ty => self.entry_or_try_insert_with(ty, block, req_id), + }; + + if is_inserted { + counters.inserted(); + counters.read_missed(); + } else { + counters.read_hit(); + } + req_id += 1; + } + + counters.add_to_report(report); + } + } + + impl EntryOrInsertWith { + fn entry_or_insert_with(&self, key: usize, req_id: usize) -> bool { + self.cache + .entry(key) + .or_insert_with(|| { + cache::sleep_thread_for_insertion(&self.config); + cache::make_value(&self.config, key, req_id) + }) + .is_fresh() + } + + fn entry_or_try_insert_with(&self, ty: InitClosureType, key: usize, req_id: usize) -> bool { + match ty { + InitClosureType::GetOrTryInsertWithError1 => self + .cache + .entry(key) + .or_try_insert_with(|| { + cache::sleep_thread_for_insertion(&self.config); + Ok(cache::make_value(&self.config, key, req_id)) + as Result<_, InitClosureError1> + }) + .unwrap() + .is_fresh(), + InitClosureType::GetOrTyyInsertWithError2 => self + .cache + .entry(key) + .or_try_insert_with(|| { + cache::sleep_thread_for_insertion(&self.config); + Ok(cache::make_value(&self.config, key, req_id)) + as Result<_, InitClosureError2> + }) + .unwrap() + .is_fresh(), + _ => unreachable!(), + } + } + } +} diff --git a/src/cache/moka_driver_v2/sync_segmented.rs b/src/cache/moka_driver_v2/sync_segmented.rs new file mode 100644 index 0000000..aa4fd0e --- /dev/null +++ b/src/cache/moka_driver_v2/sync_segmented.rs @@ -0,0 +1,375 @@ +use super::{GetOrInsertOnce, InitClosureError1, InitClosureError2, InitClosureType}; +use crate::{ + cache::{self, CacheDriver, Counters, DefaultHasher, Key, Value}, + config::Config, + moka::sync::SegmentedCache, + parser::TraceEntry, + report::Report, + EvictionCounters, +}; + +use std::sync::{ + atomic::{AtomicBool, Ordering}, + Arc, +}; + +pub(crate) struct MokaSegmentedCache { + config: Arc, + cache: SegmentedCache, + insert_once_impl: I, + eviction_counters: Option>, +} + +impl Clone for MokaSegmentedCache { + fn clone(&self) -> Self { + Self { + config: Arc::clone(&self.config), + cache: self.cache.clone(), + insert_once_impl: self.insert_once_impl.clone(), + eviction_counters: self.eviction_counters.as_ref().map(Arc::clone), + } + } +} + +impl MokaSegmentedCache { + pub(crate) fn new(config: &Config, max_cap: u64, init_cap: usize, num_segments: usize) -> Self { + let (cache, eviction_counters) = + Self::create_cache(config, max_cap, init_cap, num_segments); + let config = Arc::new(config.clone()); + let insert_once_impl = GetWith { + cache: cache.clone(), + config: Arc::clone(&config), + }; + + Self { + config, + cache, + insert_once_impl, + eviction_counters, + } + } +} + +use entry_api::EntryOrInsertWith; + +impl MokaSegmentedCache { + pub(crate) fn with_entry_api( + config: &Config, + max_cap: u64, + init_cap: usize, + num_segments: usize, + ) -> Self { + let (cache, eviction_counters) = + Self::create_cache(config, max_cap, init_cap, num_segments); + let config = Arc::new(config.clone()); + let insert_once_impl = EntryOrInsertWith::new(cache.clone(), Arc::clone(&config)); + + Self { + config, + cache, + insert_once_impl, + eviction_counters, + } + } +} + +impl MokaSegmentedCache { + fn create_cache( + config: &Config, + max_cap: u64, + init_cap: usize, + num_segments: usize, + ) -> ( + SegmentedCache, + Option>, + ) { + let mut builder = SegmentedCache::builder(num_segments) + .max_capacity(max_cap) + .initial_capacity(init_cap); + + if config.per_key_expiration { + use crate::cache::moka_driver::expiry::MokabenchExpiry; + let expiry = MokabenchExpiry::new(config.ttl, config.tti); + builder = builder.expire_after(expiry); + } + + if let Some(ttl) = config.ttl { + if !config.per_key_expiration { + builder = builder.time_to_live(ttl); + } + } + if let Some(tti) = config.tti { + if !config.per_key_expiration { + builder = builder.time_to_idle(tti) + } + } + + if config.invalidate_entries_if { + builder = builder.support_invalidation_closures(); + } + if config.size_aware { + builder = builder.weigher(|_k, (s, _v)| *s); + } + + let cache; + let eviction_counters; + + if config.is_eviction_listener_enabled() { + let c0 = Arc::new(EvictionCounters::default()); + let c1 = Arc::clone(&c0); + + builder = builder.eviction_listener(move |_k, _v, cause| { + c1.increment(cause); + }); + + eviction_counters = Some(c0); + } else { + eviction_counters = None; + } + + cache = builder.build_with_hasher(DefaultHasher); + + (cache, eviction_counters) + } + + fn get(&self, key: &usize) -> bool { + self.cache.get(key).is_some() + } + + fn insert(&self, key: usize, req_id: usize) { + let value = cache::make_value(&self.config, key, req_id); + cache::sleep_thread_for_insertion(&self.config); + self.cache.insert(key, value); + } +} + +impl CacheDriver for MokaSegmentedCache { + fn get_or_insert(&mut self, entry: &TraceEntry, report: &mut Report) { + let mut counters = Counters::default(); + let mut req_id = entry.line_number(); + + for block in entry.range() { + if self.get(&block) { + counters.read_hit(); + } else { + self.insert(block, req_id); + counters.inserted(); + counters.read_missed(); + } + req_id += 1; + } + + counters.add_to_report(report); + } + + fn get_or_insert_once(&mut self, entry: &TraceEntry, report: &mut Report) { + self.insert_once_impl.get_or_insert_once(entry, report); + } + + fn update(&mut self, entry: &TraceEntry, report: &mut Report) { + let mut counters = Counters::default(); + let mut req_id = entry.line_number(); + + for block in entry.range() { + self.insert(block, req_id); + counters.inserted(); + req_id += 1; + } + + counters.add_to_report(report); + } + + fn invalidate(&mut self, entry: &TraceEntry) { + for block in entry.range() { + self.cache.invalidate(&block); + } + } + + fn invalidate_all(&mut self) { + self.cache.invalidate_all(); + } + + fn invalidate_entries_if(&mut self, entry: &TraceEntry) { + for block in entry.range() { + self.cache + .invalidate_entries_if(move |_k, (_s, v)| v[0] == (block % 256) as u8) + .expect("invalidate_entries_if failed"); + } + } + + fn iterate(&mut self) { + let mut count = 0usize; + for _kv in &self.cache { + count += 1; + + if count % 500 == 0 { + std::thread::yield_now(); + } + } + } + + fn eviction_counters(&self) -> Option> { + self.eviction_counters.as_ref().map(Arc::clone) + } +} + +// +// GetWith (implements GetOrInsertOnce) +// +#[derive(Clone)] +pub(crate) struct GetWith { + cache: SegmentedCache, + config: Arc, +} + +impl GetOrInsertOnce for GetWith { + fn get_or_insert_once(&self, entry: &TraceEntry, report: &mut Report) { + let mut counters = Counters::default(); + let mut req_id = entry.line_number(); + let is_inserted = Arc::new(AtomicBool::default()); + + for block in entry.range() { + { + let is_inserted2 = Arc::clone(&is_inserted); + match InitClosureType::select(block) { + InitClosureType::GetOrInsert => self.get_with(block, req_id, is_inserted2), + ty => self.try_get_with(ty, block, req_id, is_inserted2), + } + } + + if is_inserted.load(Ordering::Acquire) { + counters.inserted(); + counters.read_missed(); + is_inserted.store(false, Ordering::Release); + } else { + counters.read_hit(); + } + req_id += 1; + } + + counters.add_to_report(report); + } +} + +impl GetWith { + fn get_with(&self, key: usize, req_id: usize, is_inserted: Arc) { + self.cache.get_with(key, || { + cache::sleep_thread_for_insertion(&self.config); + is_inserted.store(true, Ordering::Release); + cache::make_value(&self.config, key, req_id) + }); + } + + fn try_get_with( + &self, + ty: InitClosureType, + key: usize, + req_id: usize, + is_inserted: Arc, + ) { + match ty { + InitClosureType::GetOrTryInsertWithError1 => self + .cache + .try_get_with(key, || { + cache::sleep_thread_for_insertion(&self.config); + is_inserted.store(true, Ordering::Release); + Ok(cache::make_value(&self.config, key, req_id)) as Result<_, InitClosureError1> + }) + .is_ok(), + InitClosureType::GetOrTyyInsertWithError2 => self + .cache + .try_get_with(key, || { + cache::sleep_thread_for_insertion(&self.config); + is_inserted.store(true, Ordering::Release); + Ok(cache::make_value(&self.config, key, req_id)) as Result<_, InitClosureError2> + }) + .is_ok(), + _ => unreachable!(), + }; + } +} + +// +// EntryOrInsertWith (implements GetOrInsertOnce) +// +#[cfg(not(any(feature = "moka-v08", feature = "moka-v09")))] +mod entry_api { + use super::*; + + #[derive(Clone)] + pub(crate) struct EntryOrInsertWith { + cache: SegmentedCache, + config: Arc, + } + + impl EntryOrInsertWith { + pub(crate) fn new( + cache: SegmentedCache, + config: Arc, + ) -> Self { + Self { cache, config } + } + } + + impl GetOrInsertOnce for EntryOrInsertWith { + fn get_or_insert_once(&self, entry: &TraceEntry, report: &mut Report) { + let mut counters = Counters::default(); + let mut req_id = entry.line_number(); + + for block in entry.range() { + let is_inserted = match InitClosureType::select(block) { + InitClosureType::GetOrInsert => self.entry_or_insert_with(block, req_id), + ty => self.entry_or_try_insert_with(ty, block, req_id), + }; + + if is_inserted { + counters.inserted(); + counters.read_missed(); + } else { + counters.read_hit(); + } + req_id += 1; + } + + counters.add_to_report(report); + } + } + + impl EntryOrInsertWith { + fn entry_or_insert_with(&self, key: usize, req_id: usize) -> bool { + self.cache + .entry(key) + .or_insert_with(|| { + cache::sleep_thread_for_insertion(&self.config); + cache::make_value(&self.config, key, req_id) + }) + .is_fresh() + } + + fn entry_or_try_insert_with(&self, ty: InitClosureType, key: usize, req_id: usize) -> bool { + match ty { + InitClosureType::GetOrTryInsertWithError1 => self + .cache + .entry(key) + .or_try_insert_with(|| { + cache::sleep_thread_for_insertion(&self.config); + Ok(cache::make_value(&self.config, key, req_id)) + as Result<_, InitClosureError1> + }) + .unwrap() + .is_fresh(), + InitClosureType::GetOrTyyInsertWithError2 => self + .cache + .entry(key) + .or_try_insert_with(|| { + cache::sleep_thread_for_insertion(&self.config); + Ok(cache::make_value(&self.config, key, req_id)) + as Result<_, InitClosureError2> + }) + .unwrap() + .is_fresh(), + _ => unreachable!(), + } + } + } +} diff --git a/src/lib.rs b/src/lib.rs index 19ed570..d3e67ea 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -340,11 +340,16 @@ async fn run_multi_tasks( let mut cache = cache_driver.clone(); let ch = receive.clone(); let rb = Arc::clone(&report_builder); + let mut count = 0u32; rt::spawn(async move { let mut report = rb.build(); while let Ok(commands) = ch.recv() { cache::process_commands_async(commands, &mut cache, &mut report).await; + count += 1; + if count % 10_000 == 0 { + tokio::task::yield_now().await; + } } report }) diff --git a/src/main.rs b/src/main.rs index 7750c9a..ad845b2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -113,24 +113,6 @@ async fn run_with_capacity(config: &Config, capacity: usize) -> anyhow::Result<( } for num_clients in num_clients_slice { - if cfg!(feature = "moka-v012") - && config.eviction_listener == RemovalNotificationMode::Queued - { - eprintln!( - "WARNING: eviction_listener = \"queued\" is not supported by \ - the async cache. \"immediate\" mode will be used for it." - ); - } else if cfg!(any( - feature = "moka-v09", - feature = "moka-v010", - feature = "moka-v011" - )) && config.eviction_listener == RemovalNotificationMode::Immediate - { - eprintln!( - "WARNING: eviction_listener = \"immediate\" is not supported by \ - the async cache. \"queued\" mode will be used for it." - ); - } let report = mokabench::run_multi_tasks_moka_async(config, capacity, *num_clients).await?; println!("{}", report.to_csv_record()); } @@ -311,11 +293,33 @@ fn create_config() -> anyhow::Result<(Vec, Config)> { // Since Moka v0.11 let per_key_expiration = matches.is_present(OPTION_PER_KEY_EXPIRATION); - let eviction_listener = if cfg!(not(feature = "moka-v08")) { + let mut eviction_listener = RemovalNotificationMode::None; + + if cfg!(not(feature = "moka-v08")) { if let Some(v) = matches.value_of(OPTION_EVICTION_LISTENER) { match v { - "immediate" => RemovalNotificationMode::Immediate, - "queued" => RemovalNotificationMode::Queued, + "immediate" => { + eviction_listener = RemovalNotificationMode::Immediate; + if cfg!(any( + feature = "moka-v09", + feature = "moka-v010", + feature = "moka-v011" + )) { + eprintln!( + "WARNING: eviction_listener = \"immediate\" is not supported by \ + the async cache. \"queued\" mode will be used for it." + ); + } + } + "queued" => { + eviction_listener = RemovalNotificationMode::Queued; + if cfg!(feature = "moka-v012") { + eprintln!( + "WARNING: eviction_listener = \"queued\" is not supported by \ + the async cache. \"immediate\" mode will be used for it." + ); + } + } _ => { anyhow::bail!( r#"eviction-listener must be "immediate" or "queued", but got "{}""#, @@ -323,12 +327,8 @@ fn create_config() -> anyhow::Result<(Vec, Config)> { ); } } - } else { - RemovalNotificationMode::None } - } else { - RemovalNotificationMode::None - }; + } if !entry_api && insert_once && cfg!(not(any(feature = "moka-v08", feature = "moka-v09"))) { eprintln!("\nWARNING: Testing Moka's entry API is disabled by default. Use --entry-api to enable it.\n"); From 1d4c9f56298afdf06c178f95a6ab21393575bccd Mon Sep 17 00:00:00 2001 From: Tatsuya Kawano Date: Sun, 1 Oct 2023 22:07:18 +0800 Subject: [PATCH 6/8] Update the changelog --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a51b41..253cec9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,8 @@ ### Added -- Added support for moka v0.12. ([#??](gh-pull-????)) - +- Added support for moka v0.12. ([#11](gh-pull-0011)) + - Add crate features `rt-tokio` (default) and `rt-async-std`. ## Version 0.9.0 @@ -127,6 +127,7 @@ - `enable-invalidate-entries-if` +[gh-pull-0008]: https://github.com/moka-rs/mokabench/pull/11 [gh-pull-0008]: https://github.com/moka-rs/mokabench/pull/8 [gh-pull-0002]: https://github.com/moka-rs/mokabench/pull/2 [gh-pull-0001]: https://github.com/moka-rs/mokabench/pull/1 From 879a3580b90ac516ebf3f46e14525d95fbe0ae5c Mon Sep 17 00:00:00 2001 From: Tatsuya Kawano Date: Sun, 1 Oct 2023 22:13:23 +0800 Subject: [PATCH 7/8] Fix clippy warnings and apply rustfmt --- src/async_rt_helper.rs | 36 +++++++++------------- src/cache/moka_driver_v1/async_cache.rs | 2 +- src/cache/moka_driver_v1/sync_cache.rs | 2 +- src/cache/moka_driver_v1/sync_segmented.rs | 2 +- src/cache/moka_driver_v2/async_cache.rs | 4 +-- src/cache/moka_driver_v2/sync_cache.rs | 4 +-- src/cache/moka_driver_v2/sync_segmented.rs | 4 +-- src/load_gen.rs | 4 ++- 8 files changed, 23 insertions(+), 35 deletions(-) diff --git a/src/async_rt_helper.rs b/src/async_rt_helper.rs index 2f1b85c..c818c50 100644 --- a/src/async_rt_helper.rs +++ b/src/async_rt_helper.rs @@ -1,18 +1,8 @@ -#[cfg(all( - feature = "rt-tokio", - feature = "rt-async-std" -))] -compile_error!( - "You cannot enable both `rt-tokio` and `rt-async-std` features at the same time." -); - -#[cfg(all( - not(feature = "rt-tokio"), - not(feature = "rt-async-std") -))] -compile_error!( - "You must enable one of the `rt-tokio` and `rt-async-std` features." -); +#[cfg(all(feature = "rt-tokio", feature = "rt-async-std"))] +compile_error!("You cannot enable both `rt-tokio` and `rt-async-std` features at the same time."); + +#[cfg(all(not(feature = "rt-tokio"), not(feature = "rt-async-std")))] +compile_error!("You must enable one of the `rt-tokio` and `rt-async-std` features."); #[cfg(feature = "rt-tokio")] use rt_tokio as rt; @@ -27,9 +17,10 @@ mod rt_tokio { use std::future::Future; use tokio::task::JoinHandle; - pub(crate) fn spawn(future: T) -> JoinHandle where - T: Future + Send + 'static, - T::Output: Send + 'static, + pub(crate) fn spawn(future: T) -> JoinHandle + where + T: Future + Send + 'static, + T::Output: Send + 'static, { tokio::spawn(future) } @@ -41,12 +32,13 @@ mod rt_tokio { #[cfg(feature = "rt-async-std")] mod rt_async_std { - use std::future::Future; use async_std::task::JoinHandle; + use std::future::Future; - pub(crate) fn spawn(future: F) -> JoinHandle where - F: Future + Send + 'static, - T: Send + 'static, + pub(crate) fn spawn(future: F) -> JoinHandle + where + F: Future + Send + 'static, + T: Send + 'static, { async_std::task::spawn(future) } diff --git a/src/cache/moka_driver_v1/async_cache.rs b/src/cache/moka_driver_v1/async_cache.rs index 9fa401d..2df5a16 100644 --- a/src/cache/moka_driver_v1/async_cache.rs +++ b/src/cache/moka_driver_v1/async_cache.rs @@ -146,7 +146,7 @@ impl MokaAsyncCache { eviction_counters = None; } - cache = builder.build_with_hasher(DefaultHasher::default()); + cache = builder.build_with_hasher(DefaultHasher); } (cache, eviction_counters) diff --git a/src/cache/moka_driver_v1/sync_cache.rs b/src/cache/moka_driver_v1/sync_cache.rs index 63f2261..96988a0 100644 --- a/src/cache/moka_driver_v1/sync_cache.rs +++ b/src/cache/moka_driver_v1/sync_cache.rs @@ -157,7 +157,7 @@ impl MokaSyncCache { eviction_counters = None; } - cache = builder.build_with_hasher(DefaultHasher::default()); + cache = builder.build_with_hasher(DefaultHasher); } (cache, eviction_counters) diff --git a/src/cache/moka_driver_v1/sync_segmented.rs b/src/cache/moka_driver_v1/sync_segmented.rs index a3f205b..2809038 100644 --- a/src/cache/moka_driver_v1/sync_segmented.rs +++ b/src/cache/moka_driver_v1/sync_segmented.rs @@ -164,7 +164,7 @@ impl MokaSegmentedCache { eviction_counters = None; } - cache = builder.build_with_hasher(DefaultHasher::default()); + cache = builder.build_with_hasher(DefaultHasher); } (cache, eviction_counters) diff --git a/src/cache/moka_driver_v2/async_cache.rs b/src/cache/moka_driver_v2/async_cache.rs index c698392..03b1854 100644 --- a/src/cache/moka_driver_v2/async_cache.rs +++ b/src/cache/moka_driver_v2/async_cache.rs @@ -108,7 +108,6 @@ impl MokaAsyncCache { builder = builder.weigher(|_k, (s, _v)| *s); } - let cache; let eviction_counters; if config.is_eviction_listener_enabled() { @@ -124,8 +123,7 @@ impl MokaAsyncCache { eviction_counters = None; } - cache = builder.build_with_hasher(DefaultHasher); - + let cache = builder.build_with_hasher(DefaultHasher); (cache, eviction_counters) } diff --git a/src/cache/moka_driver_v2/sync_cache.rs b/src/cache/moka_driver_v2/sync_cache.rs index 92cafc6..2d1e82f 100644 --- a/src/cache/moka_driver_v2/sync_cache.rs +++ b/src/cache/moka_driver_v2/sync_cache.rs @@ -104,7 +104,6 @@ impl MokaSyncCache { builder = builder.weigher(|_k, (s, _v)| *s); } - let cache; let eviction_counters; if config.is_eviction_listener_enabled() { @@ -120,8 +119,7 @@ impl MokaSyncCache { eviction_counters = None; } - cache = builder.build_with_hasher(DefaultHasher); - + let cache = builder.build_with_hasher(DefaultHasher); (cache, eviction_counters) } diff --git a/src/cache/moka_driver_v2/sync_segmented.rs b/src/cache/moka_driver_v2/sync_segmented.rs index aa4fd0e..10252e4 100644 --- a/src/cache/moka_driver_v2/sync_segmented.rs +++ b/src/cache/moka_driver_v2/sync_segmented.rs @@ -111,7 +111,6 @@ impl MokaSegmentedCache { builder = builder.weigher(|_k, (s, _v)| *s); } - let cache; let eviction_counters; if config.is_eviction_listener_enabled() { @@ -127,8 +126,7 @@ impl MokaSegmentedCache { eviction_counters = None; } - cache = builder.build_with_hasher(DefaultHasher); - + let cache = builder.build_with_hasher(DefaultHasher); (cache, eviction_counters) } diff --git a/src/load_gen.rs b/src/load_gen.rs index 5fb8b17..7ed7a3f 100644 --- a/src/load_gen.rs +++ b/src/load_gen.rs @@ -17,7 +17,9 @@ where let mut ops = Vec::with_capacity(max_chunk_size); for line_result in chunk { let (line_number, line) = line_result?; - let Some(entry) = parser.parse(&line, line_number)? else { continue }; + let Some(entry) = parser.parse(&line, line_number)? else { + continue; + }; *counter += 1; if config.invalidate_all && *counter % 100_000 == 0 { ops.push(Command::InvalidateAll); From 7fb8812bb73db51156c145175107cbe48b66d699 Mon Sep 17 00:00:00 2001 From: Tatsuya Kawano Date: Sun, 1 Oct 2023 22:15:20 +0800 Subject: [PATCH 8/8] Fix broken links on the change log --- CHANGELOG.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 253cec9..59e14e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,21 +4,21 @@ ### Added -- Added support for moka v0.12. ([#11](gh-pull-0011)) +- Added support for moka v0.12. ([#11][gh-pull-0011]) - Add crate features `rt-tokio` (default) and `rt-async-std`. ## Version 0.9.0 ### Added -- Added support for moka v0.11. ([#8](gh-pull-0008)) +- Added support for moka v0.11. ([#8][gh-pull-0008]) - Added a CLI option `--per-key-expiration`. ## Version 0.8.0 ### Added -- Added support for moka v0.10 and mini-moka v0.10. ([#2](gh-pull-0002)) +- Added support for moka v0.10 and mini-moka v0.10. ([#2][gh-pull-0002]) - Added a CLI option `--entry-api`. ### Changed @@ -127,7 +127,7 @@ - `enable-invalidate-entries-if` -[gh-pull-0008]: https://github.com/moka-rs/mokabench/pull/11 +[gh-pull-0011]: https://github.com/moka-rs/mokabench/pull/11 [gh-pull-0008]: https://github.com/moka-rs/mokabench/pull/8 [gh-pull-0002]: https://github.com/moka-rs/mokabench/pull/2 [gh-pull-0001]: https://github.com/moka-rs/mokabench/pull/1