Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions Source/Core/RequestScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ define([
'../ThirdParty/Uri',
'../ThirdParty/when',
'./Check',
'./defaultValue',
'./defined',
'./defineProperties',
'./Event',
Expand All @@ -13,6 +14,7 @@ define([
Uri,
when,
Check,
defaultValue,
defined,
defineProperties,
Event,
Expand Down Expand Up @@ -67,12 +69,21 @@ define([
RequestScheduler.maximumRequests = 50;

/**
* The maximum number of simultaneous active requests per server. Un-throttled requests do not observe this limit.
* The maximum number of simultaneous active requests per server. Un-throttled requests or servers specifically
* listed in requestsByServer do not observe this limit.
* @type {Number}
* @default 6
*/
RequestScheduler.maximumRequestsPerServer = 6;

/**
* A per serverKey list of overrides to use for throttling instead of maximumRequestsPerServer
*/
RequestScheduler.requestsByServer = {
'api.cesium.com:443': 18,
'assets.cesium.com:443': 18
};

/**
* Specifies if the request scheduler should throttle incoming requests, or let the browser queue requests under its control.
* @type {Boolean}
Expand Down Expand Up @@ -146,7 +157,8 @@ define([
}

function serverHasOpenSlots(serverKey) {
return numberOfActiveRequestsByServer[serverKey] < RequestScheduler.maximumRequestsPerServer;
var maxRequests = defaultValue(RequestScheduler.requestsByServer[serverKey], RequestScheduler.maximumRequestsPerServer);
return numberOfActiveRequestsByServer[serverKey] < maxRequests;
}

function issueRequest(request) {
Expand Down
75 changes: 52 additions & 23 deletions Specs/Core/RequestSchedulerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,25 @@ defineSuite([
var originalMaximumRequests;
var originalMaximumRequestsPerServer;
var originalPriorityHeapLength;
var originalRequestsByServer;

beforeAll(function() {
originalMaximumRequests = RequestScheduler.maximumRequests;
originalMaximumRequestsPerServer = RequestScheduler.maximumRequestsPerServer;
originalPriorityHeapLength = RequestScheduler.priorityHeapLength;
originalRequestsByServer = RequestScheduler.requestsByServer;
});

beforeEach(function() {
RequestScheduler.clearForSpecs();
RequestScheduler.requestsByServer = {};
});

afterEach(function() {
RequestScheduler.maximumRequests = originalMaximumRequests;
RequestScheduler.maximumRequestsPerServer = originalMaximumRequestsPerServer;
RequestScheduler.priorityHeapLength = originalPriorityHeapLength;
RequestScheduler.requestsByServer = originalRequestsByServer;
});

it('request throws when request is undefined', function() {
Expand Down Expand Up @@ -61,13 +65,13 @@ defineSuite([
});

it('getServer with https', function() {
var server = RequestScheduler.getServerKey('https://foo.com/1');
expect(server).toEqual('foo.com:443');
var server = RequestScheduler.getServerKey('https://test.invalid/1');
expect(server).toEqual('test.invalid:443');
});

it('getServer with http', function() {
var server = RequestScheduler.getServerKey('http://foo.com/1');
expect(server).toEqual('foo.com:80');
var server = RequestScheduler.getServerKey('http://test.invalid/1');
expect(server).toEqual('test.invalid:80');
});

it('honors maximumRequests', function() {
Expand All @@ -84,7 +88,7 @@ defineSuite([

function createRequest() {
return new Request({
url : 'http://foo.com/1',
url : 'http://test.invalid/1',
requestFunction : requestFunction,
throttle : true
});
Expand Down Expand Up @@ -147,7 +151,7 @@ defineSuite([
return deferred.promise;
}

var url = 'http://foo.com/1';
var url = 'http://test.invalid/1';
var server = RequestScheduler.getServerKey(url);

function createRequest() {
Expand Down Expand Up @@ -216,7 +220,7 @@ defineSuite([

function createRequest(priority) {
var request = new Request({
url : 'http://foo.com/1',
url : 'http://test.invalid/1',
requestFunction : requestFunction,
throttle : true,
priority : priority
Expand Down Expand Up @@ -302,7 +306,7 @@ defineSuite([
});

it('request goes through immediately when throttle is false', function() {
var url = 'https://foo.com/1';
var url = 'https://test.invalid/1';
testImmediateRequest(url, false);
});

Expand All @@ -317,7 +321,7 @@ defineSuite([

var request = new Request({
throttle : true,
url : 'https://foo.com/1',
url : 'https://test.invalid/1',
requestFunction : requestFunction
});
expect(request.state).toBe(RequestState.UNISSUED);
Expand All @@ -342,7 +346,7 @@ defineSuite([

var request = new Request({
throttle : true,
url : 'https://foo.com/1',
url : 'https://test.invalid/1',
requestFunction : requestFunction
});

Expand Down Expand Up @@ -373,7 +377,7 @@ defineSuite([

var request = new Request({
throttle : true,
url : 'https://foo.com/1',
url : 'https://test.invalid/1',
requestFunction : requestFunction,
cancelFunction : cancelFunction
});
Expand Down Expand Up @@ -409,7 +413,7 @@ defineSuite([
}

var request = new Request({
url : 'https://foo.com/1',
url : 'https://test.invalid/1',
requestFunction : requestFunction
});

Expand Down Expand Up @@ -442,7 +446,7 @@ defineSuite([
function createRequest(priority) {
return new Request({
throttle : true,
url : 'https://foo.com/1',
url : 'https://test.invalid/1',
requestFunction : getRequestFunction(priority),
priority : priority
});
Expand Down Expand Up @@ -477,7 +481,7 @@ defineSuite([
function createRequest(priority) {
return new Request({
throttle : true,
url : 'https://foo.com/1',
url : 'https://test.invalid/1',
requestFunction : requestFunction,
priorityFunction : getPriorityFunction(priority)
});
Expand Down Expand Up @@ -529,7 +533,7 @@ defineSuite([
function createRequest(priority) {
return new Request({
throttle : true,
url : 'https://foo.com/1',
url : 'https://test.invalid/1',
requestFunction : requestFunction,
priority : priority
});
Expand Down Expand Up @@ -566,7 +570,7 @@ defineSuite([

function createRequest(throttle) {
return new Request({
url : 'http://foo.com/1',
url : 'http://test.invalid/1',
requestFunction : requestFunction,
throttle : throttle
});
Expand Down Expand Up @@ -604,7 +608,7 @@ defineSuite([

function createRequest(throttleByServer) {
return new Request({
url : 'http://foo.com/1',
url : 'http://test.invalid/1',
requestFunction : requestFunction,
throttleByServer : throttleByServer
});
Expand Down Expand Up @@ -637,7 +641,7 @@ defineSuite([
RequestScheduler.throttleRequests = true;
var request = new Request({
throttle : true,
url : 'https://foo.com/1',
url : 'https://test.invalid/1',
requestFunction : requestFunction
});
var promise = RequestScheduler.request(request);
Expand All @@ -646,7 +650,7 @@ defineSuite([
RequestScheduler.throttleRequests = false;
request = new Request({
throttle : true,
url : 'https://foo.com/1',
url : 'https://test.invalid/1',
requestFunction : requestFunction
});
promise = RequestScheduler.request(request);
Expand All @@ -669,7 +673,7 @@ defineSuite([

function createRequest() {
return new Request({
url : 'https://foo.com/1',
url : 'https://test.invalid/1',
requestFunction : requestFunction
});
}
Expand Down Expand Up @@ -708,7 +712,7 @@ defineSuite([
}

var request = new Request({
url : 'https://foo.com/1',
url : 'https://test.invalid/1',
requestFunction : requestFunction
});

Expand Down Expand Up @@ -806,7 +810,7 @@ defineSuite([
}

var request = new Request({
url : 'https://foo.com/1',
url : 'https://test.invalid/1',
requestFunction : requestFunction
});

Expand Down Expand Up @@ -839,7 +843,7 @@ defineSuite([
}

var requestToCancel = new Request({
url : 'https://foo.com/1',
url : 'https://test.invalid/1',
requestFunction : requestCancelFunction
});

Expand All @@ -854,4 +858,29 @@ defineSuite([
cancelDeferred.resolve();
removeListenerCallback();
});

it('RequestScheduler.requestsByServer allows for custom maximum requests', function() {
var promise;

RequestScheduler.requestsByServer['test.invalid:80'] = 23;

for (var i = 0; i < 23; i++) {
promise = RequestScheduler.request(new Request({
url: 'http://test.invalid/1',
throttle: true,
throttleByServer: true,
requestFunction: function() { return when.defer(); }
}));
RequestScheduler.update();
expect(promise).toBeDefined();
}

promise = RequestScheduler.request(new Request({
url: 'http://test.invalid/1',
throttle: true,
throttleByServer: true,
requestFunction: function() { return when.defer(); }
}));
expect(promise).toBeUndefined();
});
});