History

Learn about store's resource consumption (#259)

Sebastian Thiel committed 4 years ago

Commit ef9b08c1 parent 70dc4451 file · +25 −1Browse files

Unified · Split

experiments/odb-redesign/src/lib.rs+25−1
@@ -58,7 +58,7 @@ mod features { · 57 unmodified lines
5858
5959 mod odb {
6060 use crate::features;
61− use crate::features::{get_mut, get_ref_upgradeable, upgrade_ref_to_mut};
61+ use crate::features::{get_mut, get_ref, get_ref_upgradeable, upgrade_ref_to_mut};
6262 use crate::odb::policy::{load_indices, PackIndexMarker};
6363 use git_odb::data::Object;
6464 use git_odb::pack::bundle::Location;
@@ -219,6 +219,13 @@ mod odb { · 154 unmodified lines
219219 NoMoreIndices,
220220 }
221221 }
222+
223+ /// A snapshot about resource usage.
224+ pub struct StateInformation {
225+ pub num_handles: usize,
226+ pub open_indices: usize,
227+ pub open_packs: usize,
228+ }
222229 }
223230
224231 /// Note that each store is strictly per repository, and that we don't implement any kind of limit of file handles.
@@ -256,6 +263,23 @@ mod odb { · 31 unmodified lines
256263 id: next,
257264 }
258265 }
266+
267+ /// Get a snapshot of the current amount of handles and open packs and indices.
268+ /// If there are no handles, we are only consuming resources, which might indicate that this instance should be
269+ /// discarded.
270+ pub fn state_snapshot(&self) -> policy::StateInformation {
271+ let state = get_ref(&self.state);
272+ policy::StateInformation {
273+ num_handles: state.handles.len(),
274+ open_packs: state.loaded_packs.iter().filter(|p| p.is_some()).count()
275+ + state
276+ .loaded_packs_by_multi_index
277+ .values()
278+ .map(|packs| packs.iter().filter(|p| p.is_some()).count())
279+ .sum::<usize>(),
280+ open_indices: state.loaded_indices.iter().filter(|i| i.is_some()).count(),
281+ }
282+ }
259283 }
260284
261285 impl Store {