Skip to content

Commit 4bfbdcb

Browse files
committed
asd
1 parent 0e37de9 commit 4bfbdcb

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/tools/fs_speed.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ const block_count = Math.ceil(file_size / block_size);
9595
const file_size_aligned = block_count * block_size;
9696
const nb_native = argv.mode === 'nsfs' && require('../util/nb_native');
9797
const is_master = cluster.isPrimary;
98-
const start_time = Date.now();
99-
const end_time = start_time + (argv.time * 1000);
10098

10199
const speedometer = new Speedometer({
102100
name: 'FS Speed',
@@ -157,6 +155,8 @@ async function io_worker(worker_id, io_worker_id) {
157155
);
158156
await fs.promises.mkdir(dir, { recursive: true });
159157

158+
const start_time = Date.now();
159+
const end_time = start_time + (argv.time * 1000);
160160
for (; ;) {
161161
const file_start_time = Date.now();
162162
if (file_start_time >= end_time) break;
@@ -169,26 +169,29 @@ async function io_worker(worker_id, io_worker_id) {
169169
}
170170
try {
171171
if (argv.mode === 'nsfs') {
172-
await work_with_nsfs(file_path);
172+
await work_with_nsfs(file_path, end_time);
173173
} else if (argv.mode === 'nodejs') {
174-
await work_with_nodejs(file_path);
174+
await work_with_nodejs(file_path, end_time);
175175
} else if (argv.mode === 'dd') {
176-
await work_with_dd(file_path);
176+
await work_with_dd(file_path, end_time);
177177
}
178178
const took_ms = Date.now() - file_start_time;
179179
speedometer.update(0, took_ms);
180180
} catch (err) {
181-
if (argv.read && err.code === 'ENOENT') {
182-
// console.warn('file not found', file_path);
183-
await fs.promises.mkdir(hash_dir, { recursive: true });
181+
if (err.code === 'ENOENT') {
182+
if (argv.read) {
183+
console.warn('file not found', file_path);
184+
} else {
185+
await fs.promises.mkdir(hash_dir, { recursive: true });
186+
}
184187
} else {
185188
throw err;
186189
}
187190
}
188191
}
189192
}
190193

191-
async function work_with_dd(file_path) {
194+
async function work_with_dd(file_path, end_time) {
192195
const cmd = argv.read ?
193196
`dd if=${file_path} of=/dev/null bs=${block_size} count=${block_count}` :
194197
`dd if=${argv.device} of=${file_path} bs=${block_size} count=${block_count}`;
@@ -198,7 +201,7 @@ async function work_with_dd(file_path) {
198201
speedometer.update(file_size_aligned);
199202
}
200203

201-
async function work_with_nsfs(file_path) {
204+
async function work_with_nsfs(file_path, end_time) {
202205
const rand_stream = new RandStream(file_size_aligned, {
203206
highWaterMark: 2 * block_size,
204207
generator: argv.read ? 'noinit' : argv.generator,
@@ -232,7 +235,7 @@ async function work_with_nsfs(file_path) {
232235
await file.close(fs_context);
233236
}
234237

235-
async function work_with_nodejs(file_path) {
238+
async function work_with_nodejs(file_path, end_time) {
236239
const rand_stream = new RandStream(file_size_aligned, {
237240
highWaterMark: 2 * block_size,
238241
generator: argv.read ? 'noinit' : argv.generator,

0 commit comments

Comments
 (0)