Author: Jason White [github@jasonwhite.io]
Hash: b575c5f8a7295659b7e96c4f0c7ebfad3e8089a7
Timestamp: Mon, 11 Jan 2021 08:52:15 +0000 (3 years ago)

+18 -1 +/-4 browse
Print out cache size during initialization
1diff --git a/Cargo.lock b/Cargo.lock
2index b146e91..d7b20ad 100644
3--- a/Cargo.lock
4+++ b/Cargo.lock
5 @@ -1133,6 +1133,7 @@ dependencies = [
6 "hex 0.3.2",
7 "http",
8 "human-size",
9+ "humansize",
10 "humantime 2.0.1",
11 "hyper",
12 "linked-hash-map",
13 diff --git a/Cargo.toml b/Cargo.toml
14index e01bd8f..e8a72e4 100644
15--- a/Cargo.toml
16+++ b/Cargo.toml
17 @@ -27,6 +27,7 @@ generic-array = "0.14"
18 hex = "0.3"
19 http = "0.2"
20 human-size = "0.4"
21+ humansize = "1"
22 humantime = "2"
23 hyper = { version = "0.14", features = ["server", "http1", "http2", "tcp", "stream"] }
24 linked-hash-map = { version = "0.5", features = ["serde_impl"] }
25 diff --git a/src/lru.rs b/src/lru.rs
26index 5577086..cf318f0 100644
27--- a/src/lru.rs
28+++ b/src/lru.rs
29 @@ -52,6 +52,11 @@ where
30 self.size
31 }
32
33+ /// Returns the number of items in the cache.
34+ pub fn len(&self) -> usize {
35+ self.map.len()
36+ }
37+
38 /// Loads the cache from a stream of entries. Note that this throws away any
39 /// LRU information. Since the server shouldn't be restarted very often,
40 /// this shouldn't be a problem in practice. Frequently used entries will
41 diff --git a/src/storage/cached.rs b/src/storage/cached.rs
42index ecc76ce..acc8809 100644
43--- a/src/storage/cached.rs
44+++ b/src/storage/cached.rs
45 @@ -29,6 +29,7 @@ use futures::{
46 stream::{StreamExt, TryStreamExt},
47 Future,
48 };
49+ use humansize::{file_size_opts as file_size, FileSize};
50 use tokio::{self, sync::Mutex};
51
52 use crate::lru;
53 @@ -103,8 +104,17 @@ where
54 cache: C,
55 storage: S,
56 ) -> Result<Self, C::Error> {
57- let lru = Arc::new(Mutex::new(Cache::from_stream(cache.list()).await?));
58+ let lru = Cache::from_stream(cache.list()).await?;
59+
60+ log::info!(
61+ "Prepopulated cache with {} entries ({})",
62+ lru.len(),
63+ lru.size()
64+ .file_size(file_size::DECIMAL)
65+ .unwrap_or_else(|e| e)
66+ );
67
68+ let lru = Arc::new(Mutex::new(lru));
69 let cache = Arc::new(cache);
70
71 // Prune the cache. The maximum size setting may have changed