#1756 fix memory exhausted during searching (#1758)

* #1756 fix memory exhausted during searching

Signed-off-by: yudong.cai <yudong.cai@zilliz.com>

* #1756 update const names

Signed-off-by: yudong.cai <yudong.cai@zilliz.com>
pull/1760/head
Cai Yudong 2020-03-26 13:55:11 +08:00 committed by GitHub
parent 5a83ba4e49
commit 578d2633eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -18,6 +18,7 @@ Please mark all change in change log and use the issue from GitHub
- \#1724 Remove unused unittests
- \#1734 Opentracing for combined search request
- \#1735 Fix search out of memory with ivf_flat
- \#1756 Fix memory exhausted during searching
## Feature
- \#1603 BinaryFlat add 2 Metric: Substructure and Superstructure

View File

@ -12,15 +12,16 @@
namespace milvus {
namespace cache {
constexpr double DEFAULT_THRESHHOLD_PERCENT = 0.7;
constexpr double WARNING_THRESHHOLD_PERCENT = 0.9;
constexpr double DEFAULT_THRESHOLD_PERCENT = 0.7;
constexpr double WARNING_THRESHOLD_PERCENT = 0.9;
constexpr double BIG_ITEM_THRESHOLD_PERCENT = 0.1;
template <typename ItemObj>
Cache<ItemObj>::Cache(int64_t capacity, int64_t cache_max_count, const std::string& header)
: usage_(0),
capacity_(capacity),
header_(header),
freemem_percent_(DEFAULT_THRESHHOLD_PERCENT),
freemem_percent_(DEFAULT_THRESHOLD_PERCENT),
lru_(cache_max_count) {
}
@ -81,7 +82,9 @@ Cache<ItemObj>::insert(const std::string& key, const ItemObj& item) {
}
// if usage exceed capacity, free some items
if (usage_ > (int64_t)(capacity_ * WARNING_THRESHHOLD_PERCENT)) {
if (usage_ > capacity_ ||
(item_size > (int64_t)(capacity_ * BIG_ITEM_THRESHOLD_PERCENT) &&
usage_ > (int64_t)(capacity_ * WARNING_THRESHOLD_PERCENT))) {
SERVER_LOG_DEBUG << header_ << " Current usage " << (usage_ >> 20) << "MB is too high for capacity "
<< (capacity_ >> 20) << "MB, start free memory";
free_memory();