문서의 선택한 두 판 사이의 차이를 보여줍니다.
양쪽 이전 판 이전 판 다음 판 | 이전 판 | ||
java:apache_http_client [2014/01/13 20:45] kwon37xi |
java:apache_http_client [2021/07/27 10:26] kwon37xi |
||
---|---|---|---|
줄 2: | 줄 2: | ||
* [[http:// | * [[http:// | ||
* [[https:// | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | |||
+ | ===== Connection 갯수 ===== | ||
+ | * HttpClient는 하나의 IP 혹은 domain name에 대한 접속 갯수가 기본적으로 5개로 제한돼 있다. | ||
+ | * 고부하 서비스의 경우 이 갯수를 늘려줘야 한다. | ||
+ | <code java> | ||
+ | HttpClient httpClient = HttpClientBuilder.create().useSystemProperties() | ||
+ | .setMaxConnTotal([최대 커넥션 갯수]) | ||
+ | .setMaxConnPerRoute([IP/ | ||
+ | .... | ||
+ | </ | ||
===== Connection/ | ===== Connection/ | ||
- | * [[http:// | + | * [[http:// |
+ | int timeout = 5; | ||
+ | RequestConfig config = RequestConfig.custom() | ||
+ | .setConnectTimeout(timeout * 1000) | ||
+ | .setConnectionRequestTimeout(timeout * 1000) | ||
+ | .setSocketTimeout(timeout * 1000).build(); | ||
+ | CloseableHttpClient client = | ||
+ | HttpClientBuilder.create().setDefaultRequestConfig(config).build(); | ||
+ | </ | ||
+ | * connectionTimeout : 서버에 소켓 연결을 맺을 때의 타임아웃 | ||
+ | * connectionRequestTimeout : ConnectionManager(커넥션풀)로부터 꺼내올 때의 타임아웃 | ||
+ | * socketTimeout : 요청/ | ||
+ | |||
+ | ===== Evict Idle Connections ===== | ||
+ | * KeepAlive 설정이 있을 경우, 서버에서 KeepAlive 시간 동안 사용되지 않은 커넥션(idle connection)을 죽이는 일이 생고 이를 '' | ||
+ | * 클라이언트 측에서도 Idle Connection을 주기적으로 지워주면 된다. | ||
<code java> | <code java> | ||
- | DefaultHttpClient | + | HttpClient |
- | HttpParams params = httpClient.getParams(); | + | .evictIdleConnections(2000L, TimeUnit.MILLISECONDS) |
- | HttpConnectionParams.setConnectionTimeout(httpParams, connectionTimeoutMillis); | + | .... |
- | HttpConnectionParams.setSoTimeout(httpParams, socketTimeoutMillis); | + | .build(); |
</ | </ | ||
+ | * [[http:// | ||
+ | >> Please note this method has no effect if the instance of HttpClient is configuted to use a shared connection manager. | ||
+ | >> Please note this method may not be used when the instance of HttpClient is created inside an EJB container. | ||
===== Request Character Encoding ===== | ===== Request Character Encoding ===== | ||
==== 일반 ==== | ==== 일반 ==== | ||
줄 29: | 줄 60: | ||
</ | </ | ||
+ | ===== HttpAsyncClient ===== | ||
+ | |||
+ | * [[http:// | ||
+ | |||
+ | ===== Stale Check ===== | ||
+ | * Keep Alive 상태시 서버와 클라이언트 모두 접속중인 커넥션을 상대방에게 알리지 않고 접속을 끊을 수 있다. | ||
+ | * Stale Check에 대해 각 버전별 버그 여부 등을 확인하고 올바로 설정해야 한다. | ||
+ | * http:// | ||
+ | > HTTP specification permits both the client and the server to terminate a persistent (keep-alive) connection at any time without notice to the counterpart, | ||
+ | > | ||
+ | > See the http.connection.stalecheck parameter documentation for more information. | ||
+ | |||
+ | ===== 참조 ===== | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// |