forked from qdrant/qdrant
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Strict mode max collection vector size (qdrant#5501)
* Strict mode config: Max collection size * api specs * Add tests + set/update payload check * Improve function names and add comments * rename config to separate vectors and payload * fix tests * Adjust configs docs * add benchmark * improve performance by caching shard info * add bench for size_info() and fix tests * Also limit the batch-size for vector updates (qdrant#5508) * Also limit the batch-size for vector updates * clippy * add lost commit * Load cache on collection initialization * add unit type to parameter name * fix renaming in test * clearer error message * fix test * review remarks * remove unused function for now --------- Co-authored-by: Arnaud Gourlay <arnaud.gourlay@gmail.com>
- Loading branch information
Showing
32 changed files
with
629 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use std::sync::atomic::{AtomicUsize, Ordering}; | ||
|
||
/// Amount of requests that have to be done until the cached data gets updated. | ||
const UPDATE_INTERVAL: usize = 32; | ||
|
||
/// A cache for `LocalDataStats` utilizing `AtomicUsize` for better performance. | ||
#[derive(Default)] | ||
pub(crate) struct LocalDataStatsCache { | ||
vector_storage_size: AtomicUsize, | ||
|
||
request_counter: AtomicUsize, | ||
} | ||
|
||
impl LocalDataStatsCache { | ||
pub fn new_with_values(stats: LocalDataStats) -> Self { | ||
let LocalDataStats { | ||
vector_storage_size, | ||
} = stats; | ||
let vector_storage_size = AtomicUsize::new(vector_storage_size); | ||
Self { | ||
vector_storage_size, | ||
request_counter: AtomicUsize::new(1), // Prevent same data getting loaded a second time when doing the first request. | ||
} | ||
} | ||
|
||
/// Checks whether the cache needs to be updated. | ||
/// For performance reasons, this also assumes a cached value gets read afterwards and brings the | ||
/// Update counter one tick closer to the next update. | ||
pub fn check_need_update_and_increment(&self) -> bool { | ||
let req_counter = self.request_counter.fetch_add(1, Ordering::Relaxed); | ||
req_counter % UPDATE_INTERVAL == 0 | ||
} | ||
|
||
/// Sets all cache values to `new_stats`. | ||
pub fn update(&self, new_stats: LocalDataStats) { | ||
let LocalDataStats { | ||
vector_storage_size, | ||
} = new_stats; | ||
|
||
self.vector_storage_size | ||
.store(vector_storage_size, Ordering::Relaxed); | ||
} | ||
|
||
/// Returns cached vector storage size estimation. | ||
pub fn get_vector_storage(&self) -> usize { | ||
self.vector_storage_size.load(Ordering::Relaxed) | ||
} | ||
} | ||
|
||
/// Statistics for local data, like the size of vector storage. | ||
#[derive(Clone, Copy, Default)] | ||
pub struct LocalDataStats { | ||
/// Estimated amount of vector storage size. | ||
pub vector_storage_size: usize, | ||
} | ||
|
||
impl LocalDataStats { | ||
pub fn accumulate_from(&mut self, other: &Self) { | ||
let LocalDataStats { | ||
vector_storage_size, | ||
} = other; | ||
|
||
self.vector_storage_size += vector_storage_size; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.