예제 #1
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;
}
예제 #2
0
void ThriftServer::updateTLSCert() {
  forEachWorker([&](wangle::Acceptor* acceptor) {
    if (!acceptor) {
      return;
    }
    auto evb = acceptor->getEventBase();
    if (!evb) {
      return;
    }
    evb->runInEventBaseThread(
        [acceptor] { acceptor->resetSSLContextConfigs(); });
  });
}
예제 #3
0
void ThriftServer::stopWorkers() {
  forEachWorker([&](wangle::Acceptor* acceptor) {
    if (auto worker = dynamic_cast<Cpp2Worker*>(acceptor)) {
      worker->requestStop();
    }
  });
  auto deadline = std::chrono::system_clock::now() + workersJoinTimeout_;
  forEachWorker([&](wangle::Acceptor* acceptor) {
    if (auto worker = dynamic_cast<Cpp2Worker*>(acceptor)) {
      worker->waitForStop(deadline);
    }
  });

  if (serverChannel_) {
    return;
  }
  DCHECK(!duplexWorker_);
  ServerBootstrap::stop();
  ServerBootstrap::join();
  sslHandshakePool_->join();
  configMutable_ = true;
}
예제 #4
0
void ThriftServer::updateTicketSeeds(wangle::TLSTicketKeySeeds seeds) {
  forEachWorker([&](wangle::Acceptor* acceptor) {
    if (!acceptor) {
      return;
    }
    auto evb = acceptor->getEventBase();
    if (!evb) {
      return;
    }
    evb->runInEventBaseThread([acceptor, seeds] {
      acceptor->setTLSTicketSecrets(
          seeds.oldSeeds, seeds.currentSeeds, seeds.newSeeds);
    });
  });
}
예제 #5
0
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;
}
예제 #6
0
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;
}