Hi,
Due to size parameter, my application performance decreasing completely.
No.of Nodes:1
Operating System : CentoOS 7
No.of Documents in ES : 1Million
No.of fields in Each Document : 15 fields.Each Fields involved three analyzer are phonetic,substring and exact.
Total Documents Size : 1GB
ElasticSearch Server version : 6.0.0
ElasticSearch Heap Memory : 16GB
ElasticSearch Client : Low level Rest Client of Java
BenchMarking reads :
Total no.of Request : 100000
1.Query : {"size":0,"_source":false"query":{"term":{"7":"Sekhar__1000009"}}}
Its processing 5555 request/sec .
2.Query : {"size":1,"_source":false"query":{"term":{"7":"Sekhar__1000009"}}}
Its processing 4166 request/sec .
3.Query : {"size":10000,"_source":false"query":{"term":{"7":"Sekhar__1000009"}}}
Its processing 2033 request/sec .
Note : 1 .Could you please explain why size parameter increasing/decreasing performance based on value.
2.Can you please share benckmarking reading of different match types(exact,word,phonetic,substring,fuzzy) it can very useful for me.
3.Please guide me how to improve the search performance.
Source Code :
package ElasticSearch.ESRestClientSample;
public class RestClientMain {
public static void main(String[] args) {
int count =100000;
String searchJson = {"size":0,"_source":false"query":{"term":{"7":"Subex__1000009"}}};
ElasticSearchRestClient elasticSearchRestClient = new ElasticSearchRestClient();
elasticSearchRestClient.search("14_1024", searchJson, count);
elasticSearchRestClient.closeRestClient();
}
}
package ElasticSearch.ESRestClientSample;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.ParseException;
import org.apache.http.entity.ContentType;
import org.apache.http.nio.entity.NStringEntity;
import org.apache.log4j.Logger;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.RestClient;
public class ElasticSearchRestClient {
private static RestClient restClient;
Map<String, String> emptyMap = Collections.emptyMap();
String httpOrHttps = null;
private static final Logger logger = Logger.getLogger(ElasticSearchRestClient.class);
public ElasticSearchRestClient() {
RestClientBuilderListener restClientBuilderListener = new RestClientBuilderListener();
ElasticSearchRestClient.restClient = RestClient.builder(new HttpHost("ip", port, "http")).setRequestConfigCallback(restClientBuilderListener)
.setHttpClientConfigCallback(restClientBuilderListener).setMaxRetryTimeoutMillis(10000).build();
}
public void closeRestClient() {
logger.info("Closing ElasticSearchRestClient ");
try {
restClient.close();
} catch (IOException e) {
logger.error(
"While Closing ElasticSearchRestClient getting Exception Line :", e);
}
}
public void search(String precheckListkey, String searchJson,int count) {
long start= 0, end = 0;
int i = 0;
long total = 0;
for (; i < count; i++) {
String currJson = "{\"size\"" + ":0,\"_source\""+":false,\"query\""+":{\"term\""+":{\"7.exactMatch\""+":\"Subex__1"+i+"\""+"}}}";
start = System.currentTimeMillis();
processRequest("POST",
File.separatorChar + precheckListkey + File.separatorChar + precheckListkey + "/_search", currJson);
end = System.currentTimeMillis();
total += end-start;
}
logger.info("Total Request :"+ i +" Time Diff :" + total + " Speed : "+ i / (total/1000));
}
private void processRequest(String methodType, String url, String json) {
try {
HttpEntity entity = new NStringEntity(json, ContentType.APPLICATION_JSON);
Response response = restClient.performRequest(methodType, url, emptyMap, entity);
//int statusCode = response.getStatusLine().getStatusCode();
// String message = EntityUtils.toString(response.getEntity());
//logger.info("Status :"+ statusCode + " Response :"+ message);
} catch (ParseException | IOException e) {
logger.error("",e);
}
}
}
package ElasticSearch.ESRestClientSample;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.config.RequestConfig.Builder;
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
import org.apache.log4j.Logger;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestClientBuilder.HttpClientConfigCallback;
import org.elasticsearch.client.RestClientBuilder.RequestConfigCallback;
import org.apache.http.impl.nio.reactor.IOReactorConfig;
public class RestClientBuilderListener implements RequestConfigCallback, HttpClientConfigCallback {
private Integer connectTimeOut = RestClientBuilder.DEFAULT_CONNECT_TIMEOUT_MILLIS;
private Integer socketTimeOut = RestClientBuilder.DEFAULT_SOCKET_TIMEOUT_MILLIS;
private static final Logger logger = Logger.getLogger(RestClientBuilderListener.class);
@Override
public Builder customizeRequestConfig(Builder requestConfigBuilder) {
logger.info("customizeRequestConfig :" + requestConfigBuilder.toString());
return requestConfigBuilder.setConnectTimeout(connectTimeOut).setSocketTimeout(socketTimeOut);
}
@Override
public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
httpClientBuilder.setDefaultIOReactorConfig(
IOReactorConfig.custom().setIoThreadCount(1).build());
return httpClientBuilder;
}
}