Skip to content

Commit

Permalink
Don't allow unlimited queueing of request work
Browse files Browse the repository at this point in the history
This was just a test. In practice, the view can change frequently. We want to drop the work that doesn't make it.
  • Loading branch information
csciguy8 committed Dec 5, 2023
1 parent 2eeb071 commit 20f2b1b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ class RequestDispatcher {

void TakeCompletedWork(size_t maxCount, std::vector<TileLoadWork>& out);

size_t GetPendingCount();
size_t GetPendingRequestsCount();
size_t GetTotalPendingCount();

void GetRequestsStats(size_t& queued, size_t& inFlight, size_t& done);

Expand Down Expand Up @@ -580,7 +581,7 @@ class CESIUM3DTILESSELECTION_API Tileset final {
std::vector<TileLoadWork>& outRequestWork,
std::vector<TileLoadWork>& outImmediateWork);

void addWorkToRequestDispatcher(std::vector<TileLoadWork>& workVector);
void addWorkToRequestDispatcher(const std::vector<TileLoadWork>& workVector, size_t maxSimultaneousRequests);

void dispatchProcessingWork(std::vector<TileLoadWork>& workVector);

Expand Down
47 changes: 37 additions & 10 deletions Cesium3DTilesSelection/src/Tileset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ Tileset::updateView(const std::vector<ViewState>& frustums, float deltaTime) {
this->_pTilesetContentManager->getNumberOfRastersLoading();
result.rastersLoaded =
this->_pTilesetContentManager->getNumberOfRastersLoaded();
result.requestsPending = this->_requestDispatcher.GetPendingCount();
result.requestsPending = this->_requestDispatcher.GetTotalPendingCount();

assertViewResults();

Expand Down Expand Up @@ -1474,8 +1474,11 @@ void Tileset::_processWorkerThreadLoadQueue() {
newImmediateWork);

// Add all content requests to the dispatcher
if (newRequestWork.size() > 0)
addWorkToRequestDispatcher(newRequestWork);
size_t maxTileLoads =
static_cast<size_t>(this->_options.maximumSimultaneousTileLoads);
if (newRequestWork.size() > 0) {
addWorkToRequestDispatcher(newRequestWork, maxTileLoads);
}

//
// Define a queue of work to dispatch
Expand All @@ -1493,8 +1496,6 @@ void Tileset::_processWorkerThreadLoadQueue() {
assert(numberOfRastersLoading >= 0);
size_t totalLoads = static_cast<size_t>(numberOfTilesLoading) +
static_cast<size_t>(numberOfRastersLoading);
size_t maxTileLoads =
static_cast<size_t>(this->_options.maximumSimultaneousTileLoads);

// If there are slots available, add some completed request work
if (totalLoads < maxTileLoads) {
Expand Down Expand Up @@ -1708,10 +1709,31 @@ void Tileset::discoverLoadWork(
}
}

void Tileset::addWorkToRequestDispatcher(
std::vector<TileLoadWork>& workVector) {
void Tileset::addWorkToRequestDispatcher(const std::vector<TileLoadWork>& workVector, size_t maxSimultaneousRequests) {

for (TileLoadWork& work : workVector) {
// Determine how much incoming work we will accept
// Don't exceed our the max count passed in
size_t pendingRequestCount = this->_requestDispatcher.GetPendingRequestsCount();
assert(pendingRequestCount <= maxSimultaneousRequests);

size_t slotsOpen = maxSimultaneousRequests - pendingRequestCount;
if (slotsOpen == 0)
return;

std::vector<TileLoadWork> workToSubmit;
if (slotsOpen >= workVector.size ()) {
// We can take all incoming work
workToSubmit = workVector;
}
else {
// We can only take part of the incoming work
// Just submit the highest priority
workToSubmit = workVector;
std::sort(workToSubmit.begin(), workToSubmit.end());
workToSubmit.resize(slotsOpen);
}

for (TileLoadWork& work : workToSubmit) {
assert(!work.requestUrl.empty());

// Mark this tile as loading now so it doesn't get queued next frame
Expand All @@ -1737,7 +1759,7 @@ void Tileset::addWorkToRequestDispatcher(
workVector.size());

_requestDispatcher.QueueRequestWork(
workVector,
workToSubmit,
this->_pTilesetContentManager->getRequestHeaders());

_requestDispatcher.WakeIfNeeded();
Expand Down Expand Up @@ -1900,7 +1922,12 @@ void RequestDispatcher::stageRequestWork(
}
}

size_t RequestDispatcher::GetPendingCount() {
size_t RequestDispatcher::GetPendingRequestsCount() {
std::lock_guard<std::mutex> lock(_requestsLock);
return _queuedWork.size() + _inFlightWork.size();
}

size_t RequestDispatcher::GetTotalPendingCount() {
std::lock_guard<std::mutex> lock(_requestsLock);
return _queuedWork.size() + _inFlightWork.size() + _doneWork.size();
}
Expand Down

0 comments on commit 20f2b1b

Please sign in to comment.