@@ -179,59 +179,95 @@ namespace NKikimr {
179
179
180
180
class TThrottlingController {
181
181
private:
182
+ NMonGroup::TSkeletonOverloadGroup& Mon;
183
+
182
184
struct TControls {
185
+ TControlWrapper DeviceSpeed;
183
186
TControlWrapper MinSstCount;
184
187
TControlWrapper MaxSstCount;
185
- TControlWrapper DeviceSpeed;
188
+ TControlWrapper MinInplacedSize;
189
+ TControlWrapper MaxInplacedSize;
186
190
187
191
TControls ()
188
- : MinSstCount(16 , 1 , 200 )
189
- , MaxSstCount(64 , 1 , 200 )
190
- , DeviceSpeed(50 << 20 , 1 << 20 , 1 << 30 )
192
+ : DeviceSpeed(50 << 20 , 1 << 20 , 1 << 30 )
193
+ , MinSstCount(100 , 1 , 1000 )
194
+ , MaxSstCount(250 , 1 , 1000 )
195
+ , MinInplacedSize(20ull << 30 , 0 , 500ull < 30 )
196
+ , MaxInplacedSize(60ull << 30 , 0 , 500ull < 30 )
191
197
{}
192
198
193
199
void Register (TIntrusivePtr<TControlBoard> icb) {
200
+ icb->RegisterSharedControl (DeviceSpeed, " VDiskControls.ThrottlingDeviceSpeed" );
194
201
icb->RegisterSharedControl (MinSstCount, " VDiskControls.ThrottlingMinSstCount" );
195
202
icb->RegisterSharedControl (MaxSstCount, " VDiskControls.ThrottlingMaxSstCount" );
196
- icb->RegisterSharedControl (DeviceSpeed, " VDiskControls.ThrottlingDeviceSpeed" );
203
+ icb->RegisterSharedControl (MinInplacedSize, " VDiskControls.ThrottlingMinInplacedSize" );
204
+ icb->RegisterSharedControl (MaxInplacedSize, " VDiskControls.ThrottlingMaxInplacedSize" );
197
205
}
198
206
};
199
207
TControls Controls;
200
208
201
209
ui64 CurrentSstCount = 0 ;
210
+ ui64 CurrentInplacedSize = 0 ;
202
211
203
212
TInstant CurrentTime;
213
+ ui64 CurrentSpeedLimit = 0 ;
204
214
ui64 AvailableBytes = 0 ;
205
215
206
- ui64 GetCurrentSpeedLimit () const {
207
- ui64 minSstCount = (ui64)Controls.MinSstCount ;
208
- ui64 maxSstCount = (ui64)Controls.MaxSstCount ;
209
- ui64 deviceSpeed = (ui64)Controls.DeviceSpeed ;
210
-
211
- if (maxSstCount <= minSstCount) {
212
- return deviceSpeed;
216
+ private:
217
+ static ui64 LinearInterpolation (ui64 curX, ui64 minX, ui64 maxX, ui64 fromY) {
218
+ if (maxX <= minX) {
219
+ return fromY;
213
220
}
214
- if (CurrentSstCount <= minSstCount ) {
215
- return deviceSpeed ;
221
+ if (curX <= minX ) {
222
+ return fromY ;
216
223
}
217
- if (CurrentSstCount >= maxSstCount ) {
224
+ if (curX >= maxX ) {
218
225
return 0 ;
219
226
}
220
- return (double )(maxSstCount - CurrentSstCount) * deviceSpeed / (maxSstCount - minSstCount);
227
+ return (double )(maxX - curX) * fromY / (maxX - minX);
228
+ }
229
+
230
+ ui64 CalcSstCountSpeedLimit () const {
231
+ ui64 deviceSpeed = (ui64)Controls.DeviceSpeed ;
232
+ ui64 minSstCount = (ui64)Controls.MinSstCount ;
233
+ ui64 maxSstCount = (ui64)Controls.MaxSstCount ;
234
+
235
+ return LinearInterpolation (CurrentSstCount, minSstCount, maxSstCount, deviceSpeed);
236
+ }
237
+
238
+ ui64 CalcInplacedSizeSpeedLimit () const {
239
+ ui64 deviceSpeed = (ui64)Controls.DeviceSpeed ;
240
+ ui64 minInplacedSize = (ui64)Controls.MinInplacedSize ;
241
+ ui64 maxInplacedSize = (ui64)Controls.MaxInplacedSize ;
242
+
243
+ return LinearInterpolation (CurrentInplacedSize, minInplacedSize, maxInplacedSize, deviceSpeed);
244
+ }
245
+
246
+ ui64 CalcCurrentSpeedLimit () const {
247
+ ui64 sstCountSpeedLimit = CalcSstCountSpeedLimit ();
248
+ ui64 inplacedSizeSpeedLimit = CalcInplacedSizeSpeedLimit ();
249
+ return std::min (sstCountSpeedLimit, inplacedSizeSpeedLimit);
221
250
}
222
251
223
252
public:
253
+ explicit TThrottlingController (NMonGroup::TSkeletonOverloadGroup& mon)
254
+ : Mon(mon)
255
+ {}
256
+
224
257
void RegisterIcbControls (TIntrusivePtr<TControlBoard> icb) {
225
258
Controls.Register (icb);
226
259
}
227
260
228
261
bool IsActive () const {
229
262
ui64 minSstCount = (ui64)Controls.MinSstCount ;
230
- return CurrentSstCount > minSstCount;
263
+ ui64 minInplacedSize = (ui64)Controls.MinInplacedSize ;
264
+
265
+ return CurrentSstCount > minSstCount ||
266
+ CurrentInplacedSize > minInplacedSize;
231
267
}
232
268
233
269
TDuration BytesToDuration (ui64 bytes) const {
234
- auto limit = GetCurrentSpeedLimit () ;
270
+ auto limit = CurrentSpeedLimit ;
235
271
if (limit == 0 ) {
236
272
return TDuration::Seconds (1 );
237
273
}
@@ -247,26 +283,38 @@ namespace NKikimr {
247
283
return AvailableBytes;
248
284
}
249
285
250
- void UpdateState (TInstant now, ui64 sstCount) {
286
+ void UpdateState (TInstant now, ui64 sstCount, ui64 inplacedSize ) {
251
287
bool prevActive = IsActive ();
252
288
253
289
CurrentSstCount = sstCount;
290
+ Mon.ThrottlingLevel0SstCount () = sstCount;
291
+
292
+ CurrentInplacedSize = inplacedSize;
293
+ Mon.ThrottlingAllLevelsInplacedSize () = inplacedSize;
294
+
295
+ Mon.ThrottlingIsActive () = (ui64)IsActive ();
254
296
255
297
if (!IsActive ()) {
256
298
CurrentTime = {};
257
299
AvailableBytes = 0 ;
258
- } else if (!prevActive) {
259
- CurrentTime = now;
260
- AvailableBytes = 0 ;
300
+ CurrentSpeedLimit = (ui64)Controls.DeviceSpeed ;
301
+ } else {
302
+ if (!prevActive) {
303
+ CurrentTime = now;
304
+ AvailableBytes = 0 ;
305
+ }
306
+ CurrentSpeedLimit = CalcCurrentSpeedLimit ();
261
307
}
308
+
309
+ Mon.ThrottlingCurrentSpeedLimit () = CurrentSpeedLimit;
262
310
}
263
311
264
312
void UpdateTime (TInstant now) {
265
313
if (now <= CurrentTime) {
266
314
return ;
267
315
}
268
316
auto us = (now - CurrentTime).MicroSeconds ();
269
- AvailableBytes += GetCurrentSpeedLimit () * us / 1000000 ; // overflow ?
317
+ AvailableBytes += CurrentSpeedLimit * us / 1000000 ;
270
318
ui64 deviceSpeed = (ui64)Controls.DeviceSpeed ;
271
319
AvailableBytes = Min (AvailableBytes, deviceSpeed);
272
320
CurrentTime = now;
@@ -292,7 +340,7 @@ namespace NKikimr {
292
340
, EmergencyQueue(new TEmergencyQueue(Mon, std::move(vMovedPatch), std::move(vPatchStart), std::move(vput),
293
341
std::move (vMultiPut), std::move(loc), std::move(aoput)))
294
342
, DynamicPDiskWeightsManager(std::make_shared<TDynamicPDiskWeightsManager>(vctx, pdiskCtx))
295
- , ThrottlingController(new TThrottlingController)
343
+ , ThrottlingController(new TThrottlingController(Mon) )
296
344
{}
297
345
298
346
TOverloadHandler::~TOverloadHandler () {}
@@ -333,10 +381,12 @@ namespace NKikimr {
333
381
auto snapshot = Hull->GetSnapshot (); // THullDsSnap
334
382
auto & logoBlobsSnap = snapshot.LogoBlobsSnap ; // TLogoBlobsSnapshot
335
383
auto & sliceSnap = logoBlobsSnap.SliceSnap ; // TLevelSliceSnapshot
384
+
336
385
auto sstCount = sliceSnap.GetLevel0SstsNum ();
386
+ auto dataInplacedSize = logoBlobsSnap.AllLevelsDataInplaced ;
337
387
338
388
auto now = ctx.Now ();
339
- ThrottlingController->UpdateState (now, sstCount);
389
+ ThrottlingController->UpdateState (now, sstCount, dataInplacedSize );
340
390
341
391
if (ThrottlingController->IsActive ()) {
342
392
ThrottlingController->UpdateTime (now);
0 commit comments