Skip to content

Commit ac805a6

Browse files
committed
tools and improves
Signed-off-by: Guy Margalit <[email protected]>
1 parent b7686cc commit ac805a6

14 files changed

+229
-166
lines changed

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ module.exports = {
138138
'one-var': ['error', 'never'],
139139

140140
'@stylistic/js/space-before-function-paren': ['error', {
141-
'anonymous': 'never',
141+
'anonymous': 'ignore',
142142
'named': 'never',
143143
'asyncArrow': 'always'
144144
}],

config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,7 @@ function _get_data_from_file(file_name) {
11731173
try {
11741174
data = fs.readFileSync(file_name).toString();
11751175
} catch (e) {
1176-
console.warn(`Error accrued while getting the data from ${file_name}: ${e}`);
1176+
// console.log(`Error accrued while getting the data from ${file_name}: ${e}`);
11771177
return;
11781178
}
11791179
return data;
@@ -1189,7 +1189,7 @@ function _get_config_root() {
11891189
const data = _get_data_from_file(redirect_path);
11901190
config_root = data.toString().trim();
11911191
} catch (err) {
1192-
console.warn('config.get_config_root - could not find custom config_root, will use the default config_root ', config_root);
1192+
// console.log('config.get_config_root - could not find custom config_root, will use the default config_root ', config_root);
11931193
}
11941194
return config_root;
11951195
}
@@ -1244,7 +1244,7 @@ function load_nsfs_nc_config() {
12441244
try {
12451245
if (!config.NSFS_NC_CONF_DIR) {
12461246
config.NSFS_NC_CONF_DIR = _get_config_root();
1247-
console.warn('load_nsfs_nc_config.setting config.NSFS_NC_CONF_DIR', config.NSFS_NC_CONF_DIR);
1247+
// console.warn('load_nsfs_nc_config.setting config.NSFS_NC_CONF_DIR', config.NSFS_NC_CONF_DIR);
12481248
}
12491249
const config_path = path.join(config.NSFS_NC_CONF_DIR, 'config.json');
12501250
const config_data = require(config_path);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"scripts": {
1717
"install": "echo install hook override to avoid npm default hook calling node-gyp",
1818
"build": "npm run build:native",
19-
"build:native": "node-gyp configure && node-gyp build",
19+
"build:native": "node-gyp configure build",
2020
"rebuild": "npm run clean:install && npm run clean:build && npm install && npm run build",
2121
"pkg": "pkg . --public --options unhandled-rejections=warn --compress Brotli",
2222
"---": "------------------------------------------------------------------",

src/agent/block_store_speed.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
// const _ = require('lodash');
55
const argv = require('minimist')(process.argv);
6-
const cluster = require('cluster');
76
const mongodb = require('mongodb');
87

98
const api = require('../api');
@@ -26,17 +25,10 @@ argv.timeout = argv.timeout || 60000;
2625

2726
let block_index = 0;
2827

29-
const master_speedometer = new Speedometer('Total Speed');
3028
const speedometer = new Speedometer('Block Store Speed');
31-
32-
if (argv.forks > 1 && cluster.isMaster) {
33-
master_speedometer.fork(argv.forks);
34-
} else {
35-
main();
36-
}
29+
speedometer.run_workers(argv.forks, main, argv);
3730

3831
async function main() {
39-
console.log('ARGS', argv);
4032
const rpc = api.new_rpc();
4133
const client = rpc.new_client();
4234
const signal_client = rpc.new_client();

src/sdk/object_sdk.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -142,25 +142,25 @@ class ObjectSDK {
142142
this.abort_controller.abort(err);
143143
});
144144

145-
// TODO: aborted event is being deprecated since nodejs 16
146-
// https://nodejs.org/dist/latest-v16.x/docs/api/http.html#event-aborted recommends on listening to close event
147-
// req.once('close', () => {
148-
// dbg.log0('request aborted1', req.url);
149-
150-
// if (req.destroyed) {
151-
// dbg.log0('request aborted', req.url);
152-
// this.abort_controller.abort(new Error('request aborted ' + req.url));
153-
// }
145+
// Note: aborted event is deprecated in favor of the close event
146+
// https://nodejs.org/dist/latest-v16.x/docs/api/http.html#event-aborted
147+
// req.once('aborted', () => {
148+
// dbg.log0('request aborted', req.url);
149+
// this.abort_controller.abort(new Error('request aborted ' + req.url));
154150
// });
155-
156-
req.once('aborted', () => {
157-
dbg.log0('request aborted', req.url);
158-
this.abort_controller.abort(new Error('request aborted ' + req.url));
151+
req.once('close', () => {
152+
// dbg.log1('request closed', req.url);
153+
if (req.errored) {
154+
dbg.log0('request aborted', req.url);
155+
this.abort_controller.abort(new Error('request aborted ' + req.url));
156+
}
159157
});
158+
160159
}
161160

162161
throw_if_aborted() {
163-
if (this.abort_controller.signal.aborted) throw new Error('request aborted signal');
162+
this.abort_controller.signal.throwIfAborted();
163+
// if (this.abort_controller.signal.aborted) throw new Error('request aborted signal');
164164
}
165165

166166
add_abort_handler(handler) {

src/tools/coding_speed.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@ const _ = require('lodash');
77
const argv = require('minimist')(process.argv);
88
const stream = require('stream');
99
const assert = require('assert');
10-
const cluster = require('cluster');
1110
const crypto = require('crypto');
1211

1312
const config = require('../../config');
1413
const ChunkCoder = require('../util/chunk_coder');
1514
const RandStream = require('../util/rand_stream');
1615
const Speedometer = require('../util/speedometer');
1716
const ChunkEraser = require('../util/chunk_eraser');
18-
const stream_utils = require('../util/stream_utils');
1917
const ChunkSplitter = require('../util/chunk_splitter');
2018
const FlattenStream = require('../util/flatten_stream');
2119
// const CoalesceStream = require('../util/coalesce_stream');
@@ -35,17 +33,10 @@ argv.verbose = Boolean(argv.verbose); // default is false
3533
argv.sse_c = Boolean(argv.sse_c); // default is false
3634
delete argv._;
3735

38-
const master_speedometer = new Speedometer('Total Speed');
3936
const speedometer = new Speedometer('Chunk Coder Speed');
40-
41-
if (argv.forks > 1 && cluster.isMaster) {
42-
master_speedometer.fork(argv.forks);
43-
} else {
44-
main();
45-
}
37+
speedometer.run_workers(argv.forks, main, argv);
4638

4739
function main() {
48-
console.log('Arguments:', JSON.stringify(argv, null, 2));
4940

5041
const chunk_split_config = {
5142
avg_chunk: config.CHUNK_SPLIT_AVG_CHUNK,
@@ -106,11 +97,10 @@ function main() {
10697

10798
let total_size = 0;
10899
let num_parts = 0;
109-
const reporter = new stream.Transform({
100+
const reporter = new stream.Writable({
110101
objectMode: true,
111-
allowHalfOpen: false,
112102
highWaterMark: 50,
113-
transform(chunk, encoding, callback) {
103+
write(chunk, encoding, callback) {
114104
if (argv.verbose) console.log({ ...chunk, data: 'ommitted' });
115105
if (argv.compare && chunk.original_data) {
116106
assert(Buffer.concat(chunk.original_data).equals(chunk.data));
@@ -122,7 +112,7 @@ function main() {
122112
}
123113
});
124114

125-
/** @type {stream.Stream[]} */
115+
/** @type {(stream.Readable | stream.Transform | stream.Writable)[]} */
126116
const transforms = [
127117
input,
128118
splitter,
@@ -137,7 +127,7 @@ function main() {
137127
transforms.push(new FlattenStream());
138128
}
139129
transforms.push(reporter);
140-
return stream_utils.pipeline(transforms)
130+
return stream.promises.pipeline(transforms)
141131
.then(() => {
142132
console.log('AVERAGE CHUNK SIZE', (total_size / num_parts).toFixed(0));
143133
if (splitter.md5) {

src/tools/cpu_speed.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
require('../util/fips');
55
const crypto = require('crypto');
6-
const cluster = require('cluster');
76
const argv = require('minimist')(process.argv);
87
const Speedometer = require('../util/speedometer');
98

@@ -13,17 +12,12 @@ argv.forks = argv.forks || 1;
1312
argv.size = argv.size || (10 * 1024);
1413
argv.hash = argv.hash || 'sha256';
1514

16-
if (argv.forks > 1 && cluster.isMaster) {
17-
const master_speedometer = new Speedometer('Total Speed');
18-
master_speedometer.fork(argv.forks);
19-
} else {
20-
main();
21-
}
15+
const speedometer = new Speedometer(`CPU(${argv.hash})`);
16+
speedometer.run_workers(argv.forks, main, argv);
2217

2318
function main() {
2419
const hasher = crypto.createHash(argv.hash);
2520
const buf = crypto.randomBytes(1024 * 1024);
26-
const speedometer = new Speedometer('CPU Speed');
2721
let size = argv.size * 1024 * 1024;
2822
console.log(`Crunching ${argv.size} MB with ${argv.hash}...`);
2923
run();

src/tools/fs_speed.js

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
/* Copyright (C) 2016 NooBaa */
22
'use strict';
33

4+
require('../util/panic');
5+
46
const fs = require('fs');
57
const util = require('util');
68
const path = require('path');
79
const argv = require('minimist')(process.argv);
8-
const cluster = require('cluster');
10+
const { cluster } = require('../util/fork_utils');
911
const execAsync = util.promisify(require('child_process').exec);
1012
const Speedometer = require('../util/speedometer');
1113
const RandStream = require('../util/rand_stream');
@@ -55,6 +57,7 @@ argv.file_size_units = argv.file_size_units || 'MB';
5557
argv.block_size_units = argv.block_size_units || 'MB';
5658
argv.fsync = Boolean(argv.fsync);
5759
argv.mode = argv.mode || 'nsfs';
60+
argv.backend = argv.backend || 'GPFS';
5861
if (argv.mode === 'dd') {
5962
argv.device = argv.device || '/dev/zero';
6063
} else {
@@ -89,18 +92,15 @@ const file_size = argv.file_size * size_units_table[argv.file_size_units];
8992
const block_count = Math.ceil(file_size / block_size);
9093
const file_size_aligned = block_count * block_size;
9194
const nb_native = argv.mode === 'nsfs' && require('../util/nb_native');
92-
const is_master = cluster.isMaster;
93-
const speedometer = new Speedometer(is_master ? 'Total Speed' : 'FS Speed');
95+
const is_master = cluster.isPrimary;
9496
const start_time = Date.now();
9597
const end_time = start_time + (argv.time * 1000);
9698

97-
if (argv.forks > 1 && is_master) {
98-
speedometer.fork(argv.forks);
99-
} else {
100-
main();
101-
}
99+
const speedometer = new Speedometer('FS Speed');
100+
speedometer.run_workers(argv.forks, main, argv);
102101

103102
async function main() {
103+
// nb_native().fs.set_debug_level(5);
104104
const promises = [];
105105
fs.mkdirSync(argv.dir, { recursive: true });
106106
for (let i = 0; i < argv.concur; ++i) promises.push(worker(i));
@@ -127,15 +127,23 @@ async function worker(id) {
127127
if (file_start_time >= end_time) break;
128128
const file_path = path.join(dir, `file-${file_id}`);
129129
file_id += 1;
130-
if (argv.mode === 'nsfs') {
131-
await work_with_nsfs(file_path);
132-
} else if (argv.mode === 'nodejs') {
133-
await work_with_nodejs(file_path);
134-
} else if (argv.mode === 'dd') {
135-
await work_with_dd(file_path);
130+
try {
131+
if (argv.mode === 'nsfs') {
132+
await work_with_nsfs(file_path);
133+
} else if (argv.mode === 'nodejs') {
134+
await work_with_nodejs(file_path);
135+
} else if (argv.mode === 'dd') {
136+
await work_with_dd(file_path);
137+
}
138+
const took_ms = Date.now() - file_start_time;
139+
speedometer.add_op(took_ms);
140+
} catch (err) {
141+
if (argv.read && err.code === 'ENOENT') {
142+
file_id = 0;
143+
} else {
144+
throw err;
145+
}
136146
}
137-
const took_ms = Date.now() - file_start_time;
138-
speedometer.add_op(took_ms);
139147
}
140148
}
141149

@@ -157,24 +165,25 @@ async function work_with_nsfs(file_path) {
157165
const fs_context = {
158166
// uid: 666,
159167
// gid: 666,
160-
backend: 'GPFS',
161-
warn_threshold_ms: 1000,
168+
backend: argv.backend,
169+
warn_threshold_ms: 10000,
162170
};
163-
const file = await nb_native().fs.open(fs_context, file_path, argv.read ? 'r' : 'w', 0x660);
171+
const file = await nb_native().fs.open(fs_context, file_path, argv.read ? 'r' : 'w', 0o660);
164172
for (let pos = 0; pos < file_size_aligned; pos += block_size) {
165173
const buf_start_time = Date.now();
166174
if (buf_start_time >= end_time) break;
167175
const buf = rand_stream.generator(block_size);
168176
if (argv.nvec > 1) {
169177
if (argv.read) {
170-
await file.readv(fs_context, split_to_nvec(buf, argv.nvec));
178+
// await file.readv(fs_context, split_to_nvec(buf, argv.nvec));
179+
throw new Error('TODO: readv is not yet available in NativeFile');
171180
} else {
172181
await file.writev(fs_context, split_to_nvec(buf, argv.nvec));
173182
}
174183
} else if (argv.read) {
175184
await file.read(fs_context, buf, 0, buf.length, pos);
176185
} else {
177-
await file.write(fs_context, buf);
186+
await file.write(fs_context, buf, buf.length, pos);
178187
}
179188
speedometer.update(block_size);
180189
}
@@ -187,7 +196,7 @@ async function work_with_nodejs(file_path) {
187196
highWaterMark: 2 * block_size,
188197
generator: argv.read ? 'noinit' : argv.generator,
189198
});
190-
const file = await fs.promises.open(file_path, argv.read ? 'r' : 'w', 0x660);
199+
const file = await fs.promises.open(file_path, argv.read ? 'r' : 'w', 0o660);
191200
for (let pos = 0; pos < file_size_aligned; pos += block_size) {
192201
const buf_start_time = Date.now();
193202
if (buf_start_time >= end_time) break;

src/tools/rand_speed.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,21 @@
22
'use strict';
33

44
const zlib = require('zlib');
5-
const cluster = require('cluster');
65
const RandStream = require('../util/rand_stream');
76
const Speedometer = require('../util/speedometer');
87
const argv = require('minimist')(process.argv);
98

10-
argv.forks = argv.forks || 1;
9+
argv.forks ||= 1;
10+
argv.buf ||= 1024 * 1024;
11+
argv.generator ||= 'crypto'; // see RandStream for options
1112

12-
if (argv.forks > 1 && cluster.isMaster) {
13-
const master_speedometer = new Speedometer('Total Speed');
14-
master_speedometer.fork(argv.forks);
15-
} else {
16-
main();
17-
}
13+
const speedometer = new Speedometer('RandStream');
14+
speedometer.run_workers(argv.forks, main, argv);
1815

1916
function main() {
20-
const speedometer = new Speedometer('Rand Speed');
2117
const len = (argv.len * 1024 * 1024) || Infinity;
2218
const input = new RandStream(len, {
23-
highWaterMark: 1024 * 1024,
19+
highWaterMark: argv.buf,
2420
generator: argv.generator,
2521
});
2622
input.on('data', data => speedometer.update(data.length));

0 commit comments

Comments
 (0)