Skip to content

Commit e01b764

Browse files
committed
PR comments
1 parent c263c11 commit e01b764

File tree

5 files changed

+48
-10
lines changed

5 files changed

+48
-10
lines changed

qa/vector/build.gradle

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,21 @@ tasks.register("checkVec", JavaExec) {
6060
}
6161
def asyncProfilerPath = System.getProperty("asyncProfiler.path", null)
6262
if (asyncProfilerPath != null) {
63+
def asyncProfilerEvent = System.getProperty("asyncProfiler.event", "cpu")
6364
if (OS.current().equals(OS.MAC)) {
6465
def asyncProfilerAgent = "${asyncProfilerPath}/lib/libasyncProfiler.dylib"
6566
println "Using async-profiler agent ${asyncProfilerAgent}"
66-
jvmArgs "-agentpath:${asyncProfilerAgent}=start,event=cpu,interval=10ms,file=${layout.buildDirectory.asFile.get()}/tmp/elasticsearch-0_%t_%p.jfr"
67+
68+
// MacOS implementation of async-profiler does not support wall clock profiling with another event.
69+
// Wall clock times can be obtained separately invoking this task with `-DasyncProfiler.event=wall`
70+
jvmArgs "-agentpath:${asyncProfilerAgent}=start,event=${asyncProfilerEvent},interval=10ms,file=${layout.buildDirectory.asFile.get()}/tmp/elasticsearch-0_%t_%p.jfr"
6771
} else if (OS.current().equals(OS.LINUX)) {
72+
// Linux implementation of async-profiler uses perf_event, which allows wall clock profiling with another event (cpu)
73+
def additionalWallInterval = asyncProfilerEvent.equals("cpu") ? ",wall=50ms" : ""
74+
6875
def asyncProfilerAgent = "${asyncProfilerPath}/lib/libasyncProfiler.so"
6976
println "Using async-profiler agent ${asyncProfilerAgent}"
70-
jvmArgs "-agentpath:${asyncProfilerAgent}=start,event=cpu,interval=10ms,wall=50ms,file=${layout.buildDirectory.asFile.get()}/tmp/elasticsearch-0_%t_%p.jfr"
77+
jvmArgs "-agentpath:${asyncProfilerAgent}=start,event=${asyncProfilerEvent},interval=10ms${additionalWallInterval},file=${layout.buildDirectory.asFile.get()}/tmp/elasticsearch-0_%t_%p.jfr"
7178
} else {
7279
println "Ignoring 'asyncProfiler.path': not available on ${OS.current()}";
7380
}

qa/vector/src/main/java/org/elasticsearch/test/knn/CmdLineArgs.java

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99

1010
package org.elasticsearch.test.knn;
1111

12+
import org.apache.lucene.index.IndexWriterConfig;
1213
import org.apache.lucene.index.VectorEncoding;
1314
import org.apache.lucene.index.VectorSimilarityFunction;
1415
import org.elasticsearch.common.Strings;
1516
import org.elasticsearch.core.PathUtils;
17+
import org.elasticsearch.monitor.jvm.JvmInfo;
1618
import org.elasticsearch.xcontent.ObjectParser;
1719
import org.elasticsearch.xcontent.ParseField;
1820
import org.elasticsearch.xcontent.ToXContentObject;
@@ -54,7 +56,8 @@ record CmdLineArgs(
5456
int dimensions,
5557
boolean earlyTermination,
5658
KnnIndexTester.MergePolicyType mergePolicy,
57-
double writerBufferSizeInMb
59+
double writerBufferSizeInMb,
60+
int writerMaxBufferedDocs
5861
) implements ToXContentObject {
5962

6063
static final ParseField DOC_VECTORS_FIELD = new ParseField("doc_vectors");
@@ -83,9 +86,15 @@ record CmdLineArgs(
8386
static final ParseField FILTER_SELECTIVITY_FIELD = new ParseField("filter_selectivity");
8487
static final ParseField SEED_FIELD = new ParseField("seed");
8588
static final ParseField MERGE_POLICY_FIELD = new ParseField("merge_policy");
86-
static final ParseField WRITER_BUFFER_FIELD = new ParseField("writer_buffer_mb");
89+
static final ParseField WRITER_BUFFER_MB_FIELD = new ParseField("writer_buffer_mb");
90+
static final ParseField WRITER_BUFFER_DOCS_FIELD = new ParseField("writer_buffer_docs");
8791

88-
static final double DEFAULT_WRITER_BUFFER_MB = 128;
92+
/** By default, in ES the default writer buffer size is 10% of the heap space
93+
* (see {@code IndexingMemoryController.INDEX_BUFFER_SIZE_SETTING}).
94+
* We configure the Java heap size for this tool in {@code build.gradle}; currently we default to 16GB, so in that case
95+
* the buffer size would be 1.6GB.
96+
*/
97+
static final double DEFAULT_WRITER_BUFFER_MB = (JvmInfo.jvmInfo().getMem().getHeapMax().getBytes() / (1024.0 * 1024.0)) * 0.1;
8998

9099
static CmdLineArgs fromXContent(XContentParser parser) throws IOException {
91100
Builder builder = PARSER.apply(parser, null);
@@ -121,7 +130,8 @@ static CmdLineArgs fromXContent(XContentParser parser) throws IOException {
121130
PARSER.declareFloat(Builder::setFilterSelectivity, FILTER_SELECTIVITY_FIELD);
122131
PARSER.declareLong(Builder::setSeed, SEED_FIELD);
123132
PARSER.declareString(Builder::setMergePolicy, MERGE_POLICY_FIELD);
124-
PARSER.declareDouble(Builder::setWriterBufferMb, WRITER_BUFFER_FIELD);
133+
PARSER.declareDouble(Builder::setWriterBufferMb, WRITER_BUFFER_MB_FIELD);
134+
PARSER.declareInt(Builder::setWriterMaxBufferedDocs, WRITER_BUFFER_DOCS_FIELD);
125135
}
126136

127137
@Override
@@ -157,6 +167,8 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
157167
builder.field(EARLY_TERMINATION_FIELD.getPreferredName(), earlyTermination);
158168
builder.field(FILTER_SELECTIVITY_FIELD.getPreferredName(), filterSelectivity);
159169
builder.field(SEED_FIELD.getPreferredName(), seed);
170+
builder.field(WRITER_BUFFER_MB_FIELD.getPreferredName(), writerBufferSizeInMb);
171+
builder.field(WRITER_BUFFER_DOCS_FIELD.getPreferredName(), writerMaxBufferedDocs);
160172
return builder.endObject();
161173
}
162174

@@ -193,6 +205,12 @@ static class Builder {
193205
private KnnIndexTester.MergePolicyType mergePolicy = null;
194206
private double writerBufferSizeInMb = DEFAULT_WRITER_BUFFER_MB;
195207

208+
/**
209+
* Elasticsearch does not set this explicitly, and in Lucene this setting is
210+
* disabled by default (writer flushes by RAM usage).
211+
*/
212+
private int writerMaxBufferedDocs = IndexWriterConfig.DISABLE_AUTO_FLUSH;
213+
196214
public Builder setDocVectors(List<String> docVectors) {
197215
if (docVectors == null || docVectors.isEmpty()) {
198216
throw new IllegalArgumentException("Document vectors path must be provided");
@@ -327,6 +345,11 @@ public Builder setWriterBufferMb(double writerBufferSizeInMb) {
327345
return this;
328346
}
329347

348+
public Builder setWriterMaxBufferedDocs(int writerMaxBufferedDocs) {
349+
this.writerMaxBufferedDocs = writerMaxBufferedDocs;
350+
return this;
351+
}
352+
330353
public CmdLineArgs build() {
331354
if (docVectors == null) {
332355
throw new IllegalArgumentException("Document vectors path must be provided");
@@ -362,7 +385,8 @@ public CmdLineArgs build() {
362385
dimensions,
363386
earlyTermination,
364387
mergePolicy,
365-
writerBufferSizeInMb
388+
writerBufferSizeInMb,
389+
writerMaxBufferedDocs
366390
);
367391
}
368392
}

qa/vector/src/main/java/org/elasticsearch/test/knn/KnnIndexTester.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ public static void main(String[] args) throws Exception {
241241
cmdLineArgs.vectorSpace(),
242242
cmdLineArgs.numDocs(),
243243
mergePolicy,
244-
cmdLineArgs.writerBufferSizeInMb()
244+
cmdLineArgs.writerBufferSizeInMb(),
245+
cmdLineArgs.writerMaxBufferedDocs()
245246
);
246247
if (cmdLineArgs.reindex() == false && Files.exists(indexPath) == false) {
247248
throw new IllegalArgumentException("Index path does not exist: " + indexPath);

qa/vector/src/main/java/org/elasticsearch/test/knn/KnnIndexer.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class KnnIndexer {
7474
private final int numIndexThreads;
7575
private final MergePolicy mergePolicy;
7676
private final double writerBufferSizeInMb;
77+
private final int writerMaxBufferedDocs;
7778

7879
KnnIndexer(
7980
List<Path> docsPath,
@@ -85,7 +86,8 @@ class KnnIndexer {
8586
VectorSimilarityFunction similarityFunction,
8687
int numDocs,
8788
MergePolicy mergePolicy,
88-
double writerBufferSizeInMb
89+
double writerBufferSizeInMb,
90+
int writerMaxBufferedDocs
8991
) {
9092
this.docsPath = docsPath;
9193
this.indexPath = indexPath;
@@ -97,12 +99,13 @@ class KnnIndexer {
9799
this.numDocs = numDocs;
98100
this.mergePolicy = mergePolicy;
99101
this.writerBufferSizeInMb = writerBufferSizeInMb;
102+
this.writerMaxBufferedDocs = writerMaxBufferedDocs;
100103
}
101104

102105
void createIndex(KnnIndexTester.Results result) throws IOException, InterruptedException, ExecutionException {
103106
IndexWriterConfig iwc = new IndexWriterConfig().setOpenMode(IndexWriterConfig.OpenMode.CREATE);
104107
iwc.setCodec(codec);
105-
iwc.setMaxBufferedDocs(IndexWriterConfig.DISABLE_AUTO_FLUSH);
108+
iwc.setMaxBufferedDocs(writerMaxBufferedDocs);
106109
iwc.setRAMBufferSizeMB(writerBufferSizeInMb);
107110
iwc.setUseCompoundFile(false);
108111
if (mergePolicy != null) {

server/src/main/java/org/elasticsearch/index/engine/EngineConfig.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.elasticsearch.common.unit.MemorySizeValue;
2424
import org.elasticsearch.core.Nullable;
2525
import org.elasticsearch.core.TimeValue;
26+
import org.elasticsearch.core.UpdateForV10;
2627
import org.elasticsearch.index.IndexMode;
2728
import org.elasticsearch.index.IndexSettings;
2829
import org.elasticsearch.index.codec.CodecProvider;
@@ -131,6 +132,7 @@ public Supplier<RetentionLeases> retentionLeasesSupplier() {
131132
* TODO: Remove in 9.0
132133
*/
133134
@Deprecated
135+
@UpdateForV10(owner = UpdateForV10.Owner.DISTRIBUTED_INDEXING)
134136
public static final Setting<Boolean> INDEX_OPTIMIZE_AUTO_GENERATED_IDS = Setting.boolSetting(
135137
"index.optimize_auto_generated_id",
136138
true,
@@ -213,6 +215,7 @@ public EngineConfig(
213215
// Add an escape hatch in case this change proves problematic - it used
214216
// to be a fixed amound of RAM: 256 MB.
215217
// TODO: Remove this escape hatch in 8.x
218+
@UpdateForV10(owner = UpdateForV10.Owner.DISTRIBUTED_INDEXING)
216219
final String escapeHatchProperty = "es.index.memory.max_index_buffer_size";
217220
String maxBufferSize = System.getProperty(escapeHatchProperty);
218221
if (maxBufferSize != null) {

0 commit comments

Comments
 (0)