Skip to content

Commit 2944c9f

Browse files
authored
doc: add docs for 0.12, setup versioning (#18)
* doc: add docs for 0.12, setup versioning Signed-off-by: MrCroxx <[email protected]> * chore: update deps Signed-off-by: MrCroxx <[email protected]> --------- Signed-off-by: MrCroxx <[email protected]>
1 parent f3ad646 commit 2944c9f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1125
-36
lines changed

docs/02-tutorial/01-in-memory-cache.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ The hybrid cache `HybridCache` also provides a in-memory only mode. If you want
1515
Add this line to the `[dependencies]` section of your project's `Cargo.toml`.
1616

1717
```toml
18-
foyer = "0.11"
18+
foyer = "0.12"
1919
```
2020

2121
If you are using a nightly version of the rust toolchain, the `nightly` feature is needed.
2222

2323
```toml
24-
foyer = { version = "0.11", features = ["nightly"] }
24+
foyer = { version = "0.12", features = ["nightly"] }
2525
```
2626

2727
## 2. Build a `Cache`

docs/02-tutorial/02-hybrid-cache.md

Lines changed: 65 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ Let get through it!
1111
Add this line to the `[dependencies]` section of your project's `Cargo.toml`.
1212

1313
```toml
14-
foyer = "0.11"
14+
foyer = "0.12"
1515
```
1616

1717
If you are using a nightly version of the rust toolchain, the `nightly` feature is needed.
1818

1919
```toml
20-
foyer = { version = "0.11", features = ["nightly"] }
20+
foyer = { version = "0.12", features = ["nightly"] }
2121
```
2222

2323
## 2. Build a `HybridCache`
@@ -58,13 +58,31 @@ The default configuration count the usage by entry count. If you needs to change
5858

5959
### 2.3 Build disk cache
6060

61-
#### 2.3.1 Run on in-memory cache compatible mode
61+
After setting up the in-memory cache, you can move on to setup the disk cache.
6262

63-
After setting up the in-memory cache, you can call `storage()` to move on to setup the disk cache.
63+
#### 2.3.1 Choose a proper engine
6464

65-
```rust
66-
let mut builder = HybridCacheBuilder::new().memory(1024).storage();
67-
```
65+
To setup the disk cache, you need to choose a proper engine for your workload first. Currently, ***foyer*** support 3 kinds of engines:
66+
67+
- `Engine::Large`: For cache entries larger than 2 KiB. Friendly to HDD/SSD while minimizing memory usage for indexing.
68+
- `Engine::Small`: For cache entries smaller than 2 KiB. A set-associated cache that does not use memory for indexing.
69+
- `Engine::Mixed(ratio)`: For cache entries in all sizes. Mixed `Engine::Large` and `Engine::Small`. Use `ratio` to control the proportion of the capacity of `Engine::Small`. Introducing a little overhead compared to using `Engine::Large` and `Engine::Small` separately.
70+
71+
For more details about the engines, please refer to [Design - Architecture](/docs/design/architecture).
72+
73+
:::warning
74+
75+
`Engine::Small` and `Engine::Mixed` are preview version and have **NOT** undergone sufficient testing in production environments. Please use them with caution in production systems.
76+
77+
If you have such needs, you can contact me via Github. We can work together to improve the system for production and make ***foyer*** better! 🥰
78+
79+
:::
80+
81+
#### 2.3.2 Setup shared options
82+
83+
Some options are shared between engines, you can setup shared options before setting up engine-specific options.
84+
85+
##### 2.3.2.1 Setup device options
6886

6987
By default, the hybrid cache will **NOT** include a disk cache unless you specify a device. The hybrid cache will run on a in-memory cache compatible mode with the default configuration. All lookups to the disk will return a miss. It is useful if you want to support both in-memory cache or the hybrid cache based on your project's configuration or for debugging.
7088

@@ -74,9 +92,7 @@ RisingWave[^risingwave] supports caching the LSM-tree meta and blocks in both hy
7492

7593
:::
7694

77-
#### 2.3.2 Run on hybrid cache mode with a device
78-
79-
To specify a device for the hybrid cache, just call `with_device_config()`[^with-device-config] and provide the device config.
95+
To enable the hybrid cache mode, a device needs to be specified by calling `with_device_options()`[^with-device-options] and providing the device options.
8096

8197
Currently, the storage of the hybrid cache supports 2 kinds of devices:
8298

@@ -97,28 +113,27 @@ Let's take `DirectFsDevice` as an example:
97113
let hybrid: HybridCache<u64, String> = HybridCacheBuilder::new()
98114
.with_name("foyer")
99115
.memory(1024)
100-
.storage()
101-
.with_device_config(DirectFsDeviceOptionsBuilder::new("/data/foyer").build())
116+
.storage(Engine::Large)
117+
.with_device_options(DirectFsDeviceOptions::new("/data/foyer"))
102118
.build()
103119
.await
104120
.unwrap();
105121
```
106122

107123
This example uses directory `/data/foyer` to store disk cache data using a device options builder. With the default configuration, ***foyer*** will take 80% of the current free space as the disk cache capacity. You can also specify the disk cache capacity and per file size with the builder.
108124

109-
For more details, please refer to the API document.[^direct-fs-device-options-builder] [^direct-file-device-options-builder]
125+
For more details, please refer to the API document.[^direct-fs-device-options] [^direct-file-device-options]
110126

111-
#### 2.3.3 Restrict the throughput
127+
##### 2.3.2.2 Restrict the throughput
112128

113129
The bandwidth of the disk is much lower than the bandwidth of the memory. To avoid excessive use of the disk bandwidth, it is **HIGHLY RECOMMENDED** to setup the admission picker with a rate limiter.
114130

115131
```rust
116132
let hybrid: HybridCache<u64, String> = HybridCacheBuilder::new()
117133
.with_name("foyer")
118134
.memory(1024)
119-
.storage()
120-
.with_device_config(DirectFsDeviceOptionsBuilder::new("/data/foyer").build())
121-
.with_admission_picker(Arc::new(RateLimitPicker::new(100 * 1024 * 1024)))
135+
.storage(Engine::Large)
136+
.with_device_options(DirectFsDeviceOptions::new("/data/foyer"))
122137
.build()
123138
.await
124139
.unwrap();
@@ -134,17 +149,32 @@ For more details, please refer to [Design - Architecture](/docs/design/architect
134149

135150
:::
136151

137-
#### 2.3.4 Achieve better performance
152+
##### 2.3.2.3 Other shared options
138153

139-
The hybrid cache builder also provides a lot of detailed arguments for tuning.
154+
There are also other shared options for tuning or other purposes.
140155

141-
For example:
156+
- `with_runtime_options()`: Set the runtime options to enable and setup the dedicated runtime.
157+
- `with_compression()`: Set the compression algorithm for serialization and deserialization.
158+
- `with_recover_mode()`: Set the recover mode.
159+
- `with_flush()`: Set if trigger a flush operation after writing the disk.
160+
- ...
142161

143-
- `with_indexer_shards()` can be used for mitigating hot shards of the indexer.
144-
- `with_flushers()`, `with_reclaimers()` and `with_recover_concurrency()` can be used to tune the concurrency of the inner components.
145-
- `with_runtime_config()` can be used to enable the dedicated runtime or further runtime splitting.
162+
For more details, please refer to the API document.[^hybrid-cache-builder]
146163

147-
Tuning the optimized parameters requires an understanding of ***foyer*** interior design and benchmarking with the real workload. For more details, please refer to [Design - Architecture](/docs/design/architecture).
164+
:::tip
165+
166+
Tuning the optimized parameters requires an understanding of ***foyer*** interior design and benchmarking with the real workload. For more details, please refer to [Topic - Tuning](/docs/topic/tuning) and [Design - Architecture](/docs/design/architecture).
167+
168+
:::
169+
170+
#### 2.3.3 Setup engine-specific options
171+
172+
Each engine also has its specific options for tuning or other purposes.
173+
174+
- `with_large_object_disk_cache_options()`[^with-large-object-disk-cache-options]: Set the options for the large object disk cache.
175+
- `with_small_object_disk_cache_options()`[^with-small-object-disk-cache-options]: Set the options for the small object disk cache.
176+
177+
For more details, please refer to the API document [^large-engine-options] [^small-engine-options].
148178

149179
## 3. `HybridCache` Usage
150180

@@ -193,7 +223,7 @@ The hybrid cache also provides a `writer()` interface for advanced usage, such a
193223

194224
[^risingwave]: https://github.com/risingwavelabs/risingwave
195225

196-
[^with-device-config]: https://docs.rs/foyer/latest/foyer/struct.HybridCacheBuilderPhaseStorage.html#method.with_device_config
226+
[^with-device-options]: https://docs.rs/foyer/latest/foyer/struct.HybridCacheBuilderPhaseStorage.html#method.with_device_options
197227

198228
[^direct-fs-device]: https://docs.rs/foyer/latest/foyer/struct.DirectFsDevice.html
199229

@@ -203,8 +233,16 @@ The hybrid cache also provides a `writer()` interface for advanced usage, such a
203233

204234
[^direct-fs-device-options-builder]: https://docs.rs/foyer/latest/foyer/struct.DirectFsDeviceOptionsBuilder.html
205235

206-
[^direct-file-device-options-builder]: https://docs.rs/foyer/latest/foyer/struct.DirectFileDeviceOptionsBuilder.html
236+
[^direct-file-device-options]: https://docs.rs/foyer/latest/foyer/struct.DirectFileDeviceOptions.html
207237

208238
[^admission-picker]: https://docs.rs/foyer/latest/foyer/trait.AdmissionPicker.html
209239

210-
[^hybrid-cache-writer]: https://docs.rs/foyer/latest/foyer/struct.HybridCacheWriter.html
240+
[^hybrid-cache-writer]: https://docs.rs/foyer/latest/foyer/struct.HybridCacheWriter.html
241+
242+
[^with-large-object-disk-cache-options]: https://docs.rs/foyer/latest/foyer/struct.HybridCacheBuilderPhaseStorage.html#method.with_large_object_disk_cache_options
243+
244+
[^with-small-object-disk-cache-options]: https://docs.rs/foyer/latest/foyer/struct.HybridCacheBuilderPhaseStorage.html#method.with_small_object_disk_cache_options
245+
246+
[^large-engine-options]: https://docs.rs/foyer/latest/foyer/struct.LargeEngineOptions.html
247+
248+
[^small-engine-options]: https://docs.rs/foyer/latest/foyer/struct.SmallEngineOptions.html

docs/03-topic/03-tuning.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Tuning
2+
3+
***TBC ... ...***

docusaurus.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const config: Config = {
4242
// Remove this to remove the "edit this page" links.
4343
editUrl:
4444
'https://github.com/foyer-rs/website/tree/main/',
45+
includeCurrentVersion: false,
4546
},
4647
blog: {
4748
showReadingTime: true,
@@ -83,6 +84,11 @@ const config: Config = {
8384
},
8485
{ to: '/blog', label: 'Blog', position: 'left' },
8586
{ to: '/blog/remote/CHANGELOG', label: 'Changelog', position: 'left' },
87+
{
88+
type: 'docsVersionDropdown',
89+
docsPluginId: "default",
90+
position: 'right',
91+
},
8692
{
8793
href: 'https://crates.io/crates/foyer',
8894
label: 'crates.io',
@@ -161,6 +167,7 @@ const config: Config = {
161167
],
162168
copyright: `Copyright © ${new Date().getFullYear()} foyer. Built with Docusaurus.`,
163169
},
170+
tableOfContents: { minHeadingLevel: 3, maxHeadingLevel: 5 },
164171
prism: {
165172
theme: prismThemes.dracula,
166173
darkTheme: prismThemes.dracula,

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

versioned_docs/version-0.11/01-overview/assets/benchmarks.svg

Lines changed: 3 additions & 0 deletions
Loading

versioned_docs/version-0.11/01-overview/assets/exchange-hybrid-cache.svg

Lines changed: 3 additions & 0 deletions
Loading

versioned_docs/version-0.11/01-overview/assets/exchange.svg

Lines changed: 3 additions & 0 deletions
Loading

versioned_docs/version-0.11/01-overview/assets/hybrid-cache.svg

Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Overview
2+
3+
<p align="center">
4+
<img src="/img/logo/slogan.min.svg" style="width: 280px;" />
5+
</p>
6+
7+
<div style="text-align: center;">
8+
9+
![Website](https://img.shields.io/website?url=https%3A%2F%2Ffoyer.rs&up_message=foyer.rs&style=for-the-badge&logo=rust&labelColor=555555)
10+
![Crates.io Version](https://img.shields.io/crates/v/foyer?style=for-the-badge&logo=docs.rs&labelColor=555555)
11+
![docs.rs](https://img.shields.io/docsrs/foyer?style=for-the-badge&logo=docs.rs&labelColor=555555)
12+
13+
</div>
14+
15+
## What is foyer?
16+
17+
***foyer***, just as its slogan, is a hybrid cache library for the Rust programming language. 🦀
18+
19+
## What is hybrid cache?
20+
21+
A hybrid cache is a caching system that utilizes both memory and disk storage simultaneously.
22+
23+
<div style="text-align: center;">
24+
25+
![hybrid cache](./assets/hybrid-cache.svg)
26+
27+
</div>
28+
29+
It is commonly used to extend the insufficient memory cache for the system uses Object Store Service (OSS, e.g. AWS S3) as its primary data storage[^oss-dia] to **improve performance** and **reduce costs**[^risingwave].
30+
31+
## Why we need a hybrid cache?
32+
33+
More and more systems are using OSS as their primary data storage. OSS has many great features, such as low storage cost, high availability and durability, and almost unlimited scalability.
34+
35+
However, there are also downsides with OSS. For example, the latency is high and uncontrollable, and its price increases with each accesses. The downsides will be further amplified in a large working set because of more data exchange between cache and OSS.
36+
37+
<div style="text-align: center;">
38+
39+
![exchange](./assets/exchange.svg)
40+
41+
</div>
42+
43+
With a hybrid cache, the ability to cache the working set can be extended from memory only to memory and disk. This can reduce data exchange between cache and OSS, thereby improving performance and reducing costs.
44+
45+
<div style="text-align: center;">
46+
47+
![exchange hybrid cache](./assets/exchange-hybrid-cache.svg)
48+
49+
</div>
50+
51+
## Highlights of foyer
52+
53+
As a hybrid cache, ***foyer*** provides the following highlighted features:
54+
55+
- **Hybrid Cache**: Seamlessly integrates both in-memory and disk cache for optimal performance and flexibility.
56+
- **Plug-and-Play Algorithms**: Empowers users with easily replaceable caching algorithms, ensuring adaptability to diverse use cases.
57+
- **Fearless Concurrency**: Built to handle high concurrency with robust thread-safe mechanisms, guaranteeing reliable performance under heavy loads.
58+
- **Zero-Copy Abstraction**: Leveraging Rust's robust type system, the in-memory cache in foyer achieves a better performance with zero-copy abstraction.
59+
- **User-Friendly Interface**: Offers a simple and intuitive API, making cache integration effortless and accessible for developers of all levels.
60+
- **Out-of-the-Box Observability**: Integrate popular observation systems such as Prometheus, Grafana, Opentelemetry, and Jaeger in just **ONE** line.
61+
62+
## Why use foyer, when you have 'X'?
63+
64+
Unfortunately, there is currently no general proposed hybrid cache library in the Rust community. If you have a need for hybrid cache, ***foyer*** would be your best choice.
65+
66+
CacheLib[^cachelib] provides a Rust binding. However, it only provides limited interfaces. You still need to patch the C++ codebase if you have requirements such as logging, metrics, or tracing supports. Besides, ***foyer*** provides a better optimized storage engine implement over CacheLib. You can try both ***foyer*** and CacheLib to compare the benchmarks.
67+
68+
For the needs as an in-memory only cache, ***foyer*** also provides compatible interfaces and competitive performance. Benchmarks[^benchmark] show that ***foyer*** outperforms moka[^moka] and is only second to quick-cache[^quick-cache].
69+
70+
<div style="text-align: center;">
71+
72+
![benchmarks](./assets/benchmarks.svg)
73+
74+
</div>
75+
76+
## What's next?
77+
78+
- Learn how to use ***foyer*** in your project, goto [Tutorial](/docs/category/tutorial).
79+
- Learn how to solve various challenging situations with ***foyer***, goto [Topic](/docs/category/topic).
80+
- Learn how other projects use ***foyer***, goto [Case Study](/docs/category/case-study).
81+
- Learn the design of ***foyer***, goto [Design](/docs/category/design).
82+
83+
## Acknowledgement
84+
85+
***foyer*** draws inspiration from CacheLib[^cachelib], a well-known cache library written in C++, and Caffeine[^caffeine], a widely-used in-memory cache library in Java, among other projects like moka[^moka], intrusive-rs[^intrusive-rs], etc.
86+
87+
Thank you for your efforts! 🥰
88+
89+
[^oss-dia]: Systems using OSS as its primary data storage: [RisingWave](https://github.com/risingwavelabs/risingwave), [Chroma Cloud](https://github.com/chroma-core/chroma), [SlateDB](https://github.com/slatedb/slatedb), etc.
90+
91+
[^risingwave]: How streaming database RisingWave use foyer to improve performance and reduce costs: [Case Study - RisingWave](/docs/case-study/risingwave).
92+
93+
[^cachelib]: [FaceBook/CacheLib](https://github.com/facebook/cachelib).
94+
95+
[^benchmark]: Benchmark with mokabench[^mokabench]: [PR comments](https://github.com/moka-rs/mokabench/pull/20#issuecomment-2080429290).
96+
97+
[^moka]: [moka-rs/moka](https://github.com/moka-rs/moka).
98+
99+
[^quick-cache]: [arthurprs/quick-cache](https://github.com/arthurprs/quick-cache).
100+
101+
[^caffeine]: [ben-manes/caffeine](https://github.com/ben-manes/caffeine).
102+
103+
[^intrusive-rs]: [Amanieu/intrusive-rs](https://github.com/Amanieu/intrusive-rs).
104+
105+
[^mokabench]: [moka-rs/mokabench](https://github.com/moka-rs/mokabench).

0 commit comments

Comments
 (0)