runtime/runtime_impl_jetty9/src/main/java/com/google/apphosting/runtime/http/JettyHttpApiHostClient.java [72:116]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  static JettyHttpApiHostClient create(String url, Config config) {
    Preconditions.checkNotNull(url);
    HttpClient httpClient = new HttpClient();
    long idleTimeout = 58000; // 58 seconds, should be less than 60 used server-side.
    String envValue = System.getenv("APPENGINE_API_CALLS_IDLE_TIMEOUT_MS");
    if (envValue != null) {
      try {
        idleTimeout = Long.parseLong(envValue);
      } catch (NumberFormatException e) {
        logger.atWarning().withCause(e).log("Invalid idle timeout value: %s", envValue);
      }
    }
    httpClient.setIdleTimeout(idleTimeout);
    String schedulerName =
        HttpClient.class.getSimpleName() + "@" + httpClient.hashCode() + "-scheduler";
    ClassLoader myLoader = JettyHttpApiHostClient.class.getClassLoader();
    ThreadGroup myThreadGroup = Thread.currentThread().getThreadGroup();
    boolean daemon = false;
    Scheduler scheduler =
        new ScheduledExecutorScheduler(schedulerName, daemon, myLoader, myThreadGroup);
    ThreadFactory factory =
        runnable -> {
          Thread t = new Thread(myThreadGroup, runnable);
          t.setName("JettyHttpApiHostClient-" + threadCount.incrementAndGet());
          t.setDaemon(true);
          return t;
        };
    // By default HttpClient will use a QueuedThreadPool with minThreads=8 and maxThreads=200.
    // 8 threads is probably too much for most apps, especially since asynchronous I/O means that
    // 8 concurrent API requests probably don't need that many threads. It's also not clear
    // what advantage we'd get from using a QueuedThreadPool with a smaller minThreads value, versus
    // just one of the standard java.util.concurrent pools. Here we have minThreads=1, maxThreads=∞,
    // and idleTime=60 seconds. maxThreads=200 and maxThreads=∞ are probably equivalent in practice.
    httpClient.setExecutor(Executors.newCachedThreadPool(factory));
    httpClient.setScheduler(scheduler);
    config.maxConnectionsPerDestination().ifPresent(httpClient::setMaxConnectionsPerDestination);
    try {
      httpClient.start();
    } catch (RuntimeException e) {
      throw e;
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
    return new JettyHttpApiHostClient(url, httpClient, config);
  }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



runtime/runtime_impl_jetty12/src/main/java/com/google/apphosting/runtime/http/JettyHttpApiHostClient.java [72:116]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  static JettyHttpApiHostClient create(String url, Config config) {
    Preconditions.checkNotNull(url);
    HttpClient httpClient = new HttpClient();
    long idleTimeout = 58000; // 58 seconds, should be less than 60 used server-side.
    String envValue = System.getenv("APPENGINE_API_CALLS_IDLE_TIMEOUT_MS");
    if (envValue != null) {
      try {
        idleTimeout = Long.parseLong(envValue);
      } catch (NumberFormatException e) {
        logger.atWarning().withCause(e).log("Invalid idle timeout value: %s", envValue);
      }
    }
    httpClient.setIdleTimeout(idleTimeout);
    String schedulerName =
        HttpClient.class.getSimpleName() + "@" + httpClient.hashCode() + "-scheduler";
    ClassLoader myLoader = JettyHttpApiHostClient.class.getClassLoader();
    ThreadGroup myThreadGroup = Thread.currentThread().getThreadGroup();
    boolean daemon = false;
    Scheduler scheduler =
        new ScheduledExecutorScheduler(schedulerName, daemon, myLoader, myThreadGroup);
    ThreadFactory factory =
        runnable -> {
          Thread t = new Thread(myThreadGroup, runnable);
          t.setName("JettyHttpApiHostClient-" + threadCount.incrementAndGet());
          t.setDaemon(true);
          return t;
        };
    // By default HttpClient will use a QueuedThreadPool with minThreads=8 and maxThreads=200.
    // 8 threads is probably too much for most apps, especially since asynchronous I/O means that
    // 8 concurrent API requests probably don't need that many threads. It's also not clear
    // what advantage we'd get from using a QueuedThreadPool with a smaller minThreads value, versus
    // just one of the standard java.util.concurrent pools. Here we have minThreads=1, maxThreads=∞,
    // and idleTime=60 seconds. maxThreads=200 and maxThreads=∞ are probably equivalent in practice.
    httpClient.setExecutor(Executors.newCachedThreadPool(factory));
    httpClient.setScheduler(scheduler);
    config.maxConnectionsPerDestination().ifPresent(httpClient::setMaxConnectionsPerDestination);
    try {
      httpClient.start();
    } catch (RuntimeException e) {
      throw e;
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
    return new JettyHttpApiHostClient(url, httpClient, config);
  }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



