Skip to content

Commit b92758c

Browse files
committed
Add indexParallel(), using Ctags object pool, for faster indexing
Also, restrict (new) PendingFileCompleter as package-private not public.
1 parent 2ead3bb commit b92758c

21 files changed

+843
-149
lines changed

OpenGrok

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@
110110
# increase it to 256MB, but do increase JVM to
111111
# 4/8/16GB ! Lucene defaults to 8 threads.
112112
# Increase JVM memory as noted using JAVA_OPTS
113+
# - OPENGROK_PARALLELISM Default is 0, meaning that parallelism is
114+
# determined from available processors.
113115
# - OPENGROK_LOGGER_CONFIG_PATH Set path to custom logging.properties file.
114116
# - OPENGROK_SUBVERSION_USERNAME name of the user that should be used for
115117
# fetching the history from subversion
@@ -862,6 +864,7 @@ CommonInvocation()
862864
${OPENGROK_MANDOC:+--mandoc} ${OPENGROK_MANDOC} \
863865
${CTAGS_OPTIONS_FILE:+-o} ${CTAGS_OPTIONS_FILE} \
864866
${OPENGROK_FLUSH_RAM_BUFFER_SIZE} ${SKIN} ${LEADING_WILDCARD} \
867+
${OPENGROK_PARALLELISM:+--threads} ${OPENGROK_PARALLELISM} \
865868
${READ_XML_CONF} \
866869
${WEBAPP_CONFIG} \
867870
${WEBAPP_CONTEXT} \

src/org/opensolaris/opengrok/analysis/Ctags.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ public class Ctags {
5858

5959
private boolean junit_testing = false;
6060

61+
public boolean isClosed() {
62+
return ctags != null && !ctags.isAlive();
63+
}
64+
65+
public String getBinary() {
66+
return binary;
67+
}
68+
6169
public void setBinary(String binary) {
6270
this.binary = binary;
6371
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* See LICENSE.txt included in this distribution for the specific
9+
* language governing permissions and limitations under the License.
10+
*
11+
* When distributing Covered Code, include this CDDL HEADER in each
12+
* file and include the License file at LICENSE.txt.
13+
* If applicable, add the following below this CDDL HEADER, with the
14+
* fields enclosed by brackets "[]" replaced with your own identifying
15+
* information: Portions Copyright [yyyy] [name of copyright owner]
16+
*
17+
* CDDL HEADER END
18+
*/
19+
20+
/*
21+
* Copyright (c) 2017, Chris Fraire <[email protected]>.
22+
*/
23+
24+
package org.opensolaris.opengrok.analysis;
25+
26+
import java.io.IOException;
27+
import java.util.logging.Level;
28+
import java.util.logging.Logger;
29+
import org.opensolaris.opengrok.logger.LoggerFactory;
30+
import org.opensolaris.opengrok.util.ObjectValidator;
31+
32+
public final class CtagsValidator implements ObjectValidator<Ctags> {
33+
34+
private static final Logger LOGGER = LoggerFactory.getLogger(
35+
CtagsValidator.class);
36+
37+
public boolean isValid(Ctags ctags) {
38+
return ctags != null && !ctags.isClosed();
39+
}
40+
41+
public void invalidate(Ctags ctags) {
42+
try {
43+
if (ctags != null) ctags.close();
44+
} catch (IOException ex) {
45+
LOGGER.log(Level.FINE, "Error closing ctags", ex);
46+
}
47+
}
48+
}

src/org/opensolaris/opengrok/configuration/Configuration.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ public final class Configuration {
182182
private String luceneLocking = LuceneLockName.OFF;
183183
private boolean compressXref;
184184
private boolean indexVersionedFilesOnly;
185+
private int indexingParallelism;
185186
private boolean tagsEnabled;
186187
private int hitsPerPage;
187188
private int cachePages;
@@ -971,6 +972,14 @@ public void setIndexVersionedFilesOnly(boolean indexVersionedFilesOnly) {
971972
this.indexVersionedFilesOnly = indexVersionedFilesOnly;
972973
}
973974

975+
public int getIndexingParallelism() {
976+
return indexingParallelism;
977+
}
978+
979+
public void setIndexingParallelism(int value) {
980+
this.indexingParallelism = value > 0 ? value : 0;
981+
}
982+
974983
public boolean isTagsEnabled() {
975984
return this.tagsEnabled;
976985
}

src/org/opensolaris/opengrok/configuration/RuntimeEnvironment.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,17 @@ public void setIndexVersionedFilesOnly(boolean indexVersionedFilesOnly) {
10591059
threadConfig.get().setIndexVersionedFilesOnly(indexVersionedFilesOnly);
10601060
}
10611061

1062+
/**
1063+
* Gets the value of {@link Configuration#getIndexingParallelism()} -- or
1064+
* if zero, then as a default gets the number of available processors.
1065+
* @return a natural number &gt;= 1
1066+
*/
1067+
public int getIndexingParallelism() {
1068+
int parallelism = threadConfig.get().getIndexingParallelism();
1069+
return parallelism < 1 ? Runtime.getRuntime().availableProcessors() :
1070+
parallelism;
1071+
}
1072+
10621073
public boolean isTagsEnabled() {
10631074
return threadConfig.get().isTagsEnabled();
10641075
}

0 commit comments

Comments
 (0)