Skip to content

Commit 54795af

Browse files
author
Vladimir Kotal
authored
add elapsed statistics logs to suggester rebuild (#2221)
1 parent 07a8799 commit 54795af

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

suggester/src/main/java/org/opengrok/suggest/Suggester.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*/
2323
package org.opengrok.suggest;
2424

25+
import org.apache.commons.lang3.time.DurationFormatUtils;
2526
import org.apache.lucene.index.DirectoryReader;
2627
import org.apache.lucene.index.IndexReader;
2728
import org.apache.lucene.index.Term;
@@ -148,6 +149,7 @@ public void init(final Collection<NamedIndexDir> luceneIndexes) {
148149
}
149150

150151
synchronized (lock) {
152+
Instant start = Instant.now();
151153
logger.log(Level.INFO, "Initializing suggester");
152154

153155
ExecutorService executor = Executors.newWorkStealingPool(rebuildParallelismLevel);
@@ -156,7 +158,7 @@ public void init(final Collection<NamedIndexDir> luceneIndexes) {
156158
submitInitIfIndexExists(executor, indexDir);
157159
}
158160

159-
shutdownAndAwaitTermination(executor, "Suggester successfully initialized");
161+
shutdownAndAwaitTermination(executor, start, "Suggester successfully initialized");
160162
}
161163
}
162164

@@ -209,11 +211,13 @@ private boolean indexExists(final Path indexDir) throws IOException {
209211
}
210212
}
211213

212-
private void shutdownAndAwaitTermination(final ExecutorService executorService, final String logMessageOnSuccess) {
214+
private void shutdownAndAwaitTermination(final ExecutorService executorService, Instant start, final String logMessageOnSuccess) {
213215
executorService.shutdown();
214216
try {
215217
executorService.awaitTermination(awaitTerminationTime.toMillis(), TimeUnit.MILLISECONDS);
216-
logger.log(Level.INFO, logMessageOnSuccess);
218+
logger.log(Level.INFO, "{0} (took {1})", new Object[]{logMessageOnSuccess,
219+
DurationFormatUtils.formatDurationWords(Duration.between(start, Instant.now()).toMillis(),
220+
true, true)});
217221
} catch (InterruptedException e) {
218222
logger.log(Level.SEVERE, "Interrupted while building suggesters", e);
219223
Thread.currentThread().interrupt();
@@ -231,6 +235,7 @@ public void rebuild(final Collection<NamedIndexDir> indexDirs) {
231235
}
232236

233237
synchronized (lock) {
238+
Instant start = Instant.now();
234239
logger.log(Level.INFO, "Rebuilding the following suggesters: {0}", indexDirs);
235240

236241
ExecutorService executor = Executors.newWorkStealingPool(rebuildParallelismLevel);
@@ -244,7 +249,7 @@ public void rebuild(final Collection<NamedIndexDir> indexDirs) {
244249
}
245250
}
246251

247-
shutdownAndAwaitTermination(executor, "Suggesters for " + indexDirs + " were successfully rebuilt");
252+
shutdownAndAwaitTermination(executor, start, "Suggesters for " + indexDirs + " were successfully rebuilt");
248253
}
249254
}
250255

0 commit comments

Comments
 (0)