@@ -45,7 +45,9 @@ ABSL_FLAG(int32_t, qps, 20,
45
45
46
46
ABSL_FLAG (uint32_t , n, 1000 , " Number of requests to send per connection" );
47
47
ABSL_FLAG (uint32_t , test_time, 0 , " Testing time in seconds" );
48
- ABSL_FLAG (uint32_t , d, 16 , " Value size in bytes " );
48
+ ABSL_FLAG (string, d, " 16" ,
49
+ " Specify value size as single number for fixed length or use min:max to generate random "
50
+ " value length between min and max." );
49
51
ABSL_FLAG (string, h, " localhost" , " server hostname/ip" );
50
52
ABSL_FLAG (uint64_t , key_minimum, 0 , " Min value for keys used" );
51
53
ABSL_FLAG (uint64_t , key_maximum, 50'000'000 , " Max value for keys used" );
@@ -258,14 +260,19 @@ class CommandGenerator {
258
260
string FillSet (string_view key);
259
261
string FillGet (string_view key);
260
262
263
+ bool IsRandomValueLen () const {
264
+ return value_len_min_ != value_len_max_;
265
+ }
266
+
261
267
KeyGenerator* keygen_;
262
268
uint32_t ratio_set_ = 0 , ratio_get_ = 0 ;
263
269
string command_;
264
270
265
271
using CmdPart = variant<string_view, TemplateType>;
266
272
vector<CmdPart> cmd_parts_;
267
273
268
- string value_;
274
+ string fixed_len_value_; // used for fixed value string
275
+ int32_t value_len_min_ = 0 , value_len_max_ = 0 ;
269
276
bool might_hit_ = false ;
270
277
bool noreply_ = false ;
271
278
bool is_ascii_ = true ;
@@ -274,7 +281,25 @@ class CommandGenerator {
274
281
CommandGenerator::CommandGenerator (KeyGenerator* keygen) : keygen_(keygen) {
275
282
command_ = GetFlag (FLAGS_command);
276
283
is_ascii_ = GetFlag (FLAGS_ascii);
277
- value_ = string (GetFlag (FLAGS_d), is_ascii_ ? ' a' : char (130 ));
284
+
285
+ pair<string, string> value_len_str = absl::StrSplit (GetFlag (FLAGS_d), ' :' );
286
+ CHECK (absl::SimpleAtoi (value_len_str.first , &value_len_min_));
287
+ if (!value_len_str.second .empty ()) {
288
+ CHECK (absl::SimpleAtoi (value_len_str.second , &value_len_max_));
289
+ } else {
290
+ value_len_max_ = value_len_min_;
291
+ }
292
+
293
+ if ((value_len_min_ < 0 ) || (value_len_max_ < 0 ) || (value_len_min_ > value_len_max_)) {
294
+ LOG (ERROR) << " Invalid `-d " << GetFlag (FLAGS_d)
295
+ << " ` argument. Min and max values should be bigger than 0 and min value should "
296
+ " be smaller or equal to max. Setting to default (16)." ;
297
+ value_len_max_ = value_len_min_ = 16 ;
298
+ }
299
+
300
+ if (!IsRandomValueLen ()) {
301
+ fixed_len_value_ = string (value_len_min_, is_ascii_ ? ' a' : char (130 ));
302
+ }
278
303
279
304
if (command_.empty ()) {
280
305
pair<string, string> ratio_str = absl::StrSplit (GetFlag (FLAGS_ratio), ' :' );
@@ -335,9 +360,13 @@ string CommandGenerator::Next(SlotRange range) {
335
360
case KEY:
336
361
str = (*keygen_)(slot_id, slot_id);
337
362
break ;
338
- case VALUE:
339
- str = GetRandomHex (value_.size (), is_ascii_);
363
+ case VALUE: {
364
+ size_t value_len = IsRandomValueLen ()
365
+ ? absl::Uniform (bit_gen, value_len_min_, value_len_max_)
366
+ : fixed_len_value_.size ();
367
+ str = GetRandomHex (value_len, is_ascii_);
340
368
break ;
369
+ }
341
370
case SCORE: {
342
371
uniform_real_distribution<double > uniform (0 , 1 );
343
372
str = absl::StrCat (uniform (bit_gen));
@@ -352,19 +381,26 @@ string CommandGenerator::Next(SlotRange range) {
352
381
353
382
string CommandGenerator::FillSet (string_view key) {
354
383
string res;
384
+ string_view value = fixed_len_value_;
385
+ string random_len_value;
386
+
387
+ if (IsRandomValueLen ()) {
388
+ random_len_value = GetRandomHex (absl::Uniform (bit_gen, value_len_min_, value_len_max_), true );
389
+ value = random_len_value;
390
+ }
355
391
356
392
if (protocol == RESP) {
357
393
absl::StrAppend (&res, " *3\r\n $3\r\n set\r\n $" , key.size (), " \r\n " , key);
358
- absl::StrAppend (&res, " \r\n $" , value_ .size (), " \r\n " , value_ , " \r\n " );
394
+ absl::StrAppend (&res, " \r\n $" , value .size (), " \r\n " , value , " \r\n " );
359
395
} else {
360
396
DCHECK_EQ (protocol, MC_TEXT);
361
- absl::StrAppend (&res, " set " , key, " 0 0 " , value_ .size ());
397
+ absl::StrAppend (&res, " set " , key, " 0 0 " , value .size ());
362
398
if (GetFlag (FLAGS_noreply)) {
363
399
absl::StrAppend (&res, " noreply" );
364
400
noreply_ = true ;
365
401
}
366
402
367
- absl::StrAppend (&res, " \r\n " , value_ , " \r\n " );
403
+ absl::StrAppend (&res, " \r\n " , value , " \r\n " );
368
404
}
369
405
return res;
370
406
}
0 commit comments