org.eclipse.jetty.client.HttpClient.setMaxConnectionsPerDestination()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(10.7k)|赞(0)|评价(0)|浏览(204)

本文整理了Java中org.eclipse.jetty.client.HttpClient.setMaxConnectionsPerDestination()方法的一些代码示例,展示了HttpClient.setMaxConnectionsPerDestination()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpClient.setMaxConnectionsPerDestination()方法的具体详情如下:
包路径:org.eclipse.jetty.client.HttpClient
类名称:HttpClient
方法名:setMaxConnectionsPerDestination

HttpClient.setMaxConnectionsPerDestination介绍

[英]Sets the max number of connections to open to each destinations.

RFC 2616 suggests that 2 connections should be opened per each destination, but browsers commonly open 6. If this HttpClient is used for load testing, it is common to have only one destination (the server to load test), and it is recommended to set this value to a high value (at least as much as the threads present in the #getExecutor()).
[中]设置要打开到每个目标的最大连接数。
RFC2616建议每个目的地应打开2个连接,但浏览器通常打开6个。如果此HttpClient用于负载测试,通常只有一个目标(要进行负载测试的服务器),建议将此值设置为高值(至少与#getExecutor()中存在的线程相同)。

代码示例

代码示例来源:origin: apache/incubator-druid

httpClient.setMaxConnectionsPerDestination(config.getNumConnections());
httpClient.setMaxRequestsQueuedPerDestination(config.getNumRequestsQueued());
httpClient.setConnectTimeout(CLIENT_CONNECT_TIMEOUT_MILLIS);

代码示例来源:origin: sixt/ja-micro

private HttpClient createHttpClient() {
  SslContextFactory sslContextFactory = new SslContextFactory();
  sslContextFactory.setExcludeCipherSuites("");
  HttpClient client = new HttpClient(sslContextFactory);
  client.setFollowRedirects(false);
  client.setMaxConnectionsPerDestination(2);
  //You can set more restrictive timeouts per request, but not less, so
  //  we set the maximum timeout of 1 hour here.
  client.setIdleTimeout(60 * 60 * 1000);
  try {
    client.start();
  } catch (Exception e) {
    logger.error("Error building http client", e);
  }
  return client;
}

代码示例来源:origin: sixt/ja-micro

@Provides
public HttpClient getHttpClient() {
  HttpClient client = new HttpClient();
  client.setFollowRedirects(false);
  client.setMaxConnectionsPerDestination(32);
  client.setConnectTimeout(100);
  client.setAddressResolutionTimeout(100);
  //You can set more restrictive timeouts per request, but not less, so
  //  we set the maximum timeout of 1 hour here.
  client.setIdleTimeout(60 * 60 * 1000);
  try {
    client.start();
  } catch (Exception e) {
    logger.error("Error building http client", e);
  }
  return client;
}

代码示例来源:origin: sixt/ja-micro

private HttpClient createHttpClient() {
  //Allow ssl by default
  SslContextFactory sslContextFactory = new SslContextFactory();
  //Don't exclude RSA because Sixt needs them, dammit!
  sslContextFactory.setExcludeCipherSuites("");
  HttpClient client = new HttpClient(sslContextFactory);
  client.setFollowRedirects(false);
  client.setMaxConnectionsPerDestination(16);
  client.setRequestBufferSize(65536);
  client.setConnectTimeout(FeatureFlags.getHttpConnectTimeout(serviceProperties));
  client.setAddressResolutionTimeout(FeatureFlags.getHttpAddressResolutionTimeout(serviceProperties));
  //You can set more restrictive timeouts per request, but not less, so
  //  we set the maximum timeout of 1 hour here.
  client.setIdleTimeout(60 * 60 * 1000);
  try {
    client.start();
  } catch (Exception e) {
    logger.error("Error building http client", e);
  }
  return client;
}

代码示例来源:origin: labsai/EDDI

@Provides
@Singleton
public HttpClient provideHttpClient(ExecutorService executorService,
                  @Named("httpClient.maxConnectionsQueued") Integer maxConnectionsQueued,
                  @Named("httpClient.maxConnectionPerRoute") Integer maxConnectionPerRoute,
                  @Named("httpClient.requestBufferSize") Integer requestBufferSize,
                  @Named("httpClient.responseBufferSize") Integer responseBufferSize,
                  @Named("httpClient.maxRedirects") Integer maxRedirects,
                  @Named("httpClient.trustAllCertificates") Boolean trustAllCertificates) {
  try {
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setTrustAll(trustAllCertificates);
    HttpClient httpClient = new HttpClient(sslContextFactory);
    httpClient.setExecutor(executorService);
    httpClient.setMaxConnectionsPerDestination(maxConnectionsQueued);
    httpClient.setMaxRequestsQueuedPerDestination(maxConnectionPerRoute);
    httpClient.setRequestBufferSize(requestBufferSize);
    httpClient.setResponseBufferSize(responseBufferSize);
    httpClient.setMaxRedirects(maxRedirects);
    httpClient.start();
    registerHttpClientShutdownHook(httpClient);
    return httpClient;
  } catch (Exception e) {
    System.out.println(Arrays.toString(e.getStackTrace()));
    throw new RuntimeException(e.getLocalizedMessage(), e);
  }
}

代码示例来源:origin: openhab/openhab-core

@Override
  public HttpClient run() {
    if (logger.isDebugEnabled()) {
      if (endpoint == null) {
        logger.debug("creating http client for consumer {}", consumerName);
      } else {
        logger.debug("creating http client for consumer {}, endpoint {}", consumerName, endpoint);
      }
    }
    HttpClient httpClient = new HttpClient(createSslContextFactory(endpoint));
    httpClient.setMaxConnectionsPerDestination(2);
    if (threadPool != null) {
      httpClient.setExecutor(threadPool);
    } else {
      final QueuedThreadPool queuedThreadPool = createThreadPool(consumerName, minThreadsCustom,
          maxThreadsCustom, keepAliveTimeoutCustom);
      httpClient.setExecutor(queuedThreadPool);
    }
    if (startClient) {
      try {
        httpClient.start();
      } catch (Exception e) {
        logger.error("Could not start Jetty http client", e);
        throw new HttpClientInitializationException("Could not start Jetty http client", e);
      }
    }
    return httpClient;
  }
});

代码示例来源:origin: danielflower/app-runner

private HttpClient createClient() throws Exception {
  int selectors = Math.max(1, Runtime.getRuntime().availableProcessors() / 2);
  HttpClient client = new HttpClient(new HttpClientTransportOverHTTP(selectors), new SslContextFactory(true));
  client.setFollowRedirects(false);
  client.setCookieStore(new HttpCookieStore.Empty());
  client.setMaxConnectionsPerDestination(256);
  client.setAddressResolutionTimeout(15000);
  client.setConnectTimeout(15000);
  client.setIdleTimeout(idleTimeout);
  client.setUserAgentField(null);
  client.start();
  client.getContentDecoderFactories().clear();
  return client;
}

代码示例来源:origin: org.apache.pulsar/pulsar-proxy

if (value == null)
  value = "256";
client.setMaxConnectionsPerDestination(Integer.parseInt(value));

代码示例来源:origin: org.eclipse.jetty/jetty-proxy

if (value == null)
  value = "256";
client.setMaxConnectionsPerDestination(Integer.parseInt(value));

代码示例来源:origin: isucon/isucon5-qualify

private HttpClient client() {
 HttpField agent = new HttpField("User-Agent", config.agent);
 HttpClient httpClient = new HttpClient();
 httpClient.setFollowRedirects(false);
 httpClient.setMaxConnectionsPerDestination(MAX_CONNECTIONS_PER_DEST);
 httpClient.setMaxRequestsQueuedPerDestination(MAX_QUEUED_REQUESTS_PER_DEST);
 httpClient.setUserAgentField(agent);
 httpClient.setCookieStore(new HttpCookieStore.Empty());
 return httpClient;
}

代码示例来源:origin: isucon/isucon5-final

private HttpClient client() {
  HttpField agent = new HttpField("User-Agent", config.agent);
  // TODO: non-keepalived client connections
  HttpClient httpClient = new HttpClient();
  httpClient.setFollowRedirects(false);
  httpClient.setMaxConnectionsPerDestination(MAX_CONNECTIONS_PER_DEST);
  httpClient.setMaxRequestsQueuedPerDestination(MAX_QUEUED_REQUESTS_PER_DEST);
  httpClient.setUserAgentField(agent);
  httpClient.setCookieStore(new HttpCookieStore.Empty());
  return httpClient;
}

代码示例来源:origin: io.druid/druid-server

httpClient.setMaxConnectionsPerDestination(config.getNumConnections());
httpClient.setMaxRequestsQueuedPerDestination(config.getNumRequestsQueued());
httpClient.setConnectTimeout(CLIENT_CONNECT_TIMEOUT);

代码示例来源:origin: org.apache.druid/druid-server

httpClient.setMaxConnectionsPerDestination(config.getNumConnections());
httpClient.setMaxRequestsQueuedPerDestination(config.getNumRequestsQueued());
httpClient.setConnectTimeout(CLIENT_CONNECT_TIMEOUT_MILLIS);

代码示例来源:origin: com.cisco.oss.foundation/http-client-jetty

@Override
protected void configureClient() {
  boolean addSslSupport = StringUtils.isNotEmpty(metadata.getKeyStorePath()) && StringUtils.isNotEmpty(metadata.getKeyStorePassword());
  if(addSslSupport){
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath(metadata.getKeyStorePath());
    sslContextFactory.setKeyStorePassword(metadata.getKeyStorePassword());
    boolean addTrustSupport = StringUtils.isNotEmpty(metadata.getTrustStorePath()) && StringUtils.isNotEmpty(metadata.getTrustStorePassword());
    if(addTrustSupport){
      sslContextFactory.setTrustStorePath(metadata.getTrustStorePath());
      sslContextFactory.setTrustStorePassword(metadata.getTrustStorePassword());
    }else{
      sslContextFactory.setTrustAll(true);
    }
    httpClient = new  HttpClient(sslContextFactory);
  }
  httpClient.setConnectTimeout(metadata.getConnectTimeout());
  httpClient.setIdleTimeout(metadata.getIdleTimeout());
  httpClient.setMaxConnectionsPerDestination(metadata.getMaxConnectionsPerAddress());
  httpClient.setMaxRequestsQueuedPerDestination(metadata.getMaxQueueSizePerAddress());
  httpClient.setFollowRedirects(followRedirects);
  try {
    httpClient.start();
  } catch (Exception e) {
    throw new ClientException("failed to start jetty http client: " + e, e);
  }
}

代码示例来源:origin: allegro/hermes

public HttpClient createClientForHttp1(String name) {
  ExecutorService executor = executorFactory.getExecutorService(name,
      configFactory.getIntProperty(CONSUMER_HTTP_CLIENT_THREAD_POOL_SIZE),
      configFactory.getBooleanProperty(CONSUMER_HTTP_CLIENT_THREAD_POOL_MONITORING));
  HttpClient client = new HttpClient(createSslContextFactory());
  client.setMaxConnectionsPerDestination(configFactory.getIntProperty(CONSUMER_HTTP_CLIENT_MAX_CONNECTIONS_PER_DESTINATION));
  client.setMaxRequestsQueuedPerDestination(configFactory.getIntProperty(CONSUMER_INFLIGHT_SIZE));
  client.setExecutor(executor);
  client.setCookieStore(new HttpCookieStore.Empty());
  return client;
}

代码示例来源:origin: pl.allegro.tech.hermes/hermes-consumers

public HttpClient createClientForHttp1(String name) {
  ExecutorService executor = executorFactory.getExecutorService(name,
      configFactory.getIntProperty(CONSUMER_HTTP_CLIENT_THREAD_POOL_SIZE),
      configFactory.getBooleanProperty(CONSUMER_HTTP_CLIENT_THREAD_POOL_MONITORING));
  HttpClient client = new HttpClient(createSslContextFactory());
  client.setMaxConnectionsPerDestination(configFactory.getIntProperty(CONSUMER_HTTP_CLIENT_MAX_CONNECTIONS_PER_DESTINATION));
  client.setMaxRequestsQueuedPerDestination(configFactory.getIntProperty(CONSUMER_INFLIGHT_SIZE));
  client.setExecutor(executor);
  client.setCookieStore(new HttpCookieStore.Empty());
  return client;
}

代码示例来源:origin: org.attribyte/attribyte-http

this.httpClient.setFollowRedirects(options.followRedirects);
this.httpClient.setConnectTimeout(options.connectionTimeoutMillis);
this.httpClient.setMaxConnectionsPerDestination(options.maxConnectionsPerDestination);
this.httpClient.setCookieStore(new HttpCookieStore.Empty());
if(options.proxyHost != null) {

代码示例来源:origin: airlift/airlift

httpClient.setMaxConnectionsPerDestination(config.getMaxConnectionsPerServer());
httpClient.setMaxRequestsQueuedPerDestination(config.getMaxRequestsQueuedPerDestination());

代码示例来源:origin: com.proofpoint.platform/http-client

httpClient.setMaxConnectionsPerDestination(config.getMaxConnectionsPerServer());

相关文章

HttpClient类方法