Skip to content

Commit 377789e

Browse files
author
Brian Chen
authored
fix: set default max ratelimiter throughput to 10k and update docs (#1439)
1 parent d4665f0 commit 377789e

5 files changed

Lines changed: 30 additions & 20 deletions

File tree

handwritten/firestore/dev/src/bulk-writer.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,26 @@ const MAX_BATCH_SIZE = 20;
5353
* The starting maximum number of operations per second as allowed by the
5454
* 500/50/5 rule.
5555
*
56-
* https://cloud.google.com/datastore/docs/best-practices#ramping_up_traffic.
56+
* https://firebase.google.com/docs/firestore/best-practices#ramping_up_traffic.
5757
*/
58-
export const DEFAULT_STARTING_MAXIMUM_OPS_PER_SECOND = 500;
58+
export const DEFAULT_INITIAL_OPS_PER_SECOND_LIMIT = 500;
5959

6060
/*!
61-
* The rate by which to increase the capacity as specified by the 500/50/5 rule.
61+
* The maximum number of operations per second as allowed by the 500/50/5 rule.
62+
* By default the rate limiter will not exceed this value.
6263
*
63-
* https://cloud.google.com/datastore/docs/best-practices#ramping_up_traffic.
64+
* https://firebase.google.com/docs/firestore/best-practices#ramping_up_traffic.
65+
*/
66+
export const DEFAULT_MAXIMUM_OPS_PER_SECOND_LIMIT = 10000;
67+
68+
/*!
69+
* The rate by which to increase the capacity as specified by the 500/50/5 rule.
6470
*/
6571
const RATE_LIMITER_MULTIPLIER = 1.5;
6672

6773
/*!
6874
* How often the operations per second capacity should increase in milliseconds
6975
* as specified by the 500/50/5 rule.
70-
*
71-
* https://cloud.google.com/datastore/docs/best-practices#ramping_up_traffic.
7276
*/
7377
const RATE_LIMITER_MULTIPLIER_MILLIS = 5 * 60 * 1000;
7478

@@ -336,8 +340,8 @@ export class BulkWriter {
336340
Number.POSITIVE_INFINITY
337341
);
338342
} else {
339-
let startingRate = DEFAULT_STARTING_MAXIMUM_OPS_PER_SECOND;
340-
let maxRate = Number.POSITIVE_INFINITY;
343+
let startingRate = DEFAULT_INITIAL_OPS_PER_SECOND_LIMIT;
344+
let maxRate = DEFAULT_MAXIMUM_OPS_PER_SECOND_LIMIT;
341345

342346
if (typeof options?.throttling !== 'boolean') {
343347
if (options?.throttling?.maxOpsPerSecond !== undefined) {

handwritten/firestore/dev/src/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -728,12 +728,13 @@ export class Firestore implements firestore.Firestore {
728728
* multiple writes in parallel. Gradually ramps up writes as specified
729729
* by the 500/50/5 rule.
730730
*
731-
* @see [500/50/5 Documentation]{@link https://cloud.google.com/datastore/docs/best-practices#ramping_up_traffic}
731+
* If you pass [BulkWriterOptions]{@link BulkWriterOptions}, you can
732+
* configure the throttling rates for the created BulkWriter.
732733
*
733-
* @param {object=} options BulkWriter options.
734-
* @param {boolean=} options.disableThrottling Whether to disable throttling
735-
* as specified by the 500/50/5 rule.
736-
* @returns {WriteBatch} A BulkWriter that operates on this Firestore
734+
* @see [500/50/5 Documentation]{@link https://firebase.google.com/docs/firestore/best-practices#ramping_up_traffic}
735+
*
736+
* @param {BulkWriterOptions=} options BulkWriter options.
737+
* @returns {BulkWriter} A BulkWriter that operates on this Firestore
737738
* client.
738739
*
739740
* @example

handwritten/firestore/dev/src/rate-limiter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {logger} from './logger';
2626
*
2727
* RateLimiter can also implement a gradually increasing rate limit. This is
2828
* used to enforce the 500/50/5 rule
29-
* (https://cloud.google.com/datastore/docs/best-practices#ramping_up_traffic).
29+
* (https://firebase.google.com/docs/firestore/best-practices#ramping_up_traffic).
3030
*
3131
* @private
3232
*/

handwritten/firestore/dev/test/bulk-writer.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ import {
2929
import {setTimeoutHandler} from '../src/backoff';
3030
import {
3131
BulkWriterError,
32-
DEFAULT_STARTING_MAXIMUM_OPS_PER_SECOND,
32+
DEFAULT_INITIAL_OPS_PER_SECOND_LIMIT,
33+
DEFAULT_MAXIMUM_OPS_PER_SECOND_LIMIT,
3334
} from '../src/bulk-writer';
3435
import {
3536
ApiOverride,
@@ -253,7 +254,7 @@ describe('BulkWriter', () => {
253254
});
254255
expect(bulkWriter._rateLimiter.availableTokens).to.equal(100);
255256
expect(bulkWriter._rateLimiter.maximumCapacity).to.equal(
256-
Number.POSITIVE_INFINITY
257+
DEFAULT_MAXIMUM_OPS_PER_SECOND_LIMIT
257258
);
258259

259260
bulkWriter = firestore.bulkWriter({
@@ -264,18 +265,18 @@ describe('BulkWriter', () => {
264265

265266
bulkWriter = firestore.bulkWriter();
266267
expect(bulkWriter._rateLimiter.availableTokens).to.equal(
267-
DEFAULT_STARTING_MAXIMUM_OPS_PER_SECOND
268+
DEFAULT_INITIAL_OPS_PER_SECOND_LIMIT
268269
);
269270
expect(bulkWriter._rateLimiter.maximumCapacity).to.equal(
270-
Number.POSITIVE_INFINITY
271+
DEFAULT_MAXIMUM_OPS_PER_SECOND_LIMIT
271272
);
272273

273274
bulkWriter = firestore.bulkWriter({throttling: true});
274275
expect(bulkWriter._rateLimiter.availableTokens).to.equal(
275-
DEFAULT_STARTING_MAXIMUM_OPS_PER_SECOND
276+
DEFAULT_INITIAL_OPS_PER_SECOND_LIMIT
276277
);
277278
expect(bulkWriter._rateLimiter.maximumCapacity).to.equal(
278-
Number.POSITIVE_INFINITY
279+
DEFAULT_MAXIMUM_OPS_PER_SECOND_LIMIT
279280
);
280281

281282
bulkWriter = firestore.bulkWriter({throttling: false});

handwritten/firestore/types/firestore.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ declare namespace FirebaseFirestore {
290290
* multiple writes in parallel. Gradually ramps up writes as specified
291291
* by the 500/50/5 rule.
292292
*
293+
* @see https://firebase.google.com/docs/firestore/best-practices#ramping_up_traffic
294+
*
293295
* @param options An options object used to configure the throttling
294296
* behavior for the underlying BulkWriter.
295297
*/
@@ -682,6 +684,8 @@ declare namespace FirebaseFirestore {
682684
* the defaults by setting it to `false` to disable throttling, or by
683685
* setting the config values to enable throttling with the provided values.
684686
*
687+
* @see https://firebase.google.com/docs/firestore/best-practices#ramping_up_traffic
688+
*
685689
* @param initialOpsPerSecond The initial maximum number of operations per
686690
* second allowed by the throttler. If this field is not set, the default
687691
* is 500 operations per second.

0 commit comments

Comments
 (0)