Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::TemporaryFileCompressionAdaptivity Class Reference
Collaboration diagram for duckdb::TemporaryFileCompressionAdaptivity:

Public Member Functions

TemporaryCompressionLevel GetCompressionLevel ()
 Get the compression level to use based on current write times.
void Update (TemporaryCompressionLevel level, int64_t time_before_ns)
 Update write time for given compression level.

Static Public Member Functions

static int64_t GetCurrentTimeNanos ()
 Get current time in nanoseconds to measure write times.

Static Private Member Functions

static TemporaryCompressionLevel IndexToLevel (idx_t index)
 Convert from level to index into write time array and back.
static idx_t LevelToIndex (TemporaryCompressionLevel level)
static TemporaryCompressionLevel MinimumCompressionLevel ()
 Min/max compression levels.
static TemporaryCompressionLevel MaximumCompressionLevel ()

Private Attributes

RandomEngine random_engine
 Random engine to (sometimes) randomize compression.
int64_t last_uncompressed_write_ns
 Duration of the last uncompressed write.
int64_t last_compressed_writes_ns [LEVELS]
 Duration of the last compressed writes.

Static Private Attributes

static constexpr int64_t INITIAL_NS = 50000
 The value to initialize the atomic write counters to.
static constexpr idx_t LEVELS = 6
 How many compression levels we adapt between.
static constexpr double DURATION_RATIO_THRESHOLD = 2.0
 Bias towards compressed writes: we only choose uncompressed if it is more than 2x faster than compressed.
static constexpr double COMPRESSION_DEVIATION = 0.5
 Probability to deviate from the current best write behavior (1 in 20).
static constexpr int64_t WEIGHT = 16
 Weight to use for moving weighted average.

Constructor & Destructor Documentation

◆ TemporaryFileCompressionAdaptivity()

duckdb::TemporaryFileCompressionAdaptivity::TemporaryFileCompressionAdaptivity ( )
443067 for (idx_t i = 0; i < LEVELS; i++) {
443069 }
443070}
int64_t last_uncompressed_write_ns
Duration of the last uncompressed write.
Definition duckdb.cpp:61740
static constexpr idx_t LEVELS
How many compression levels we adapt between.
Definition duckdb.cpp:61729
static constexpr int64_t INITIAL_NS
The value to initialize the atomic write counters to.
Definition duckdb.cpp:61727
int64_t last_compressed_writes_ns[LEVELS]
Duration of the last compressed writes.
Definition duckdb.cpp:61742
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

Member Function Documentation

◆ GetCurrentTimeNanos()

int64_t duckdb::TemporaryFileCompressionAdaptivity::GetCurrentTimeNanos ( )
static

Get current time in nanoseconds to measure write times.

443072 {
443073 return duration_cast<nanoseconds>(high_resolution_clock::now().time_since_epoch()).count();
443074}
Here is the caller graph for this function:

◆ GetCompressionLevel()

TemporaryCompressionLevel duckdb::TemporaryFileCompressionAdaptivity::GetCompressionLevel ( )

Get the compression level to use based on current write times.

443092 {
443093 idx_t min_compression_idx = 0;
443094 TemporaryCompressionLevel level;
443095
443096 double ratio;
443097 bool should_compress;
443098
443099 bool should_deviate;
443100 bool deviate_uncompressed;
443101 {
443102 lock_guard<mutex> guard(random_engine.lock);
443103
443104 auto min_compressed_time = last_compressed_writes_ns[min_compression_idx];
443105 for (idx_t compression_idx = 1; compression_idx < LEVELS; compression_idx++) {
443106 const auto time = last_compressed_writes_ns[compression_idx];
443107 if (time < min_compressed_time) {
443108 min_compression_idx = compression_idx;
443109 min_compressed_time = time;
443110 }
443111 }
443112 level = IndexToLevel(min_compression_idx);
443113
443114 ratio = static_cast<double>(min_compressed_time) / static_cast<double>(last_uncompressed_write_ns);
443115 should_compress = ratio < DURATION_RATIO_THRESHOLD;
443116
443117 should_deviate = random_engine.NextRandom() < COMPRESSION_DEVIATION;
443118 deviate_uncompressed = random_engine.NextRandom() < 0.5; // Coin flip to deviate with just uncompressed
443119 }
443120
443121 TemporaryCompressionLevel result;
443122 if (!should_deviate) {
443123 result = should_compress ? level : TemporaryCompressionLevel::UNCOMPRESSED; // Don't deviate
443124 } else if (!should_compress) {
443125 result = MinimumCompressionLevel(); // Deviate from uncompressed -> go to fastest level
443126 } else if (deviate_uncompressed) {
443127 result = TemporaryCompressionLevel::UNCOMPRESSED;
443128 } else if (level == MaximumCompressionLevel()) {
443129 result = IndexToLevel(min_compression_idx - 1); // At highest level, go down one
443130 } else if (ratio < 1.0) { // Compressed writes are faster, try increasing the compression level
443131 result = IndexToLevel(min_compression_idx + 1);
443132 } else { // Compressed writes are slower, try decreasing the compression level
443133 result = level == MinimumCompressionLevel()
443134 ? TemporaryCompressionLevel::UNCOMPRESSED // Already lowest level, go to uncompressed
443135 : IndexToLevel(min_compression_idx - 1);
443136 }
443137 return result;
443138}
static constexpr double COMPRESSION_DEVIATION
Probability to deviate from the current best write behavior (1 in 20).
Definition duckdb.cpp:61733
static TemporaryCompressionLevel IndexToLevel(idx_t index)
Convert from level to index into write time array and back.
Definition duckdb.cpp:443076
static constexpr double DURATION_RATIO_THRESHOLD
Bias towards compressed writes: we only choose uncompressed if it is more than 2x faster than compres...
Definition duckdb.cpp:61731
RandomEngine random_engine
Random engine to (sometimes) randomize compression.
Definition duckdb.cpp:61738
static TemporaryCompressionLevel MinimumCompressionLevel()
Min/max compression levels.
Definition duckdb.cpp:443084
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Update()

void duckdb::TemporaryFileCompressionAdaptivity::Update ( TemporaryCompressionLevel level,
int64_t time_before_ns )

Update write time for given compression level.

443140 {
443141 const auto duration = GetCurrentTimeNanos() - time_before_ns;
443142 auto &last_write_ns = level == TemporaryCompressionLevel::UNCOMPRESSED
443144 : last_compressed_writes_ns[LevelToIndex(level)];
443145 lock_guard<mutex> guard(random_engine.lock);
443146 last_write_ns = (last_write_ns * (WEIGHT - 1) + duration) / WEIGHT;
443147}
static constexpr int64_t WEIGHT
Weight to use for moving weighted average.
Definition duckdb.cpp:61735
static int64_t GetCurrentTimeNanos()
Get current time in nanoseconds to measure write times.
Definition duckdb.cpp:443072
Here is the call graph for this function:

◆ IndexToLevel()

TemporaryCompressionLevel duckdb::TemporaryFileCompressionAdaptivity::IndexToLevel ( idx_t index)
staticprivate

Convert from level to index into write time array and back.

443076 {
443077 return static_cast<TemporaryCompressionLevel>(NumericCast<int>(index) * 2 - 5);
443078}
Here is the caller graph for this function:

◆ LevelToIndex()

idx_t duckdb::TemporaryFileCompressionAdaptivity::LevelToIndex ( TemporaryCompressionLevel level)
staticprivate
443080 {
443081 return NumericCast<idx_t>((static_cast<int>(level) + 5) / 2);
443082}

◆ MinimumCompressionLevel()

TemporaryCompressionLevel duckdb::TemporaryFileCompressionAdaptivity::MinimumCompressionLevel ( )
staticprivate

Min/max compression levels.

443084 {
443085 return IndexToLevel(0);
443086}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MaximumCompressionLevel()

TemporaryCompressionLevel duckdb::TemporaryFileCompressionAdaptivity::MaximumCompressionLevel ( )
staticprivate
443088 {
443089 return IndexToLevel(LEVELS - 1);
443090}

The documentation for this class was generated from the following file: