Skip to content

Commit 0a68308

Browse files
dom-hernandezMongoDB Bot
authored and
MongoDB Bot
committedFeb 5, 2025
SERVER-99656: Add throughput probing state metrics (#31765)
GitOrigin-RevId: 13f4d503dd23c784b91d96260fd14d9a06793929
1 parent 222c3cd commit 0a68308

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed
 

‎src/mongo/db/admission/throughput_probing.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ std::pair<int32_t, int32_t> newReadWriteConcurrencies(double stableConcurrency,
196196

197197
void ThroughputProbing::_probeStable(OperationContext* opCtx, double throughput) {
198198
invariant(_state == ProbingState::kStable);
199-
200199
LOGV2_DEBUG(7346000, 3, "Throughput Probing: stable", "throughput"_attr = throughput);
201200

202201
// Record the baseline reading.
@@ -218,6 +217,8 @@ void ThroughputProbing::_probeStable(OperationContext* opCtx, double throughput)
218217
_state = ProbingState::kDown;
219218
_decreaseConcurrency(opCtx);
220219
}
220+
// Due to the time resize concurrency takes, increment after increase/decrease
221+
_stats.timesProbedStable.fetchAndAdd(1);
221222
}
222223

223224
void ThroughputProbing::_probeUp(OperationContext* opCtx, double throughput) {
@@ -249,6 +250,8 @@ void ThroughputProbing::_probeUp(OperationContext* opCtx, double throughput) {
249250
_state = ProbingState::kStable;
250251
_resetConcurrency(opCtx);
251252
}
253+
// Due to the time resize concurrency takes, increment after reset
254+
_stats.timesProbedUp.fetchAndAdd(1);
252255
}
253256

254257
void ThroughputProbing::_probeDown(OperationContext* opCtx, double throughput) {
@@ -280,6 +283,8 @@ void ThroughputProbing::_probeDown(OperationContext* opCtx, double throughput) {
280283
_state = ProbingState::kStable;
281284
_resetConcurrency(opCtx);
282285
}
286+
// Due to the time resize concurrency takes, increment after reset
287+
_stats.timesProbedDown.fetchAndAdd(1);
283288
}
284289

285290
void ThroughputProbing::_resize(OperationContext* opCtx,
@@ -375,6 +380,9 @@ void ThroughputProbing::Stats::serialize(BSONObjBuilder& builder) const {
375380
builder.append("totalAmountDecreased", static_cast<long long>(totalAmountDecreased.load()));
376381
builder.append("totalAmountIncreased", static_cast<long long>(totalAmountIncreased.load()));
377382
builder.append("resizeDurationMicros", static_cast<long long>(resizeDurationMicros.load()));
383+
builder.append("timesProbedStable", static_cast<long long>(timesProbedStable.load()));
384+
builder.append("timesProbedUp", static_cast<long long>(timesProbedUp.load()));
385+
builder.append("timesProbedDown", static_cast<long long>(timesProbedDown.load()));
378386
}
379387

380388
ThroughputProbingTicketHolderManager::ThroughputProbingTicketHolderManager(

‎src/mongo/db/admission/throughput_probing.h

+3
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ class ThroughputProbing {
109109
AtomicWord<int64_t> totalAmountDecreased;
110110
AtomicWord<int64_t> totalAmountIncreased;
111111
AtomicWord<int64_t> resizeDurationMicros;
112+
AtomicWord<int64_t> timesProbedStable;
113+
AtomicWord<int64_t> timesProbedUp;
114+
AtomicWord<int64_t> timesProbedDown;
112115
} _stats;
113116

114117
PeriodicJobAnchor _job;

‎src/mongo/db/admission/throughput_probing_test.cpp

+24-2
Original file line numberDiff line numberDiff line change
@@ -145,17 +145,23 @@ class ThroughputProbingTest : public ServiceContextTest {
145145
return !concurrencyIncreased() && !concurrencyDecreased();
146146
}
147147

148+
bool probeIncemented(std::string a) const {
149+
return _stats[a].Long() > _prevStats[a].Long();
150+
}
151+
148152
std::string toString() const {
149153
return str::stream() << "Stats: " << _stats << ", previous stats: " << _prevStats;
150154
}
151155

152156
private:
153157
BSONObj _stats =
154158
BSON("timesDecreased" << 0ll << "timesIncreased" << 0ll << "totalAmountDecreased" << 0ll
155-
<< "totalAmountIncreased" << 0ll);
159+
<< "totalAmountIncreased" << 0ll << "timesProbedStable" << 0ll
160+
<< "timesProbedUp" << 0ll << "timesProbedDown" << 0ll);
156161
BSONObj _prevStats =
157162
BSON("timesDecreased" << 0ll << "timesIncreased" << 0ll << "totalAmountDecreased" << 0ll
158-
<< "totalAmountIncreased" << 0ll);
163+
<< "totalAmountIncreased" << 0ll << "timesProbedStable" << 0ll
164+
<< "timesProbedUp" << 0ll << "timesProbedDown" << 0ll);
159165
} _statsTester;
160166
};
161167

@@ -208,6 +214,9 @@ TEST_F(ThroughputProbingTest, ProbeUpSucceeds) {
208214
ASSERT_GT(_readTicketHolder.outof(), initialSize);
209215
ASSERT_LT(_writeTicketHolder.outof(), size);
210216
ASSERT_GT(_writeTicketHolder.outof(), initialSize);
217+
ASSERT_TRUE(_statsTester.probeIncemented("timesProbedUp"));
218+
ASSERT_FALSE(_statsTester.probeIncemented("timesProbedDown"));
219+
ASSERT_FALSE(_statsTester.probeIncemented("timesProbedStable"));
211220
ASSERT(_statsTester.concurrencyIncreased()) << _statsTester.toString();
212221
}
213222

@@ -231,6 +240,9 @@ TEST_F(ThroughputProbingTest, ProbeUpFails) {
231240
_run();
232241
ASSERT_EQ(_readTicketHolder.outof(), size);
233242
ASSERT_EQ(_writeTicketHolder.outof(), size);
243+
ASSERT_TRUE(_statsTester.probeIncemented("timesProbedUp"));
244+
ASSERT_FALSE(_statsTester.probeIncemented("timesProbedDown"));
245+
ASSERT_FALSE(_statsTester.probeIncemented("timesProbedStable"));
234246
ASSERT(_statsTester.concurrencyKept()) << _statsTester.toString();
235247
}
236248

@@ -259,6 +271,9 @@ TEST_F(ThroughputProbingTest, ProbeDownSucceeds) {
259271
ASSERT_GT(_readTicketHolder.outof(), size);
260272
ASSERT_LT(_writeTicketHolder.outof(), initialSize);
261273
ASSERT_GT(_writeTicketHolder.outof(), size);
274+
ASSERT_TRUE(_statsTester.probeIncemented("timesProbedDown"));
275+
ASSERT_FALSE(_statsTester.probeIncemented("timesProbedUp"));
276+
ASSERT_FALSE(_statsTester.probeIncemented("timesProbedStable"));
262277
ASSERT(_statsTester.concurrencyDecreased()) << _statsTester.toString();
263278
}
264279

@@ -282,6 +297,9 @@ TEST_F(ThroughputProbingTest, ProbeDownFails) {
282297
_run();
283298
ASSERT_EQ(_readTicketHolder.outof(), size);
284299
ASSERT_EQ(_writeTicketHolder.outof(), size);
300+
ASSERT_TRUE(_statsTester.probeIncemented("timesProbedDown"));
301+
ASSERT_FALSE(_statsTester.probeIncemented("timesProbedUp"));
302+
ASSERT_FALSE(_statsTester.probeIncemented("timesProbedStable"));
285303
ASSERT(_statsTester.concurrencyKept()) << _statsTester.toString();
286304
}
287305

@@ -295,6 +313,8 @@ TEST_F(ThroughputProbingMaxConcurrencyTest, NoProbeUp) {
295313
// Stable. Probe down since concurrency is already at its maximum allowed value, even though
296314
// ticktes are exhausted.
297315
_run();
316+
ASSERT_TRUE(_statsTester.probeIncemented("timesProbedStable"));
317+
ASSERT_FALSE(_statsTester.probeIncemented("timesProbedUp"));
298318
ASSERT_LT(_readTicketHolder.outof(), size);
299319
ASSERT_LT(_writeTicketHolder.outof(), size);
300320
}
@@ -309,6 +329,8 @@ TEST_F(ThroughputProbingMinConcurrencyTest, NoProbeDown) {
309329
// Stable. Do not probe in either direction since tickets are not exhausted but concurrency is
310330
// already at its minimum allowed value.
311331
_run();
332+
ASSERT_TRUE(_statsTester.probeIncemented("timesProbedStable"));
333+
ASSERT_FALSE(_statsTester.probeIncemented("timesProbedDown"));
312334
ASSERT_EQ(_readTicketHolder.outof(), size);
313335
ASSERT_EQ(_writeTicketHolder.outof(), size);
314336
}

0 commit comments

Comments
 (0)
Failed to load comments.