Automatically compute a good value for number of indexer threads to start.

This commit is contained in:
Jacob Dufault 2017-04-20 22:16:52 -07:00
parent 145bf87d70
commit 16dc2971a6
2 changed files with 15 additions and 6 deletions

View File

@ -1673,8 +1673,11 @@ void QueryDbMain(IndexerConfig* config) {
FileConsumer::SharedState file_consumer_shared;
// Start indexer threads.
std::cerr << "[querydb] Starting " << config->indexerCount << " indexers" << std::endl;
for (int i = 0; i < config->indexerCount; ++i) {
int indexerCount = std::min<int>(std::thread::hardware_concurrency(), 2) - 1;
if (config->indexerCount > 0)
indexerCount = config->indexerCount;
std::cerr << "[querydb] Starting " << indexerCount << " indexers" << std::endl;
for (int i = 0; i < indexerCount; ++i) {
new std::thread([&]() {
IndexMain(config, &file_consumer_shared, &project, &queue_do_index, &queue_do_id_map, &queue_on_id_mapped, &queue_on_indexed);
});

View File

@ -59,9 +59,14 @@ struct IndexerConfig {
std::string cacheDirectory;
NonElidedVector<std::string> whitelist;
NonElidedVector<std::string> blacklist;
int indexerCount = 1;
int maxWorkspaceSearchResults = 1000;
std::vector<std::string> extraClangArguments;
// Maximum workspace search results.
int maxWorkspaceSearchResults = 1000;
// Force a certain number of indexer threads. If less than 1 a default value
// should be used.
int indexerCount = 0;
// If false, the indexer will be disabled.
bool enableIndexing = true;
// If false, indexed files will not be written to disk.
@ -72,9 +77,10 @@ struct IndexerConfig {
MAKE_REFLECT_STRUCT(IndexerConfig,
cacheDirectory,
whitelist, blacklist,
indexerCount,
maxWorkspaceSearchResults,
extraClangArguments,
maxWorkspaceSearchResults,
indexerCount,
enableIndexing, enableCacheWrite, enableCacheRead);