blob: dd7fd441f231d6321cb62fc8ec86da869526312f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include <chrono>
#include <stdint.h>
namespace search {
/**
* Stats on the usage and availability of lids in a document meta store.
*/
class LidUsageStats {
public:
using TimePoint = std::chrono::time_point<std::chrono::steady_clock>;
private:
uint32_t _lidLimit;
uint32_t _usedLids;
uint32_t _lowestFreeLid;
uint32_t _highestUsedLid;
public:
LidUsageStats() noexcept
: _lidLimit(0),
_usedLids(0),
_lowestFreeLid(0),
_highestUsedLid(0)
{
}
LidUsageStats(uint32_t lidLimit,
uint32_t usedLids,
uint32_t lowestFreeLid,
uint32_t highestUsedLid) noexcept
: _lidLimit(lidLimit),
_usedLids(usedLids),
_lowestFreeLid(lowestFreeLid),
_highestUsedLid(highestUsedLid)
{
}
uint32_t getLidLimit() const { return _lidLimit; }
uint32_t getUsedLids() const { return _usedLids; }
uint32_t getLowestFreeLid() const { return _lowestFreeLid; }
uint32_t getHighestUsedLid() const { return _highestUsedLid; }
uint32_t getLidBloat() const {
// Account for reserved lid 0
int32_t lidBloat = getLidLimit() - getUsedLids() - 1;
if (lidBloat < 0) {
return 0u;
}
return lidBloat;
}
double getLidBloatFactor() const {
return (double)getLidBloat() / (double)getLidLimit();
}
double getLidFragmentationFactor() const {
int32_t freeLids = getHighestUsedLid() - getUsedLids();
if (freeLids < 0) {
return 0;
}
if (getHighestUsedLid() == 0) {
return 0;
}
return (double)freeLids / (double)getHighestUsedLid();
}
};
}
|