inline AsyncMcServer::Options createAsyncMcServerOptions()

in mcrouter/Server-inl.h [165:237]


inline AsyncMcServer::Options createAsyncMcServerOptions(
    const McrouterOptions& mcrouterOpts,
    const McrouterStandaloneOptions& standaloneOpts,
    const std::vector<folly::EventBase*>* evb = nullptr) {
  AsyncMcServer::Options opts;

  if (standaloneOpts.listen_sock_fd >= 0) {
    opts.existingSocketFds = {standaloneOpts.listen_sock_fd};
  } else if (!standaloneOpts.unix_domain_sock.empty()) {
    opts.unixDomainSockPath = standaloneOpts.unix_domain_sock;
  } else {
    opts.listenAddresses = standaloneOpts.listen_addresses;
    opts.ports = standaloneOpts.ports;
    opts.sslPorts = standaloneOpts.ssl_ports;
    opts.tlsTicketKeySeedPath = standaloneOpts.tls_ticket_key_seed_path;
    opts.pemCertPath = standaloneOpts.server_pem_cert_path;
    opts.pemKeyPath = standaloneOpts.server_pem_key_path;
    opts.pemCaPath = standaloneOpts.server_pem_ca_path;
    opts.sslRequirePeerCerts = standaloneOpts.ssl_require_peer_certs;
    opts.tfoEnabledForSsl = mcrouterOpts.enable_ssl_tfo;
    opts.tfoQueueSize = standaloneOpts.tfo_queue_size;
    opts.worker.useKtls12 = standaloneOpts.ssl_use_ktls12;
  }

  opts.numThreads = mcrouterOpts.num_proxies;
  opts.numListeningSockets = standaloneOpts.num_listening_sockets;
  opts.worker.tcpZeroCopyThresholdBytes =
      standaloneOpts.tcp_zero_copy_threshold;

  size_t maxConns =
      opts.setMaxConnections(standaloneOpts.max_conns, opts.numThreads);
  if (maxConns > 0) {
    VLOG(1) << "The system will allow " << maxConns
            << " simultaneos connections before start closing connections"
            << " using an LRU algorithm";
  }

  if (standaloneOpts.enable_qos) {
    uint64_t qos = 0;
    if (getQoS(
            standaloneOpts.default_qos_class,
            standaloneOpts.default_qos_path,
            qos)) {
      opts.worker.trafficClass = qos;
    } else {
      VLOG(1) << "Incorrect qos class / qos path. Accepted connections will not"
              << "be marked.";
    }
  }

  opts.tcpListenBacklog = standaloneOpts.tcp_listen_backlog;
  opts.worker.defaultVersionHandler = false;
  opts.worker.maxInFlight = standaloneOpts.max_client_outstanding_reqs;
  opts.worker.sendTimeout =
      std::chrono::milliseconds{standaloneOpts.client_timeout_ms};
  if (!mcrouterOpts.debug_fifo_root.empty()) {
    opts.worker.debugFifoPath = getServerDebugFifoFullPath(mcrouterOpts);
  }

  if (standaloneOpts.server_load_interval_ms > 0) {
    opts.cpuControllerOpts.dataCollectionInterval =
        std::chrono::milliseconds(standaloneOpts.server_load_interval_ms);
  }

  /* Default to one read per event to help latency-sensitive workloads.
     We can make this an option if this needs to be adjusted. */
  opts.worker.maxReadsPerEvent = 1;

  if (evb) {
    opts.eventBases = (*evb);
  }
  return opts;
}