Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add reservedMemory #1197

Merged
merged 4 commits into from
Mar 21, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 2 additions & 1 deletion core/api-server/config/main/config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const useSentinel = !!process.env.REDIS_SENTINEL_SERVICE_HOST;
config.defaultStorage = process.env.DEFAULT_STORAGE || 's3';
config.maxStorageFetchKeys = formatter.parseInt(process.env.MAX_STORAGE_FETCH_KEYS, 100);
config.storageResultsThreshold = process.env.STORAGE_RESULTS_THRESHOLD || '100Ki';
config.defaultAlgorithmReservedMemoryRatio = formatter.parseInt(process.env.DEFAULT_ALGORITHM_RESERVED_MEMORY_RATIO, 0.2);
const storageEncoding = process.env.STORAGE_ENCODING || 'bson';

config.version = packageJson.version;
Expand Down Expand Up @@ -53,7 +54,7 @@ config.swagger = {
protocol: secured ? 'https' : 'http',
host: process.env.BASE_URL_HOST || 'localhost',
port: process.env.BASE_URL_PORT || config.rest.port,
path: process.env.BASE_URL_PATH? path.join(config.ingressPrefix, process.env.BASE_URL_PATH): config.ingressPrefix
path: process.env.BASE_URL_PATH ? path.join(config.ingressPrefix, process.env.BASE_URL_PATH) : config.ingressPrefix
};

config.jobs = {
Expand Down
8 changes: 8 additions & 0 deletions core/api-server/lib/service/algorithms.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const merge = require('lodash.merge');
const isEqual = require('lodash.isequal');
const cloneDeep = require('lodash.clonedeep');
const format = require('string-template');
const unitsConverter = require('@hkube/units-converter');
const storageManager = require('@hkube/storage-manager');
const { buildTypes } = require('@hkube/consts');
const executionService = require('./execution');
Expand All @@ -15,6 +16,7 @@ const { MESSAGES } = require('../consts/builds');
class AlgorithmStore {
init(config) {
this._debugUrl = config.debugUrl.path;
this._defaultAlgorithmReservedMemoryRatio = config.defaultAlgorithmReservedMemoryRatio;

stateManager.onBuildComplete(async (build) => {
/**
Expand Down Expand Up @@ -179,6 +181,12 @@ class AlgorithmStore {
newAlgorithm.data = { ...newAlgorithm.data, path: `${this._debugUrl}/${newAlgorithm.name}` };
}

if (!newAlgorithm.reservedMemory) {
const memInMb = unitsConverter.getMemoryInMi(newAlgorithm.mem);
const reservedMemory = Math.ceil(memInMb * this._defaultAlgorithmReservedMemoryRatio);
newAlgorithm.reservedMemory = `${reservedMemory}Mi`;
}

const newVersion = await this._versioning(hasDiff, newAlgorithm, buildId);
if (newVersion) {
newAlgorithm.version = newVersion;
Expand Down
12 changes: 11 additions & 1 deletion core/api-server/tests/algorithms-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -1681,7 +1681,17 @@ describe('Store/Algorithms', () => {
const res = await request(req);
expect(res.body.algorithm.reservedMemory).to.eql(reservedMemory);
});
it('should succeed to add reservedMemory', async () => {
it('should succeed to calc reservedMemory', async () => {
const apply = {
name: `my-alg-${uuid()}`,
algorithmImage: 'test-algorithmImage',
mem: '1024Mi'
}
const req = { uri: applyPath, formData: { payload: JSON.stringify(apply) } };
const res = await request(req);
expect(res.body.algorithm.reservedMemory).to.eql('205Mi');
});
it('should succeed to add created and modified', async () => {
const apply = {
name: `my-alg-${uuid()}`,
algorithmImage: 'test-algorithmImage',
Expand Down