ApiListener::UpdateObjectAuthority(): distribute auth. by object's host

Pin child objects of hosts (HOST!...) to the same endpoint as the host.
This reduces cross-object action latency withing the same host.
If all endpoints know this algorithm, we can use it.
This commit is contained in:
Alexander A. Klimov 2024-09-18 17:45:00 +02:00
parent daab7d59ca
commit 2ac1d7bf65
3 changed files with 28 additions and 4 deletions

View File

@ -25,6 +25,7 @@ void ApiListener::UpdateObjectAuthority()
std::vector<Endpoint::Ptr> endpoints;
Endpoint::Ptr my_endpoint;
int hostChildrenInheritObjectAuthority = 0;
if (my_zone) {
my_endpoint = Endpoint::GetLocalEndpoint();
@ -51,6 +52,12 @@ void ApiListener::UpdateObjectAuthority()
return a->GetName() < b->GetName();
}
);
for (auto& endpoint : endpoints) {
if (endpoint == my_endpoint || endpoint->GetCapabilities() & (uint_fast64_t)ApiCapabilities::HostChildrenInheritObjectAuthority) {
++hostChildrenInheritObjectAuthority;
}
}
}
for (const Type::Ptr& type : Type::GetAllTypes()) {
@ -65,10 +72,24 @@ void ApiListener::UpdateObjectAuthority()
bool authority;
if (!my_zone)
if (my_zone) {
auto name (object->GetName());
// If all endpoints know this algorithm, we can use it.
if (hostChildrenInheritObjectAuthority == endpoints.size()) {
auto exclamation (name.FindFirstOf('!'));
// Pin child objects of hosts (HOST!...) to the same endpoint as the host.
// This reduces cross-object action latency withing the same host.
if (exclamation != String::NPos) {
name = name.SubStr(0, exclamation);
}
}
authority = endpoints[Utility::SDBM(name) % endpoints.size()] == my_endpoint;
} else {
authority = true;
else
authority = endpoints[Utility::SDBM(object->GetName()) % endpoints.size()] == my_endpoint;
}
#ifdef I2_DEBUG
// //Enable on demand, causes heavy logging on each run.

View File

@ -644,7 +644,9 @@ static const auto l_AppVersionInt (([]() -> unsigned long {
})());
static const auto l_MyCapabilities (
(uint_fast64_t)ApiCapabilities::ExecuteArbitraryCommand | (uint_fast64_t)ApiCapabilities::IfwApiCheckCommand
(uint_fast64_t)ApiCapabilities::ExecuteArbitraryCommand
| (uint_fast64_t)ApiCapabilities::IfwApiCheckCommand
| (uint_fast64_t)ApiCapabilities::HostChildrenInheritObjectAuthority
);
/**

View File

@ -69,6 +69,7 @@ enum class ApiCapabilities : uint_fast64_t
{
ExecuteArbitraryCommand = 1u << 0u,
IfwApiCheckCommand = 1u << 1u,
HostChildrenInheritObjectAuthority = 1u << 2u,
};
/**