Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

elasticsearchRestTemplate.search occur SocketTimeoutException under concurrent condition everytime #2868

Closed
ilwyiworld opened this issue Mar 12, 2024 · 1 comment
Labels
status: waiting-for-triage An issue we've not yet triaged

Comments

@ilwyiworld
Copy link

ilwyiworld commented Mar 12, 2024

spring-data-elasticsearch:4.2.5

elasticsearch:7.12.1

when I use elasticsearchRestTemplate.search to search data under concurrent condition everytime(tested by JMETER),only a few request return data successful,others occur SocketTimeoutException,here is exception trace:

Caused by: java.lang.RuntimeException: 1,500 milliseconds timeout on connection http-outgoing-21 [ACTIVE]
	at org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate.translateException(ElasticsearchRestTemplate.java:400)
	... 92 more
Caused by: java.net.SocketTimeoutException: 1,500 milliseconds timeout on connection http-outgoing-21 [ACTIVE]
	at org.elasticsearch.client.RestClient.extractAndWrapCause(RestClient.java:865)
	at org.elasticsearch.client.RestClient.performRequest(RestClient.java:283)
	at org.elasticsearch.client.RestClient.performRequest(RestClient.java:270)
	at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1654)
	at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1624)
	at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1594)
	at org.elasticsearch.client.RestHighLevelClient.search(RestHighLevelClient.java:1110)
	at org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate.lambda$search$11(ElasticsearchRestTemplate.java:296)
	at org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate.execute(ElasticsearchRestTemplate.java:383)
	... 91 more
Caused by: java.net.SocketTimeoutException: 1,500 milliseconds timeout on connection http-outgoing-21 [ACTIVE]
	at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.timeout(HttpAsyncRequestExecutor.java:387)
	at org.apache.http.impl.nio.client.InternalIODispatch.onTimeout(InternalIODispatch.java:92)
	at org.apache.http.impl.nio.client.InternalIODispatch.onTimeout(InternalIODispatch.java:39)
	at org.apache.http.impl.nio.reactor.AbstractIODispatch.timeout(AbstractIODispatch.java:175)
	at org.apache.http.impl.nio.reactor.BaseIOReactor.sessionTimedOut(BaseIOReactor.java:261)
	at org.apache.http.impl.nio.reactor.AbstractIOReactor.timeoutCheck(AbstractIOReactor.java:502)
	at org.apache.http.impl.nio.reactor.BaseIOReactor.validate(BaseIOReactor.java:211)
	at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:280)
	at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104)
	at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:591)
	... 1 more

here is JMETER setting:
1
2
3

here is java code:

    public Resp testGetEsData() {
        // 随机查询数据
        BoolQueryBuilder filter = QueryBuilders.boolQuery();
        filter.must(QueryBuilders.termsQuery("allLabels", Lists.newArrayList("历史","地理")));
        filter.must(QueryBuilders.termsQuery("questionType", Lists.newArrayList(0)));
        filter.must(QueryBuilders.termsQuery("questionSpecifyType", Lists.newArrayList(2)));
        // 算法不推荐限制
        filter.mustNot(QueryBuilders.termsQuery("algorithmParams", Lists.newArrayList("notShow")));
        NativeSearchQueryBuilder searchQueryBuilder = new NativeSearchQueryBuilder();
        Script script = new Script("Math.random()");
        ScriptSortBuilder sortBuilder = new ScriptSortBuilder(script, ScriptSortBuilder.ScriptSortType.NUMBER);
        searchQueryBuilder.withSort(sortBuilder);
        searchQueryBuilder.withPageable(PageRequest.of(0, 1));
        NativeSearchQuery query = searchQueryBuilder.build();
        SearchHits<CompleteQuestionEntity> searchHits = elasticsearchRestTemplate.search(query, CompleteQuestionEntity.class);
        Page<CompleteQuestionEntity> page = PageableExecutionUtils.getPage(searchHits.getSearchHits().stream()
                .map(SearchHit::getContent).collect(Collectors.toList()), PageRequest.of(0, 1), searchHits::getTotalHits);
        return Resp.success(page.getContent().get(0));
    }

but when I send same request to es directly used by JMETER,it all worked successfully,here is JMETER setting:
4
5
6

here is request body:

{
	"query": {
		"bool": {
			"must": [
				{
					"terms": {
						"allLabels": [
							"历史",
							"地理"
						],
						"boost": 1
					}
				},
				{
					"terms": {
						"questionType": [
							0
						],
						"boost": 1
					}
				},
				{
					"terms": {
						"questionSpecifyType": [
							2
						],
						"boost": 1
					}
				}
			],

			"must_not": [
				{
					"terms": {
						"algorithmParams": [
							"notShow"
						],
						"boost": 1
					}
				}
			],
			"adjust_pure_negative": true,
			"boost": 1
		}
	},
	"sort": {
		"_script": {
			"script": {
				"source": "Math.random()",
				"lang": "painless"
			},
			"type": "number",
			"order": "asc"
		}
	}
	"from": 0,
	"size": 1
}

here is spring-data-elasticsearch config:

spring:
  elasticsearch:
    rest:
      uris: 192.168.102.57:9200
      username:
      password:
      connection-timeout: 1500
      read-timeout: 1500
      max-conn-total: 800
      max-conn-per-route: 800
      keep-alive-minutes: 10
      sniffer:
        interval: 5m
        delay-after-failure: 1m

is it something wrong with those config?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 12, 2024
@sothawo
Copy link
Collaborator

sothawo commented Mar 12, 2024

4.2 is out of maintenance for nearly 2 years now. If we should have a look, update to maintained version (>= 5.1)

@sothawo sothawo closed this as not planned Won't fix, can't repro, duplicate, stale Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

3 participants