Skip to content

Commit

Permalink
Remove RequestQueue code
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Jul 5, 2018
1 parent 6a8fcfa commit 23e71dc
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 441 deletions.
186 changes: 0 additions & 186 deletions Source/Core/RequestQueue.js

This file was deleted.

82 changes: 43 additions & 39 deletions Source/Core/RequestScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ define([
'./defined',
'./defineProperties',
'./Event',
'./Heap',
'./isBlobUri',
'./isDataUri',
'./RequestQueue',
'./RequestState'
], function(
Uri,
Expand All @@ -18,12 +18,16 @@ define([
defined,
defineProperties,
Event,
Heap,
isBlobUri,
isDataUri,
RequestQueue,
RequestState) {
'use strict';

function sortRequests(a, b) {
return a.priority - b.priority;
}

var statistics = {
numberOfAttemptedRequests : 0,
numberOfActiveRequests : 0,
Expand All @@ -33,8 +37,12 @@ define([
numberOfActiveRequestsEver : 0
};

var requestQueueLength = 20;
var requestQueue = new RequestQueue(requestQueueLength);
var priorityHeapLength = 20;
var requestHeap = new Heap({
comparator : sortRequests
});
requestHeap.maximumLength = priorityHeapLength;
requestHeap.reserve(priorityHeapLength);

var activeRequests = [];
var numberOfActiveRequestsByServer = {};
Expand Down Expand Up @@ -115,28 +123,29 @@ define([
},

/**
* The maximum length of the request queue. This limits the number of requests that are sorted by priority. Only applies to requests that are not yet active.
* The maximum size of the priority heap. This limits the number of requests that are sorted by priority. Only applies to requests that are not yet active.
*
* @memberof RequestScheduler
*
* @type {Number}
* @default 20
*
* @private
*/
requestQueueLength : {
priorityHeapLength : {
get : function() {
return requestQueueLength;
return priorityHeapLength;
},
set : function(value) {
// Cancel all requests and resize the queue
var length = requestQueue.length;
for (var i = 0; i < length; ++i) {
var request = requestQueue.get(i);
cancelRequest(request);
// If the new length shrinks the heap, need to cancel some of the requests.
// Since this value is not intended to be tweaked regularly it is fine to just cancel the high priority requests.
if (value < priorityHeapLength) {
while (requestHeap.length > value) {
var request = requestHeap.pop();
cancelRequest(request);
}
}
requestQueue = new RequestQueue(value);
RequestScheduler.requestQueue = requestQueue;
priorityHeapLength = value;
requestHeap.maximumLength = value;
requestHeap.reserve(value);
}
}
});
Expand Down Expand Up @@ -245,19 +254,21 @@ define([
}
activeRequests.length -= removeCount;

// Update priority of issued requests and resort the queue
requestQueue.forEach(updatePriority);
requestQueue.sort();
// Update priority of issued requests and resort the heap
var issuedRequests = requestHeap.internalArray;
var issuedLength = requestHeap.length;
for (i = 0; i < issuedLength; ++i) {
updatePriority(issuedRequests[i]);
}
requestHeap.resort();

// Get the number of open slots and fill with the highest priority requests.
// Un-throttled requests are automatically added to activeRequests, so activeRequests.length may exceed maximumRequests
var openSlots = Math.max(RequestScheduler.maximumRequests - activeRequests.length, 0);
var filledSlots = 0;
var processedRequests = 0;
var totalRequests = requestQueue.length;
while (filledSlots < openSlots && processedRequests < totalRequests) {
// Loop until all open slots are filled or the queue becomes empty
request = requestQueue.get(processedRequests++);
while (filledSlots < openSlots && requestHeap.length > 0) {
// Loop until all open slots are filled or the heap becomes empty
request = requestHeap.pop();
if (request.cancelled) {
// Request was explicitly cancelled
cancelRequest(request);
Expand All @@ -273,7 +284,6 @@ define([
startRequest(request);
++filledSlots;
}
requestQueue.remove(processedRequests);

updateStatistics();
};
Expand Down Expand Up @@ -346,9 +356,10 @@ define([
return undefined;
}

// Insert into the priority queue and see if a request was bumped off. If this request is the lowest priority it will be returned.
// Insert into the priority heap and see if a request was bumped off. If this request is the lowest
// priority it will be returned.
updatePriority(request);
var removedRequest = requestQueue.insert(request);
var removedRequest = requestHeap.insert(request);

if (defined(removedRequest)) {
if (removedRequest === request) {
Expand Down Expand Up @@ -398,19 +409,12 @@ define([
* @private
*/
RequestScheduler.clearForSpecs = function() {
var request;
var length;
var i;

length = requestQueue.length;
for (i = 0; i < length; ++i) {
request = requestQueue.get(i);
while (requestHeap.length > 0) {
var request = requestHeap.pop();
cancelRequest(request);
}
requestQueue.remove(length);

length = activeRequests.length;
for (i = 0; i < length; ++i) {
var length = activeRequests.length;
for (var i = 0; i < length; ++i) {
cancelRequest(activeRequests[i]);
}
activeRequests.length = 0;
Expand Down Expand Up @@ -439,7 +443,7 @@ define([
*
* @private
*/
RequestScheduler.requestQueue = requestQueue;
RequestScheduler.requestHeap = requestHeap;

return RequestScheduler;
});
6 changes: 0 additions & 6 deletions Source/Scene/GlobeSurfaceTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ define([
'../Core/defineProperties',
'../Core/IntersectionTests',
'../Core/PixelFormat',
'../Core/Rectangle',
'../Renderer/PixelDatatype',
'../Renderer/Sampler',
'../Renderer/Texture',
Expand All @@ -29,7 +28,6 @@ define([
defineProperties,
IntersectionTests,
PixelFormat,
Rectangle,
PixelDatatype,
Sampler,
Texture,
Expand Down Expand Up @@ -256,10 +254,6 @@ define([

function createPriorityFunction(surfaceTile, frameState) {
return function() {
if (Rectangle.contains(surfaceTile.tileBoundingRegion.rectangle, frameState.camera.positionCartographic)) {
// If the camera is inside this tile's bounding region treat it as highest priority
return 0.0;
}
return surfaceTile.tileBoundingRegion.distanceToCamera(frameState);
};
}
Expand Down
Loading

0 comments on commit 23e71dc

Please sign in to comment.