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
58 58
59mod odb {59mod odb {
60 use crate::features;60 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};
62 use crate::odb::policy::{load_indices, PackIndexMarker};62 use crate::odb::policy::{load_indices, PackIndexMarker};
63 use git_odb::data::Object;63 use git_odb::data::Object;
64 use git_odb::pack::bundle::Location;64 use git_odb::pack::bundle::Location;
@@ -219,6 +219,13 @@ mod odb { · 154 unmodified lines
219 NoMoreIndices,219 NoMoreIndices,
220 }220 }
221 }221 }
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 }
222 }229 }
223 230
224 /// Note that each store is strictly per repository, and that we don't implement any kind of limit of file handles.231 /// 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
256 id: next,263 id: next,
257 }264 }
258 }265 }
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 }
259 }283 }
260 284
261 impl Store {285 impl Store {