Commit e91c3bab authored by Axel Auweter's avatar Axel Auweter
Browse files

Add a sensor property cache to speed up evaluation of virtual sensors by ~25%.

parent e51407fb
......@@ -7,6 +7,7 @@
#include <list>
#include <string>
#include <unordered_map>
#include "cassandra.h"
......@@ -27,6 +28,9 @@ protected:
Connection* connection;
CassSession* session;
typedef std::unordered_map<std::string, PublicSensor> SensorPropertyCache_t;
static SensorPropertyCache_t sensorPropertyCache;
bool validateSensorPattern(const char* sensorPattern);
bool validateSensorPublicName(std::string publicName);
......
......@@ -11,6 +11,7 @@
#include <string>
#include <list>
#include <unordered_set>
#include <utility>
#include "cassandra.h"
......@@ -150,8 +151,9 @@ SensorConfig::~SensorConfig()
}
/*
* SensorConfigImpl protected functions
* SensorConfigImpl protected members and functions
*/
SensorConfigImpl::SensorPropertyCache_t SensorConfigImpl::sensorPropertyCache;
/*
* Validate the pattern for a Sensor to be published
......@@ -600,6 +602,14 @@ SCError SensorConfigImpl::getPublicSensorsVerbose(std::list<PublicSensor>& publi
SCError SensorConfigImpl::getPublicSensorByName(PublicSensor& sensor, const char* publicName)
{
/* Check if the sensor definition is already in the cache */
SensorPropertyCache_t::const_iterator got = sensorPropertyCache.find(publicName);
if (got != sensorPropertyCache.end()) {
sensor = got->second;
return SC_OK;
}
/* Not in cache - query the data base */
/* Check if the session is valid */
if (!session) {
return SC_INVALIDSESSION;
......@@ -702,6 +712,8 @@ SCError SensorConfigImpl::getPublicSensorByName(PublicSensor& sensor, const char
sensor.t_zero = tzero;
sensor.frequency = frequency;
/* Add to sensorPropertyCache for later use */
sensorPropertyCache.insert(std::make_pair(publicName, sensor));
}
else {
cass_result_free(result);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment