Skip to content

Commit 0a9d386

Browse files
committed
CCBC-1592: allow to generate more randomized bodies in pillowfight
By default cbc-pillowfight pre-generates only one document body per selected size. New option --random-body-pool-size allows to control how many documents will be generated (default is 100). This fixes behaviour in the corner case when --min-size equals --max-size and allow still have many random bodies in this case. Change-Id: If8dd15076950473f0539bea5037addafc6b6346e Reviewed-on: https://review.couchbase.org/c/libcouchbase/+/189713 Reviewed-by: Dave Rigby <daver@couchbase.com> Tested-by: Build Bot <build@couchbase.com>
1 parent aa643e1 commit 0a9d386

2 files changed

Lines changed: 23 additions & 12 deletions

File tree

tools/cbc-pillowfight.cc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ class Configuration
9999
public:
100100
Configuration()
101101
: o_multiSize("batch-size"), o_numItems("num-items"), o_keyPrefix("key-prefix"), o_numThreads("num-threads"),
102-
o_randSeed("random-seed"), o_randomBody("random-body"), o_setPercent("set-pct"), o_minSize("min-size"),
102+
o_randSeed("random-seed"), o_randomBody("random-body"), o_randomBodyPoolSize("random-body-pool-size"),
103+
o_setPercent("set-pct"), o_minSize("min-size"),
103104
o_maxSize("max-size"), o_noPopulate("no-population"), o_numCycles("num-cycles"), o_sequential("sequential"),
104105
o_startAt("start-at"), o_rateLimit("rate-limit"), o_userdocs("docs"), o_writeJson("json"),
105106
o_templatePairs("template"), o_subdoc("subdoc"), o_noop("noop"), o_sdPathCount("pathcount"),
@@ -114,6 +115,9 @@ class Configuration
114115
o_randSeed.setDefault(0).abbrev('s').description("Specify random seed").hide();
115116
o_randomBody.setDefault(false).abbrev('R').description(
116117
"Randomize document body (otherwise use 'x' and '*' to fill)");
118+
o_randomBodyPoolSize.setDefault(100).description(
119+
"How many of randomized documents should be generated for each size in the range [min-size..max-size]. "
120+
"Only used if --random-body is specified.");
117121
o_setPercent.setDefault(33).abbrev('r').description("The percentage of operations which should be mutations");
118122
o_minSize.setDefault(50).abbrev('m').description("Set minimum payload size");
119123
o_maxSize.setDefault(5120).abbrev('M').description("Set maximum payload size");
@@ -222,7 +226,8 @@ class Configuration
222226

223227
if (specs.empty()) {
224228
if (o_writeJson.result()) {
225-
docgen.reset(new JsonDocGenerator(o_minSize.result(), o_maxSize.result(), o_randomBody.numSpecified()));
229+
docgen.reset(new JsonDocGenerator(o_minSize.result(), o_maxSize.result(), o_randomBody.numSpecified(),
230+
o_randomBodyPoolSize.result()));
226231
} else if (!userdocs.empty()) {
227232
docgen.reset(new PresetDocGenerator(userdocs));
228233
} else {
@@ -232,7 +237,8 @@ class Configuration
232237
if (o_writeJson.result()) {
233238
if (userdocs.empty()) {
234239
docgen.reset(new PlaceholderJsonGenerator(o_minSize.result(), o_maxSize.result(), specs,
235-
o_randomBody.numSpecified()));
240+
o_randomBody.numSpecified(),
241+
o_randomBodyPoolSize.result()));
236242
} else {
237243
docgen.reset(new PlaceholderJsonGenerator(userdocs, specs));
238244
}
@@ -262,6 +268,7 @@ class Configuration
262268
parser.addOption(o_numThreads);
263269
parser.addOption(o_randSeed);
264270
parser.addOption(o_randomBody);
271+
parser.addOption(o_randomBodyPoolSize);
265272
parser.addOption(o_setPercent);
266273
parser.addOption(o_noPopulate);
267274
parser.addOption(o_minSize);
@@ -397,6 +404,7 @@ class Configuration
397404
UIntOption o_numThreads;
398405
UIntOption o_randSeed;
399406
BoolOption o_randomBody;
407+
UIntOption o_randomBodyPoolSize;
400408
UIntOption o_setPercent;
401409
UIntOption o_minSize;
402410
UIntOption o_maxSize;

tools/docgen/docgen.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -259,18 +259,18 @@ class JsonDocGenerator : public PresetDocGenerator
259259
* @param minsz Minimum JSON document size
260260
* @param maxsz Maximum JSON document size
261261
*/
262-
JsonDocGenerator(uint32_t minsz, uint32_t maxsz, int rnd)
262+
JsonDocGenerator(uint32_t minsz, uint32_t maxsz, int rnd, uint32_t pool_size)
263263
{
264-
genDocuments(minsz, maxsz, m_docs, rnd);
264+
genDocuments(minsz, maxsz, m_docs, rnd, pool_size);
265265
for (size_t ii = 0; ii < m_docs.size(); ++ii) {
266266
m_bufs.push_back(m_docs[ii].m_doc);
267267
}
268268
}
269269

270-
static void genDocuments(uint32_t minsz, uint32_t maxsz, std::vector< std::string > &out, int rnd)
270+
static void genDocuments(uint32_t minsz, uint32_t maxsz, std::vector< std::string > &out, int rnd, uint32_t pool_size)
271271
{
272272
std::vector< Doc > docs;
273-
genDocuments(minsz, maxsz, docs, rnd);
273+
genDocuments(minsz, maxsz, docs, rnd, pool_size);
274274
for (size_t ii = 0; ii < docs.size(); ++ii) {
275275
out.push_back(docs[ii].m_doc);
276276
}
@@ -290,11 +290,13 @@ class JsonDocGenerator : public PresetDocGenerator
290290
*orig = std::max(0, *orig - static_cast< int >(toDecr));
291291
}
292292

293-
static void genDocuments(uint32_t minsz, uint32_t maxsz, std::vector< Doc > &out, int rnd)
293+
static void genDocuments(uint32_t minsz, uint32_t maxsz, std::vector< Doc > &out, int rnd, uint32_t pool_size)
294294
{
295295
std::vector< size_t > sizes = RawDocGenerator::gen_graded_sizes(minsz, maxsz);
296-
for (std::vector< size_t >::iterator ii = sizes.begin(); ii != sizes.end(); ++ii) {
297-
out.push_back(generate(*ii, rnd));
296+
for (const auto &size : sizes) {
297+
for (uint32_t ii = 0; ii < pool_size; ++ii) {
298+
out.push_back(generate(size, rnd));
299+
}
298300
}
299301
}
300302

@@ -487,11 +489,12 @@ class PlaceholderJsonGenerator : public PlaceholderDocGenerator
487489
* @param minsz Minimum document size
488490
* @param maxsz Maximum document size
489491
*/
490-
PlaceholderJsonGenerator(uint32_t minsz, uint32_t maxsz, const std::vector< TemplateSpec > &specs, int rnd)
492+
PlaceholderJsonGenerator(uint32_t minsz, uint32_t maxsz, const std::vector<TemplateSpec> &specs, int rnd,
493+
uint32_t pool_size)
491494
{
492495

493496
std::vector< std::string > jsondocs;
494-
JsonDocGenerator::genDocuments(minsz, maxsz, jsondocs, rnd);
497+
JsonDocGenerator::genDocuments(minsz, maxsz, jsondocs, rnd, pool_size);
495498
initJsonPlaceholders(specs, jsondocs);
496499
}
497500

0 commit comments

Comments
 (0)