-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathrocksMemoryConfig.test.js
More file actions
108 lines (91 loc) · 3.95 KB
/
Copy pathrocksMemoryConfig.test.js
File metadata and controls
108 lines (91 loc) · 3.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
'use strict';
const assert = require('node:assert/strict');
const { resolveRocksMemoryConfig } = require('#src/utility/rocksMemoryConfig');
const GB = 1024 * 1024 * 1024;
function resolve(overrides) {
return resolveRocksMemoryConfig({
configuredBlockCacheSize: undefined,
configuredWriteBufferManagerSize: undefined,
configuredCostToCache: undefined,
configuredAllowStall: undefined,
availableMemory: 8 * GB,
...overrides,
});
}
describe('resolveRocksMemoryConfig', function () {
describe('block cache', function () {
it('defaults to 25% of available memory when unset', function () {
assert.strictEqual(resolve({}).blockCacheSize, 2 * GB);
});
it('honors an explicit positive size', function () {
assert.strictEqual(resolve({ configuredBlockCacheSize: 512 * 1024 * 1024 }).blockCacheSize, 512 * 1024 * 1024);
});
it('falls back to the default for zero, negative, or non-number values', function () {
assert.strictEqual(resolve({ configuredBlockCacheSize: 0 }).blockCacheSize, 2 * GB);
assert.strictEqual(resolve({ configuredBlockCacheSize: -1 }).blockCacheSize, 2 * GB);
assert.strictEqual(resolve({ configuredBlockCacheSize: 'big' }).blockCacheSize, 2 * GB);
});
});
describe('WriteBufferManager size', function () {
it('defaults to 1/3 of the resolved block cache when unset', function () {
const config = resolve({});
assert.strictEqual(config.writeBufferManagerSize, Math.floor((2 * GB) / 3));
});
it('defaults relative to an explicit block cache size', function () {
const config = resolve({ configuredBlockCacheSize: 900 });
assert.strictEqual(config.writeBufferManagerSize, 300);
});
it('honors an explicit positive size', function () {
assert.strictEqual(
resolve({ configuredWriteBufferManagerSize: 256 * 1024 * 1024 }).writeBufferManagerSize,
256 * 1024 * 1024
);
});
it('disables the WBM entirely when explicitly set to 0', function () {
const config = resolve({ configuredWriteBufferManagerSize: 0 });
assert.ok(!('writeBufferManagerSize' in config));
assert.ok(!('writeBufferManagerCostToCache' in config));
assert.ok(!('writeBufferManagerAllowStall' in config));
});
it('falls back to the default for non-number values', function () {
assert.strictEqual(
resolve({ configuredWriteBufferManagerSize: 'lots' }).writeBufferManagerSize,
Math.floor((2 * GB) / 3)
);
});
});
describe('integer flooring', function () {
it('floors a fractional block cache default', function () {
// 10 * 0.25 = 2.5 -> 2
assert.strictEqual(resolve({ availableMemory: 10 }).blockCacheSize, 2);
});
it('floors a fractional WriteBufferManager default', function () {
// floor(10 / 3) = 3
const config = resolve({ configuredBlockCacheSize: 10 });
assert.strictEqual(config.writeBufferManagerSize, 3);
});
it('produces integer sizes for a realistic constrained memory limit', function () {
// 6 GB cgroup limit: block cache 1.5 GB, WBM 1.5 GB / 3
const config = resolve({ availableMemory: 6 * GB });
assert.ok(Number.isInteger(config.blockCacheSize));
assert.ok(Number.isInteger(config.writeBufferManagerSize));
});
});
describe('costToCache and allowStall', function () {
it('both default to true when the WBM is enabled', function () {
const config = resolve({});
assert.strictEqual(config.writeBufferManagerCostToCache, true);
assert.strictEqual(config.writeBufferManagerAllowStall, true);
});
it('honor explicit false values', function () {
const config = resolve({ configuredCostToCache: false, configuredAllowStall: false });
assert.strictEqual(config.writeBufferManagerCostToCache, false);
assert.strictEqual(config.writeBufferManagerAllowStall, false);
});
it('fall back to true for non-boolean values', function () {
const config = resolve({ configuredCostToCache: 'yes', configuredAllowStall: 1 });
assert.strictEqual(config.writeBufferManagerCostToCache, true);
assert.strictEqual(config.writeBufferManagerAllowStall, true);
});
});
});