Skip to content

Commit

Permalink
limit concurrency (#404)
Browse files Browse the repository at this point in the history
  • Loading branch information
carrolp authored Apr 23, 2024
1 parent e84b538 commit 3a59b21
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/BaseDownloadController.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 IBM Corp. All Rights Reserved.
* Copyright 2019, 2024 IBM Corp. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,6 +21,13 @@ const hash = require('object-hash');
const clone = require('clone');
const pLimit = require('p-limit');

// Limit concurrent check and save of kube resources in `_saveChild()`.
// This limit will apply across separate BaseDownloadController instances,
// e.g. to prevent either large numbers of RemoteResources OR large
// numbers of kube resources in RemoteResources from flooding the
// Kubernetes API.
const globalLimit = pLimit(10);

const CompositeController = require('./CompositeController');

const FetchEnvs = require('./FetchEnvs');
Expand All @@ -29,11 +36,6 @@ module.exports = class BaseDownloadController extends CompositeController {
constructor(params) {
params.finalizerString = params.finalizerString || 'children.downloads.deploy.razee.io';
super(params);
this._limit = pLimit(5);
}

get limit() {
return this._limit;
}

async added() {
Expand Down Expand Up @@ -282,7 +284,8 @@ module.exports = class BaseDownloadController extends CompositeController {
}

async _saveChild(child) {
let res = await this.limit(async () => {
// Limit concurrency to prevent flooding the Kubernetes API
let res = await globalLimit(async () => {
return await this.applyChild(child);
});

Expand Down

0 comments on commit 3a59b21

Please sign in to comment.