Какие есть способы подключения клиента за 30 миллисекунд для отправки почтового запроса. Как производитель, так и потребитель находятся в одном регионе AWS и в одном и том же VPC.
Я написал пример клиента, но он занимает более 30 миллисекунд. Клиент в том же vpc запрашивает сервер с частным IP-адресом.
Клиент работает на 2 экземплярах.
Логика сервера занимает менее 10 мс. Это просто подключит Redis и отправит ответ.
Пожалуйста, сообщите, каковы возможные способы установления соединения за 30 миллисекунд, если и потребитель, и производитель находятся на одном и том же VPC и в одном регионе AWS.
HttpPost httpPost = new HttpPost(
"elb/endpoint");
httpPost.addHeader("Accept", "application/json");
httpPost.addHeader("Content-Type", "application/json");
String stringRequest = request.toString();
StringEntity stringEntity = new StringEntity(stringRequest, Charsets.UTF_8);
httpPost.setConfig(getRequestConfig());
httpPost.setEntity(stringEntity);
logger.info("Client sent time");
long start = System.currentTimeMillis();
try (CloseableHttpClient client = getCloseableClient();
CloseableHttpResponse httpResponse = client.execute(httpPost)) {
logger.info("Client received time");
long endTime = System.currentTimeMillis();
HttpEntity httpEntity = httpResponse.getEntity();
responses = EntityUtils.toString(httpEntity, "UTF-8");
long duration = endTime - start;
report.duration = duration;
report.scriptTime = entity.processTime;
} catch (Exception ex) {
throw new Exception(ex.getMessage());
}
private RequestConfig getRequestConfig() {
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(socketTimeout)
.setConnectTimeout(connectTimeout).build();
return requestConfig;
}
private CloseableHttpClient getCloseableClient() {
CloseableHttpClient httpClient = null;
long startTime = System.currentTimeMillis();
try {
initSSLSocketFactory();
Registry<ConnectionSocketFactory> r = RegistryBuilder.<ConnectionSocketFactory> create()
.register("http", PlainConnectionSocketFactory.getSocketFactory())
.register("https", sslSocketFactory).build();
HttpClientConnectionManager connMgr = pooling
? new PoolingHttpClientConnectionManager(r)
: new BasicHttpClientConnectionManager(r);
HttpClientBuilder builder = HttpClients.custom();
builder.setConnectionManager(connMgr);
httpClient = builder.build();
long endTime = System.currentTimeMillis();
long getCloseableClientTime = endTime - startTime;
logger.info("getCloseableClientTime method {}", getCloseableClientTime);
return httpClient;
} catch (Exception ex) {
}
return httpClient;
}
private SSLConnectionSocketFactory initSSLSocketFactory() {
if (sslSocketFactory == null) {
try {
TrustStrategy trustStrategy = new TrustSelfSignedStrategy();
SSLContextBuilder sslContextBuilder = SSLContexts.custom()
.loadTrustMaterial(trustStrategy);
SSLContext sslContext = sslContextBuilder.build();
sslSocketFactory = new SSLConnectionSocketFactory(sslContext,
NoopHostnameVerifier.INSTANCE);
} catch (Exception e) {
String message = "Unable to create the SSL socket factory.";
}
}
return sslSocketFactory;
}