@@ -58,6 +58,7 @@ TWorkloadCommand::TWorkloadCommand(const TString& name, const std::initializer_l
58
58
: TYdbCommand(name, aliases, description)
59
59
, TotalSec(0 )
60
60
, Threads(0 )
61
+ , Rate(0 )
61
62
, ClientTimeoutMs(0 )
62
63
, OperationTimeoutMs(0 )
63
64
, CancelAfterTimeoutMs(0 )
@@ -67,6 +68,7 @@ TWorkloadCommand::TWorkloadCommand(const TString& name, const std::initializer_l
67
68
, QueryExecuterType()
68
69
, WindowHist(60000 , 2 ) // highestTrackableValue 60000ms = 60s, precision 2
69
70
, TotalHist(60000 , 2 )
71
+ , TotalQueries(0 )
70
72
, TotalRetries(0 )
71
73
, WindowRetryCount(0 )
72
74
, TotalErrors(0 )
@@ -80,6 +82,17 @@ void TWorkloadCommand::Config(TConfig& config) {
80
82
.DefaultValue (10 ).StoreResult (&TotalSec);
81
83
config.Opts ->AddLongOption (' t' , " threads" , " Number of parallel threads in workload." )
82
84
.DefaultValue (10 ).StoreResult (&Threads);
85
+
86
+ const auto name = Parent->Parent ->Name ;
87
+ if (name == " kv" ) {
88
+ config.Opts ->AddLongOption (" rate" , " Total rate for all threads (requests per second)." )
89
+ .DefaultValue (0 ).StoreResult (&Rate);
90
+ }
91
+ else if (name == " stock" ) {
92
+ config.Opts ->AddLongOption (" rate" , " Total rate for all threads (transactions per second)." )
93
+ .DefaultValue (0 ).StoreResult (&Rate);
94
+ }
95
+
83
96
config.Opts ->AddLongOption (" quiet" , " Quiet mode. Doesn't print statistics each second." )
84
97
.StoreTrue (&Quiet);
85
98
config.Opts ->AddLongOption (" print-timestamp" , " Print timestamp each second with statistics." )
@@ -206,10 +219,22 @@ void TWorkloadCommand::WorkerFn(int taskId, NYdbWorkload::IWorkloadQueryGenerato
206
219
207
220
auto opStartTime = Now ();
208
221
NYdbWorkload::TQueryInfoList::iterator it;
209
- for (it = queryInfoList.begin (); it != queryInfoList.end (); ++it) {
222
+ for (it = queryInfoList.begin (); it != queryInfoList.end (); ) {
223
+
224
+ if (Rate != 0 )
225
+ {
226
+ const ui64 expectedQueries = (Now () - StartTime).SecondsFloat () * Rate;
227
+ if (TotalQueries > expectedQueries) {
228
+ Sleep (TDuration::MilliSeconds (1 ));
229
+ continue ;
230
+ }
231
+ }
232
+
210
233
queryInfo = *it;
211
234
auto status = runQuery ();
212
- if (!status.IsSuccess ()) {
235
+ if (status.IsSuccess ()) {
236
+ TotalQueries++;
237
+ } else {
213
238
TotalErrors++;
214
239
WindowErrors++;
215
240
// if (status.GetStatus() != EStatus::ABORTED) {
@@ -222,6 +247,8 @@ void TWorkloadCommand::WorkerFn(int taskId, NYdbWorkload::IWorkloadQueryGenerato
222
247
WindowRetryCount += retryCount;
223
248
}
224
249
retryCount = -1 ;
250
+
251
+ ++it;
225
252
}
226
253
if (it != queryInfoList.end ()) {
227
254
continue ;
0 commit comments