Skip to content

Commit b24e28d

Browse files
committed
Fix performance bugs in indexing performance tests:
- reduce bottleneck in reading line files by switching to (optional) binary format, and by using a dedicated reader thread that writes to a queue - tune for faster indexing throughput on beast2: 2 GB IW buffer, 8 GB heap, 20 indexing threads - stop using MemoryPostingsFormat for ID field - don't wait for commit on indexing performance runs - turn off merge IO throttling on indexing performance runs
1 parent 622ae06 commit b24e28d

8 files changed

Lines changed: 371 additions & 120 deletions

File tree

‎src/main/perf/IndexThreads.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public IndexThreads(Random random, IndexWriter w, AtomicBoolean indexingFailed,
7676

7777
for(int thread=0;thread<numThreads;thread++) {
7878
threads[thread] = new IndexThread(random, startLatch, stopLatch, w, docs, docCountLimit, count, mode, groupBlockIndex, stop, refreshing, lastRefreshNS, docsPerSecPerThread, failed, updatesListener, nrtEverySec, randomDocIDMax);
79+
threads[thread].setName("Index #" + thread);
7980
threads[thread].start();
8081
}
8182

@@ -380,7 +381,9 @@ public void remove() {
380381
}
381382

382383
if ((docCount % 10000) == 0) {
383-
System.out.println("Indexer: " + docCount + " docs... (" + (System.currentTimeMillis() - tStart) + " msec)");
384+
long nowMS = System.currentTimeMillis();
385+
double dps = docCount / ((nowMS - tStart)/1000.0);
386+
System.out.println(String.format(Locale.ROOT, "Indexer: %d docs (%.1f sec); %.1f docs/sec", docCount, (nowMS - tStart)/1000.0, dps));
384387
}
385388

386389
if (mode == Mode.UPDATE) {

‎src/main/perf/Indexer.java‎

Lines changed: 61 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static void main(String[] clArgs) throws Exception {
7878
}
7979
}
8080

81-
private static MergeScheduler getMergeScheduler(AtomicBoolean indexingFailed, boolean useCMS, int maxConcurrentMerges) {
81+
private static MergeScheduler getMergeScheduler(AtomicBoolean indexingFailed, boolean useCMS, int maxConcurrentMerges, boolean disableIOThrottle) {
8282
if (useCMS) {
8383
ConcurrentMergeScheduler cms = new ConcurrentMergeScheduler() {
8484
@Override
@@ -90,6 +90,9 @@ protected void handleMergeException(Directory dir, Throwable exc) {
9090
}
9191
};
9292
cms.setMaxMergesAndThreads(maxConcurrentMerges+4, maxConcurrentMerges);
93+
if (disableIOThrottle) {
94+
cms.disableAutoIOThrottle();
95+
}
9396
return cms;
9497
} else {
9598
// Gives better repeatability because if you use CMS, the order in which the merges complete can impact how the merge policy later
@@ -200,6 +203,7 @@ private static void _main(String[] clArgs) throws Exception {
200203
final boolean doDeletions = args.getFlag("-deletions");
201204
final boolean printDPS = args.getFlag("-printDPS");
202205
final boolean waitForMerges = args.getFlag("-waitForMerges");
206+
final boolean waitForCommit = args.getFlag("-waitForCommit");
203207
final String mergePolicy = args.getString("-mergePolicy");
204208
final Mode mode;
205209
final boolean doUpdate = args.getFlag("-update");
@@ -224,6 +228,23 @@ private static void _main(String[] clArgs) throws Exception {
224228
final boolean addDVFields = args.getFlag("-dvfields");
225229
final boolean doRandomCommit = args.getFlag("-randomCommit");
226230
final boolean useCMS = args.getFlag("-useCMS");
231+
final boolean disableIOThrottle = args.getFlag("-disableIOThrottle");
232+
233+
if (waitForCommit == false && waitForMerges) {
234+
throw new RuntimeException("pass -waitForCommit if you pass -waitForMerges");
235+
}
236+
237+
if (waitForCommit == false && doForceMerge) {
238+
throw new RuntimeException("pass -waitForCommit if you pass -forceMerge");
239+
}
240+
241+
if (waitForCommit == false && doDeletions) {
242+
throw new RuntimeException("pass -waitForCommit if you pass -deletions");
243+
}
244+
245+
if (useCMS == false && disableIOThrottle) {
246+
throw new RuntimeException("-disableIOThrottle only makes sense with -useCMS");
247+
}
227248

228249
final double nrtEverySec;
229250
if (args.hasArg("-nrtEverySec")) {
@@ -263,6 +284,8 @@ private static void _main(String[] clArgs) throws Exception {
263284
System.out.println("Default postings format: " + defaultPostingsFormat);
264285
System.out.println("Do deletions: " + (doDeletions ? "yes" : "no"));
265286
System.out.println("Wait for merges: " + (waitForMerges ? "yes" : "no"));
287+
System.out.println("Wait for commit: " + (waitForCommit ? "yes" : "no"));
288+
System.out.println("IO throttle: " + (disableIOThrottle ? "no" : "yes"));
266289
System.out.println("Merge policy: " + mergePolicy);
267290
System.out.println("Mode: " + mode);
268291
if (mode == Mode.UPDATE) {
@@ -310,7 +333,7 @@ private static void _main(String[] clArgs) throws Exception {
310333

311334
final AtomicBoolean indexingFailed = new AtomicBoolean();
312335

313-
iwc.setMergeScheduler(getMergeScheduler(indexingFailed, useCMS, maxConcurrentMerges));
336+
iwc.setMergeScheduler(getMergeScheduler(indexingFailed, useCMS, maxConcurrentMerges, disableIOThrottle));
314337
iwc.setMergePolicy(getMergePolicy(mergePolicy, useCFS));
315338

316339
// Keep all commit points:
@@ -401,11 +424,12 @@ public DocValuesFormat getDocValuesFormatForField(String field) {
401424
throw new RuntimeException("w.maxDoc()=" + w.maxDoc() + " but expected " + docCountLimit);
402425
}
403426

404-
final long t2;
427+
final Map<String,String> commitData = new HashMap<String,String>();
428+
405429
if (waitForMerges) {
406430
w.close();
407431
IndexWriterConfig iwc2 = new IndexWriterConfig(a);
408-
iwc2.setMergeScheduler(getMergeScheduler(indexingFailed, useCMS, maxConcurrentMerges));
432+
iwc2.setMergeScheduler(getMergeScheduler(indexingFailed, useCMS, maxConcurrentMerges, disableIOThrottle));
409433
iwc2.setMergePolicy(getMergePolicy(mergePolicy, useCFS));
410434
iwc2.setCodec(codec);
411435
iwc2.setUseCompoundFile(useCFS);
@@ -416,29 +440,33 @@ public DocValuesFormat getDocValuesFormatForField(String field) {
416440
}
417441

418442
w = new IndexWriter(dir, iwc2);
419-
t2 = System.currentTimeMillis();
443+
long t2 = System.currentTimeMillis();
420444
System.out.println("\nIndexer: waitForMerges done (" + (t2-t1) + " msec)");
421-
} else {
422-
t2 = System.currentTimeMillis();
423445
}
424446

425-
final Map<String,String> commitData = new HashMap<String,String>();
426-
commitData.put("userData", "multi");
427-
w.setCommitData(commitData);
428-
w.commit();
429-
final long t3 = System.currentTimeMillis();
430-
System.out.println("\nIndexer: commit multi (took " + (t3-t2) + " msec)");
447+
if (waitForCommit) {
448+
commitData.put("userData", "multi");
449+
w.setCommitData(commitData);
450+
long t2 = System.currentTimeMillis();
451+
w.commit();
452+
long t3 = System.currentTimeMillis();
453+
System.out.println("\nIndexer: commit multi (took " + (t3-t2) + " msec)");
454+
} else {
455+
w.rollback();
456+
w = null;
457+
}
431458

432459
if (doForceMerge) {
460+
long forceMergeStartMSec = System.currentTimeMillis();
433461
w.forceMerge(1);
434-
final long t4 = System.currentTimeMillis();
435-
System.out.println("\nIndexer: force merge done (took " + (t4-t3) + " msec)");
462+
long forceMergeEndMSec = System.currentTimeMillis();
463+
System.out.println("\nIndexer: force merge done (took " + (forceMergeEndMSec-forceMergeStartMSec) + " msec)");
436464

437465
commitData.put("userData", "single");
438466
w.setCommitData(commitData);
439467
w.commit();
440468
final long t5 = System.currentTimeMillis();
441-
System.out.println("\nIndexer: commit single done (took " + (t5-t4) + " msec)");
469+
System.out.println("\nIndexer: commit single done (took " + (t5-forceMergeEndMSec) + " msec)");
442470
}
443471

444472
if (doDeletions) {
@@ -476,17 +504,27 @@ public DocValuesFormat getDocValuesFormatForField(String field) {
476504
}
477505

478506
final long tCloseStart = System.currentTimeMillis();
479-
if (waitForMerges == false) {
480-
w.rollback();
481-
} else {
507+
if (w != null) {
482508
w.close();
509+
w = null;
510+
}
511+
if (waitForCommit) {
512+
System.out.println("\nIndexer: at close: " + SegmentInfos.readLatestCommit(dir));
513+
System.out.println("\nIndexer: close took " + (System.currentTimeMillis() - tCloseStart) + " msec");
483514
}
484-
System.out.println("\nIndexer: at close: " + SegmentInfos.readLatestCommit(dir));
485-
System.out.println("\nIndexer: close took " + (System.currentTimeMillis() - tCloseStart) + " msec");
515+
486516
dir.close();
487517
final long tFinal = System.currentTimeMillis();
488-
System.out.println("\nIndexer: finished (" + (tFinal-t0) + " msec)");
489518
System.out.println("\nIndexer: net bytes indexed " + threads.getBytesIndexed());
490-
System.out.println("\nIndexer: " + (threads.getBytesIndexed()/1024./1024./1024./((tFinal-t0)/3600000.)) + " GB/hour plain text");
519+
520+
final long indexingTime;
521+
if (waitForCommit) {
522+
indexingTime = tFinal - t0;
523+
System.out.println("\nIndexer: finished (" + indexingTime + " msec)");
524+
} else {
525+
indexingTime = t1 - t0;
526+
System.out.println("\nIndexer: finished (" + indexingTime + " msec), excluding commit");
527+
}
528+
System.out.println("\nIndexer: " + (threads.getBytesIndexed()/1024./1024./1024./(indexingTime/3600000.)) + " GB/hour plain text");
491529
}
492530
}

0 commit comments

Comments
 (0)