summaryrefslogtreecommitdiff
path: root/controller
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2017-04-26 10:35:59 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2017-04-26 10:35:59 -0700
commit7c184cf9919fb9d01b8279397e7b20fa756dc981 (patch)
tree1c94a4ad173ed25af7512974dbee90e4dd5e2e07 /controller
parent72def658d0ad8dda1e1735f6b28a7a0ec0235c22 (diff)
downloadinfinitytier-7c184cf9919fb9d01b8279397e7b20fa756dc981.tar.gz
infinitytier-7c184cf9919fb9d01b8279397e7b20fa756dc981.zip
Another performance improvement to controller.
Diffstat (limited to 'controller')
-rw-r--r--controller/JSONDB.cpp35
-rw-r--r--controller/JSONDB.hpp5
2 files changed, 27 insertions, 13 deletions
diff --git a/controller/JSONDB.cpp b/controller/JSONDB.cpp
index c8a31ab4..9b0dd836 100644
--- a/controller/JSONDB.cpp
+++ b/controller/JSONDB.cpp
@@ -26,7 +26,8 @@ static const nlohmann::json _EMPTY_JSON(nlohmann::json::object());
static const std::map<std::string,std::string> _ZT_JSONDB_GET_HEADERS;
JSONDB::JSONDB(const std::string &basePath) :
- _basePath(basePath)
+ _basePath(basePath),
+ _summaryThreadRun(true)
{
if ((_basePath.length() > 7)&&(_basePath.substr(0,7) == "http://")) {
// TODO: this doesn't yet support IPv6 since bracketed address notiation isn't supported.
@@ -67,14 +68,14 @@ JSONDB::~JSONDB()
Mutex::Lock _l(_networks_m);
_networks.clear();
}
+ Thread t;
{
Mutex::Lock _l(_summaryThread_m);
- if (_summaryThread) {
- _updateSummaryInfoQueue.post(0);
- _updateSummaryInfoQueue.post(0);
- Thread::join(_summaryThread);
- }
+ _summaryThreadRun = false;
+ t = _summaryThread;
}
+ if (t)
+ Thread::join(t);
}
bool JSONDB::writeRaw(const std::string &n,const std::string &obj)
@@ -197,10 +198,21 @@ nlohmann::json JSONDB::eraseNetworkMember(const uint64_t networkId,const uint64_
void JSONDB::threadMain()
throw()
{
- uint64_t networkId = 0;
- while ((networkId = _updateSummaryInfoQueue.get()) != 0) {
- const uint64_t now = OSUtils::now();
+ std::vector<uint64_t> todo;
+ while (_summaryThreadRun) {
+ Thread::sleep(10);
+
{
+ Mutex::Lock _l(_summaryThread_m);
+ if (_summaryThreadToDo.empty())
+ continue;
+ else _summaryThreadToDo.swap(todo);
+ }
+
+ const uint64_t now = OSUtils::now();
+ for(std::vector<uint64_t>::iterator ii(todo.begin());ii!=todo.end();++ii) {
+ const uint64_t networkId = *ii;
+
Mutex::Lock _l(_networks_m);
std::unordered_map<uint64_t,_NW>::iterator n(_networks.find(networkId));
if (n != _networks.end()) {
@@ -258,6 +270,8 @@ void JSONDB::threadMain()
n->second.summaryInfoLastComputed = now;
}
}
+
+ todo.clear();
}
}
@@ -334,9 +348,10 @@ bool JSONDB::_load(const std::string &p)
void JSONDB::_recomputeSummaryInfo(const uint64_t networkId)
{
Mutex::Lock _l(_summaryThread_m);
+ if (std::find(_summaryThreadToDo.begin(),_summaryThreadToDo.end(),networkId) == _summaryThreadToDo.end())
+ _summaryThreadToDo.push_back(networkId);
if (!_summaryThread)
_summaryThread = Thread::start(this);
- _updateSummaryInfoQueue.post(networkId);
}
std::string JSONDB::_genPath(const std::string &n,bool create)
diff --git a/controller/JSONDB.hpp b/controller/JSONDB.hpp
index 0883bd4b..55ead4ea 100644
--- a/controller/JSONDB.hpp
+++ b/controller/JSONDB.hpp
@@ -38,7 +38,6 @@
#include "../osdep/OSUtils.hpp"
#include "../osdep/Http.hpp"
#include "../osdep/Thread.hpp"
-#include "../osdep/BlockingQueue.hpp"
namespace ZeroTier {
@@ -171,9 +170,9 @@ private:
std::string _basePath;
InetAddress _httpAddr;
- BlockingQueue<uint64_t> _updateSummaryInfoQueue;
-
Thread _summaryThread;
+ std::vector<uint64_t> _summaryThreadToDo;
+ volatile bool _summaryThreadRun;
Mutex _summaryThread_m;
struct _NW