mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 12:33:44 +02:00
Memo-ize some computed stuff to control CPU utilization.
This commit is contained in:
parent
3d948a930e
commit
1ebfca666d
2 changed files with 52 additions and 29 deletions
|
@ -1535,6 +1535,9 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpDELETE(
|
||||||
return false; // delete
|
return false; // delete
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Mutex::Lock _l2(_nmiCache_m);
|
||||||
|
_nmiCache.erase(nwid);
|
||||||
|
|
||||||
responseBody = network.dump(2);
|
responseBody = network.dump(2);
|
||||||
responseContentType = "application/json";
|
responseContentType = "application/json";
|
||||||
return 200;
|
return 200;
|
||||||
|
@ -1614,6 +1617,16 @@ void EmbeddedNetworkController::_getNetworkMemberInfo(uint64_t now,uint64_t nwid
|
||||||
char pfx[256];
|
char pfx[256];
|
||||||
Utils::snprintf(pfx,sizeof(pfx),"network/%.16llx/member",nwid);
|
Utils::snprintf(pfx,sizeof(pfx),"network/%.16llx/member",nwid);
|
||||||
|
|
||||||
|
{
|
||||||
|
Mutex::Lock _l(_nmiCache_m);
|
||||||
|
std::map<uint64_t,_NetworkMemberInfo>::iterator c(_nmiCache.find(nwid));
|
||||||
|
if ((c != _nmiCache.end())&&((now - c->second.nmiTimestamp) < 1000)) { // a short duration cache but limits CPU use on big networks
|
||||||
|
nmi = c->second;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
Mutex::Lock _l(_db_m);
|
Mutex::Lock _l(_db_m);
|
||||||
_db.filter(pfx,120000,[&nmi,&now](const std::string &n,const json &member) {
|
_db.filter(pfx,120000,[&nmi,&now](const std::string &n,const json &member) {
|
||||||
try {
|
try {
|
||||||
|
@ -1651,6 +1664,13 @@ void EmbeddedNetworkController::_getNetworkMemberInfo(uint64_t now,uint64_t nwid
|
||||||
} catch ( ... ) {}
|
} catch ( ... ) {}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
nmi.nmiTimestamp = now;
|
||||||
|
|
||||||
|
{
|
||||||
|
Mutex::Lock _l(_nmiCache_m);
|
||||||
|
_nmiCache[nwid] = nmi;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ZeroTier
|
} // namespace ZeroTier
|
||||||
|
|
|
@ -96,7 +96,10 @@ private:
|
||||||
unsigned long activeMemberCount;
|
unsigned long activeMemberCount;
|
||||||
unsigned long totalMemberCount;
|
unsigned long totalMemberCount;
|
||||||
uint64_t mostRecentDeauthTime;
|
uint64_t mostRecentDeauthTime;
|
||||||
|
uint64_t nmiTimestamp; // time this NMI structure was computed
|
||||||
};
|
};
|
||||||
|
std::map<uint64_t,_NetworkMemberInfo> _nmiCache;
|
||||||
|
Mutex _nmiCache_m;
|
||||||
void _getNetworkMemberInfo(uint64_t now,uint64_t nwid,_NetworkMemberInfo &nmi);
|
void _getNetworkMemberInfo(uint64_t now,uint64_t nwid,_NetworkMemberInfo &nmi);
|
||||||
|
|
||||||
// These init objects with default and static/informational fields
|
// These init objects with default and static/informational fields
|
||||||
|
|
Loading…
Add table
Reference in a new issue