Commit 5da108d7 authored by Carla Guillen's avatar Carla Guillen
Browse files

adding debug information, reducing the job cache, and optimizing the mysql...

adding debug information, reducing the job cache, and optimizing the mysql query (only one query instead of two)
parent 78d94c06
...@@ -93,6 +93,17 @@ Job_info_t * JobCache::find(const std::string uid, int number_of_nodes, const st ...@@ -93,6 +93,17 @@ Job_info_t * JobCache::find(const std::string uid, int number_of_nodes, const st
return nullptr; return nullptr;
} }
std::string JobCache::cache2String(){
std::stringstream out;
out << "JobCache Size=" << _jobCacheMap.size() << std::endl;
for(auto & kv: _jobCacheMap){
out << "\tJobId=" << kv.first << std::endl;
out << "\t\tjob_id_db=" << kv.second.job_id_db << std::endl;
out << "\t\tlast_seen_timestamp=" << kv.second.last_seen_timestamp << std::endl;
}
return out.str();
}
/**************MariaDB****************/ /**************MariaDB****************/
MariaDB * MariaDB::instance = nullptr; MariaDB * MariaDB::instance = nullptr;
...@@ -176,6 +187,7 @@ bool MariaDB::getDBJobID(const std::string & job_id_string, std::string& job_db_ ...@@ -176,6 +187,7 @@ bool MariaDB::getDBJobID(const std::string & job_id_string, std::string& job_db_
job_db_id = row[0]; job_db_id = row[0];
std::string job_id_string = std::string(row[1]); std::string job_id_string = std::string(row[1]);
_jobCache.addJobToCache(user, number_nodes, job_id_string, job_db_id); _jobCache.addJobToCache(user, number_nodes, job_id_string, job_db_id);
LOG(debug) << _jobCache.cache2String();
return true; //found return true; //found
} }
} }
...@@ -253,6 +265,7 @@ bool MariaDB::insertIntoJob(const std::string& job_id_string, const std::string& ...@@ -253,6 +265,7 @@ bool MariaDB::insertIntoJob(const std::string& job_id_string, const std::string&
if (row[0]) { if (row[0]) {
job_id_db = row[0]; job_id_db = row[0];
_jobCache.addJobToCache(uid, number_nodes, job_id_string, job_id_db); _jobCache.addJobToCache(uid, number_nodes, job_id_string, job_id_db);
LOG(debug) << _jobCache.cache2String();
job_found_in_db=true; job_found_in_db=true;
} }
} }
...@@ -273,6 +286,9 @@ bool MariaDB::insertIntoJob(const std::string& job_id_string, const std::string& ...@@ -273,6 +286,9 @@ bool MariaDB::insertIntoJob(const std::string& job_id_string, const std::string&
return false; return false;
} }
job_id_db = std::to_string(mysql_insert_id(_mysql)); job_id_db = std::to_string(mysql_insert_id(_mysql));
//insert into job cache here?
_jobCache.addJobToCache(uid, number_nodes, job_id_string, job_id_db);
LOG(debug) << _jobCache.cache2String();
} }
return true; return true;
} }
......
...@@ -54,10 +54,23 @@ struct Job_info_t { ...@@ -54,10 +54,23 @@ struct Job_info_t {
class JobCache { class JobCache {
private: private:
std::map<std::string, Job_info_t> _jobCacheMap; //< Job id string to job data std::map<std::string, Job_info_t> _jobCacheMap; //< Job id string to job data
const std::size_t JOB_CACHE_MAX_SIZE = 10000; const std::size_t JOB_CACHE_MAX_SIZE = 1000;
public: public:
/**
* Adds one job to cache, if cache is full, the job last seen will be removed
* so the new added job can feet in.
*/
void addJobToCache(const std::string uid, int number_of_nodes, const std::string &job_id_string, const std::string & job_id_db); void addJobToCache(const std::string uid, int number_of_nodes, const std::string &job_id_string, const std::string & job_id_db);
/**
* Find job in cache
*/
Job_info_t * find(const std::string uid, int number_of_nodes, const std::string &job_id_string); Job_info_t * find(const std::string uid, int number_of_nodes, const std::string &job_id_string);
/**
* Get entire cache as string for debugging
*/
std::string cache2String();
}; };
class MariaDB { class MariaDB {
......
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