-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce memory usage in field-caps responses (#88042)
We have reduced the memory usage of field-caps requests targeting many indices in 8.2+ (see #83494). Unfortunately, we still receive OOM reports in 7.17. I think we should push some contained improvements to reduce the memory usage for those requests in 7.17. I have looked into several options. This PR reduces the memory usage of field-caps responses by replace HashMap with ArrayList for the field responses to eliminate duplicated string names and internal nodes of Map.
- Loading branch information
Showing
8 changed files
with
126 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pr: 88042 | ||
summary: Reduce memory usage in field-caps responses | ||
area: Search | ||
type: bug | ||
issues: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...src/test/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesIndexResponseTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.action.fieldcaps; | ||
|
||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.Writeable; | ||
import org.elasticsearch.test.AbstractWireSerializingTestCase; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Base64; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomAsciiLettersOfLength; | ||
import static org.elasticsearch.action.fieldcaps.FieldCapabilitiesResponseTests.randomFieldCaps; | ||
import static org.hamcrest.Matchers.containsInAnyOrder; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
public class FieldCapabilitiesIndexResponseTests extends AbstractWireSerializingTestCase<FieldCapabilitiesIndexResponse> { | ||
@Override | ||
protected Writeable.Reader<FieldCapabilitiesIndexResponse> instanceReader() { | ||
return FieldCapabilitiesIndexResponse::new; | ||
} | ||
|
||
static FieldCapabilitiesIndexResponse randomIndexResponse() { | ||
return randomIndexResponse(randomAsciiLettersOfLength(10), randomBoolean()); | ||
} | ||
|
||
static FieldCapabilitiesIndexResponse randomIndexResponse(String index, boolean canMatch) { | ||
List<IndexFieldCapabilities> fields = new ArrayList<>(); | ||
if (canMatch) { | ||
String[] fieldNames = generateRandomStringArray(5, 10, false, true); | ||
assertNotNull(fieldNames); | ||
for (String fieldName : fieldNames) { | ||
fields.add(randomFieldCaps(fieldName)); | ||
} | ||
} | ||
return new FieldCapabilitiesIndexResponse(index, fields, canMatch); | ||
} | ||
|
||
@Override | ||
protected FieldCapabilitiesIndexResponse createTestInstance() { | ||
return randomIndexResponse(); | ||
} | ||
|
||
public void testDeserializeFromBase64() throws Exception { | ||
String base64 = "CWxvZ3MtMTAwMQMGcGVyaW9kBnBlcmlvZARsb25nAQABAQR1bml0BnNlY29uZApAdGltZXN0" | ||
+ "YW1wCkB0aW1lc3RhbXAEZGF0ZQEBAAAHbWVzc2FnZQdtZXNzYWdlBHRleHQAAQAAAQAAAAAAAAAAAA=="; | ||
StreamInput in = StreamInput.wrap(Base64.getDecoder().decode(base64)); | ||
FieldCapabilitiesIndexResponse resp = new FieldCapabilitiesIndexResponse(in); | ||
assertTrue(resp.canMatch()); | ||
assertThat(resp.getIndexName(), equalTo("logs-1001")); | ||
assertThat( | ||
resp.getFields(), | ||
containsInAnyOrder( | ||
new IndexFieldCapabilities("@timestamp", "date", true, true, false, Collections.emptyMap()), | ||
new IndexFieldCapabilities("message", "text", false, true, false, Collections.emptyMap()), | ||
new IndexFieldCapabilities("period", "long", true, false, true, Collections.singletonMap("unit", "second")) | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters