Skip to content

Commit

Permalink
Add GetGuaranteedReadRequestsPerFabric
Browse files Browse the repository at this point in the history
  • Loading branch information
erjiaqing committed Jun 6, 2022
1 parent 3b6f3ae commit 51c2006
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
15 changes: 6 additions & 9 deletions src/app/InteractionModelEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ bool InteractionModelEngine::EnsureResourceForSubscription(FabricIndex aFabricIn

bool InteractionModelEngine::TrimFabricForRead(FabricIndex aFabricIndex)
{
constexpr size_t minSupportedPathsPerFabricForRead = kMinSupportedReadRequestsPerFabric * kMinSupportedPathsPerReadRequest;
const size_t minSupportedPathsPerFabricForRead = GetGuaranteedReadRequestsPerFabric() * kMinSupportedPathsPerReadRequest;

size_t attributePathsUsedByCurrentFabric = 0;
size_t eventPathsUsedByCurrentFabric = 0;
Expand Down Expand Up @@ -841,7 +841,7 @@ bool InteractionModelEngine::TrimFabricForRead(FabricIndex aFabricIndex)
if (candidate != nullptr &&
((attributePathsUsedByCurrentFabric > minSupportedPathsPerFabricForRead ||
eventPathsUsedByCurrentFabric > minSupportedPathsPerFabricForRead ||
readTransactionsOnCurrentFabric > kMinSupportedReadRequestsPerFabric) ||
readTransactionsOnCurrentFabric > GetGuaranteedReadRequestsPerFabric()) ||
// Always evict the transactions on PASE sessions if the fabric table is full.
(aFabricIndex == kUndefinedFabricIndex && mpFabricTable->FabricCount() == GetConfigMaxFabrics())))
{
Expand Down Expand Up @@ -931,13 +931,10 @@ Protocols::InteractionModel::Status InteractionModelEngine::EnsureResourceForRea

// Resources exhausted, since there is already some read requests ongoing on this fabric, please retry later.
if (usedAttributePathsInFabric + aRequestedAttributePathCount >
kMinSupportedPathsPerReadRequest * kMinSupportedReadRequestsPerFabric ||
usedEventPathsInFabric + aRequestedEventPathCount > kMinSupportedPathsPerReadRequest * kMinSupportedReadRequestsPerFabric)
{
return Protocols::InteractionModel::Status::Busy;
}

if (usedReadHandlersInFabric >= kMinSupportedReadRequestsPerFabric)
kMinSupportedPathsPerReadRequest * GetGuaranteedReadRequestsPerFabric() ||
usedEventPathsInFabric + aRequestedEventPathCount >
kMinSupportedPathsPerReadRequest * GetGuaranteedReadRequestsPerFabric() ||
usedReadHandlersInFabric >= GetGuaranteedReadRequestsPerFabric())
{
return Protocols::InteractionModel::Status::Busy;
}
Expand Down
8 changes: 7 additions & 1 deletion src/app/InteractionModelEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler,

//
// Override the maximal capacity of the underlying read handler pool to mimic
// out of memory scenarios in unit-tests.
// out of memory scenarios in unit-tests. You need to SetConfigMaxFabrics to make GetGuaranteedReadRequestsPerFabric
// working correctly.
//
// If -1 is passed in, no override is instituted and default behavior resumes.
//
Expand Down Expand Up @@ -441,6 +442,11 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler,
#endif
}

inline size_t GetGuaranteedReadRequestsPerFabric() const
{
return GetReadHandlerPoolCapacityForReads() / GetConfigMaxFabrics();
}

/**
* Verify and ensure (by killing oldest read handlers that make the resources used by the current fabric exceed the fabric
* quota)
Expand Down
3 changes: 2 additions & 1 deletion src/controller/tests/data_model/TestRead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2436,6 +2436,7 @@ void TestReadInteraction::TestReadHandler_ParallelReads(nlTestSuite * apSuite, v

app::InteractionModelEngine::GetInstance()->SetForceHandlerQuota(true);
app::InteractionModelEngine::GetInstance()->SetHandlerCapacityForReads(2);
app::InteractionModelEngine::GetInstance()->SetConfigMaxFabrics(2);
app::InteractionModelEngine::GetInstance()->SetPathPoolCapacityForReads(
2 * app::InteractionModelEngine::kMinSupportedPathsPerReadRequest);

Expand Down Expand Up @@ -2597,7 +2598,7 @@ void TestReadInteraction::TestReadHandler_ParallelReads(nlTestSuite * apSuite, v
// Case 5: The device's fabric table is not full, PASE sessions are counted as a valid fabric and can evict existing read
// transactions.
{
app::InteractionModelEngine::GetInstance()->SetConfigMaxFabrics(-1);
app::InteractionModelEngine::GetInstance()->SetConfigMaxFabrics(3);

TestReadCallback readCallback;
TestPerpetualListReadCallback backgroundReadCallback1;
Expand Down

0 comments on commit 51c2006

Please sign in to comment.