MXS-2555 Implement cache eviction (or query re-measurment) strategy

This commit is contained in:
Niclas Antti
2019-06-18 17:02:23 +03:00
parent f5615cc174
commit a950715176
4 changed files with 92 additions and 90 deletions

View File

@ -13,44 +13,6 @@
#include "performance.hh"
#include <cstdio>
#include <fstream>
#include <mutex>
const std::string file_version = "Alpha"; // if a file has a different version string, discard it.
CanonicalPerformance::CanonicalPerformance()
: m_nChanges(0)
{
}
bool CanonicalPerformance::insert(const std::string& canonical, const PerformanceInfo& perf)
{
bool saved = m_perfs.insert({canonical, perf}).second;
m_nChanges += saved;
return saved;
}
bool CanonicalPerformance::remove(const std::string& canonical)
{
auto erased = m_perfs.erase(canonical);
m_nChanges += erased;
return erased;
}
PerformanceInfo CanonicalPerformance::find(const std::string& canonical)
{
auto it = m_perfs.find(canonical);
return it == m_perfs.end() ? PerformanceInfo() : it->second;
}
void CanonicalPerformance::clear()
{
m_perfs.clear();
m_nChanges = 0;
}
std::string show_some(const std::string& str, int nchars)
{
int sz = str.length();
@ -64,7 +26,6 @@ std::string show_some(const std::string& str, int nchars)
}
}
// These are TODOs for the GA version. The Beta version will not have persistence.
// 1. Read the file once at startup. There might also be a need to do cleanup
// of the file if the configuration has changed.
@ -78,11 +39,3 @@ std::string show_some(const std::string& str, int nchars)
// probably be dropped immediately.
// 6. Save all data at shutdown.
// Start using xxhash
//
// Expiration rules. At least these rules should be implemented:
// 1. Since the various engines have different setup times during the first few queries,
// this should be taken into account (not implemented).
// 2. Expire entries after X minutes.
// 3. If the measured time is very different from the stored one (+/20%),
// expire the entry (not implemented).
// More rules can be found out by testing.