Skip to content

Commit

Permalink
PERF-1758: Add support for index options and use non-uniform distribu…
Browse files Browse the repository at this point in the history
…tions. (mongodb#62)
  • Loading branch information
David authored Dec 14, 2018
1 parent f5eb8c5 commit 195ae08
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 22 deletions.
28 changes: 21 additions & 7 deletions src/cast_core/src/actors/Loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

namespace {} // namespace

using document_ptr=std::unique_ptr<genny::value_generators::DocumentGenerator>;
using index_type=std::pair<document_ptr, std::optional<document_ptr>>;

struct genny::actor::Loader::PhaseConfig {
PhaseConfig(PhaseContext& context, std::mt19937_64& rng, mongocxx::pool::entry& client, uint thread)
: database{(*client)[context.get<std::string>("Database")]},
Expand All @@ -25,9 +28,11 @@ struct genny::actor::Loader::PhaseConfig {
batchSize{context.get<uint>("BatchSize")},
documentTemplate{value_generators::makeDoc(context.get("Document"), rng)},
collectionOffset{numCollections*thread} {
auto indexNodes = context.get<std::vector<YAML::Node>>("Indexes");
auto indexNodes = context.get("Indexes");
for (auto indexNode : indexNodes) {
indexes.push_back(value_generators::makeDoc(indexNode, rng));
indexes.emplace_back(
value_generators::makeDoc(indexNode["keys"], rng),
indexNode["options"] ? std::make_optional(value_generators::makeDoc(indexNode["options"], rng)) : std::nullopt);
}
if (thread == context.get<int>("Threads") - 1) {
// Pick up any extra collections left over by the division
Expand All @@ -39,8 +44,8 @@ struct genny::actor::Loader::PhaseConfig {
uint numCollections;
uint numDocuments;
uint batchSize;
std::unique_ptr<value_generators::DocumentGenerator> documentTemplate;
std::vector<std::unique_ptr<value_generators::DocumentGenerator>> indexes;
document_ptr documentTemplate;
std::vector<index_type> indexes;
uint collectionOffset;
};

Expand Down Expand Up @@ -71,11 +76,20 @@ void genny::actor::Loader::run() {
}
}
// For each index
for (auto& index : config->indexes) {
for (auto&& [keys, options] : config->indexes) {
// Make the index
bsoncxx::builder::stream::document keys;
auto keyView = index->view(keys);
bsoncxx::builder::stream::document keysDoc;
bsoncxx::builder::stream::document optionsDoc;
auto keyView = keys->view(keysDoc);
BOOST_LOG_TRIVIAL(debug) << "Building index " << bsoncxx::to_json(keyView);
if (options)
{
auto optionsView = (*options)->view(optionsDoc);
BOOST_LOG_TRIVIAL(debug) << "With options " << bsoncxx::to_json(optionsView);
auto op = _indexBuildTimer.raii();
collection.create_index(keyView, optionsView);
}
else
{
auto op = _indexBuildTimer.raii();
collection.create_index(keyView);
Expand Down
32 changes: 17 additions & 15 deletions src/driver/test/BigUpdate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ Actors:
BatchSize: 1000
Document: # Documents are approximately 1 KiB in size
t: {$randomint: {min: 0, max: 10}}
w: {$randomint: {min: 0, max: 10}}
w: {$randomint: {distribution: geometric, p: 0.1}}
x: 0
y: {$randomint: {min: 0, max: 1000}}
z: {$randomint: {min: 0, max: 2147483647}} # This is for max int for low probability of conflicts
int0: &int {$randomint: {min: 0, max: 10000}}
int0: &int {$randomint: {distribution: binomial, t: 200, p: 0.5}}
int1: *int
int2: *int
int3: *int
Expand Down Expand Up @@ -55,6 +55,7 @@ Actors:
string8: *string
string9: *string
stringShort: {$randomstring: {length: 1}}
stringLong: {$randomstring: {length: 100}}
compressibleStringArray:
- &cstring AAAAAAAAAAAAAAAAAAAA
- *cstring
Expand All @@ -70,16 +71,17 @@ Actors:
# The Loader needs to be updated to take options to support unique, etc. I will do as a
# follow-up. PERF-1758
Indexes:
- {t: 1, w: 1}
- {y: 1}
- {t: 1, StringShort: 1}
- {string0: 1}
- {string1: 1}
- {z: 1} # will make this unique
- {y: 1, StringShort: 1}
- {int0: 1, int1: 1, int2: 1}
- {int3: 1}
- {int4: 1}
- keys: {t: 1, w: 1}
- keys: {y: 1}
- keys: {t: 1, stringShort: 1}
- keys: {string0: 1}
- keys: {stringLong: 1}
options: {unique: 1}
- keys: {stringShort: 1, y: 1}
- keys: {int0: 1, int1: 1, int2: 1}
- keys: {int3: 1}
- keys: {int4: 1}
- keys: {int5: 1, int6: 1}
Phases:
- Repeat: 1
- Operation: Nop
Expand All @@ -88,7 +90,7 @@ Actors:
Threads: 10
Database: *DB
CollectionCount: 100 # This is specifically 1% of collections
UpdateFilter: {y: {$randomint: {min: 0, max: 1000}}}
UpdateFilter: {y: {$randomint: {distribution: poisson, mean: 100}}}
Update: {$inc: {x: 1}}
Phases:
- Operation: Nop
Expand All @@ -98,8 +100,8 @@ Actors:
Type: MultiCollectionQuery
Threads: 10
Database: *DB
CollectionCount: 10000 # This is specifically 10% of collections.
Filter: {y: {$randomint: {min: 0, max: 1000}}}
CollectionCount: 1000 # This is specifically 10% of collections.
Filter: {y: {$randomint: {distribution: poisson, mean: 100}}}
Limit: 20
Phases:
- Operation: Nop
Expand Down

0 comments on commit 195ae08

Please sign in to comment.