int64_t ThriftServer::getLoad(const std::string& counter, bool check_custom) { if (check_custom && getLoad_) { return getLoad_(counter); } int reqload = 0; int connload = 0; int queueload = 0; if (maxRequests_ > 0) { reqload = (100*(activeRequests_ + getPendingCount())) / ((float)maxRequests_); } auto ioGroup = getIOGroupSafe(); auto workerFactory = ioGroup != nullptr ? std::dynamic_pointer_cast<wangle::NamedThreadFactory>( ioGroup->getThreadFactory()) : nullptr; if (maxConnections_ > 0) { int32_t connections = 0; forEachWorker([&](wangle::Acceptor* acceptor) mutable { auto worker = dynamic_cast<Cpp2Worker*>(acceptor); connections += worker->getPendingCount(); }); connload = (100*connections) / (float)maxConnections_; } auto tm = getThreadManager(); if (tm) { auto codel = tm->getCodel(); if (codel) { queueload = codel->getLoad(); } } if (VLOG_IS_ON(1) && workerFactory) { FB_LOG_EVERY_MS(INFO, 1000 * 10) << workerFactory->getNamePrefix() << " load is: " << reqload << "% requests, " << connload << "% connections, " << queueload << "% queue time, " << activeRequests_ << " active reqs, " << getPendingCount() << " pending reqs"; } int load = std::max({reqload, connload, queueload}); return load; }
int64_t ThriftServer::getRequestLoad() { if (maxRequests_ > 0) { return (100*(activeRequests_ + getPendingCount())) / ((float)maxRequests_); } return 0; }
int32_t ThriftServer::getPendingCount() const { int32_t count = 0; if (!getIOGroupSafe()) { // Not enabled in duplex mode return 0; } forEachWorker([&](wangle::Acceptor* acceptor) { auto worker = dynamic_cast<Cpp2Worker*>(acceptor); count += worker->getPendingCount(); }); return count; }
bool ThriftServer::isOverloaded(uint32_t workerActiveRequests) { if (UNLIKELY(isOverloaded_())) { return true; } if (maxRequests_ > 0) { if (isUnevenLoad_) { return globalActiveRequests_ + getPendingCount() >= maxRequests_; } else { return workerActiveRequests >= maxRequests_ / nWorkers_; } } return false; }
int64_t ThriftServer::getConnectionLoad() { auto ioGroup = getIOGroupSafe(); auto workerFactory = ioGroup != nullptr ? std::dynamic_pointer_cast<wangle::NamedThreadFactory>( ioGroup->getThreadFactory()) : nullptr; if (maxConnections_ > 0) { int32_t connections = 0; forEachWorker([&](wangle::Acceptor* acceptor) mutable { auto worker = dynamic_cast<Cpp2Worker*>(acceptor); connections += worker->getPendingCount(); }); return (100*connections) / (float)maxConnections_; } return 0; }
std::string ThriftServer::getLoadInfo(int64_t reqload, int64_t connload, int64_t queueload) { auto ioGroup = getIOGroupSafe(); auto workerFactory = ioGroup != nullptr ? std::dynamic_pointer_cast<wangle::NamedThreadFactory>( ioGroup->getThreadFactory()) : nullptr; if (!workerFactory) { return ""; } std::stringstream stream; stream << workerFactory->getNamePrefix() << " load is: " << reqload << "% requests, " << connload << "% connections, " << queueload << "% queue time, " << activeRequests_ << " active reqs, " << getPendingCount() << " pending reqs"; return stream.str(); }