@@ -95,8 +95,6 @@ const block_count = Math.ceil(file_size / block_size);
95
95
const file_size_aligned = block_count * block_size ;
96
96
const nb_native = argv . mode === 'nsfs' && require ( '../util/nb_native' ) ;
97
97
const is_master = cluster . isPrimary ;
98
- const start_time = Date . now ( ) ;
99
- const end_time = start_time + ( argv . time * 1000 ) ;
100
98
101
99
const speedometer = new Speedometer ( {
102
100
name : 'FS Speed' ,
@@ -157,6 +155,8 @@ async function io_worker(worker_id, io_worker_id) {
157
155
) ;
158
156
await fs . promises . mkdir ( dir , { recursive : true } ) ;
159
157
158
+ const start_time = Date . now ( ) ;
159
+ const end_time = start_time + ( argv . time * 1000 ) ;
160
160
for ( ; ; ) {
161
161
const file_start_time = Date . now ( ) ;
162
162
if ( file_start_time >= end_time ) break ;
@@ -169,26 +169,29 @@ async function io_worker(worker_id, io_worker_id) {
169
169
}
170
170
try {
171
171
if ( argv . mode === 'nsfs' ) {
172
- await work_with_nsfs ( file_path ) ;
172
+ await work_with_nsfs ( file_path , end_time ) ;
173
173
} else if ( argv . mode === 'nodejs' ) {
174
- await work_with_nodejs ( file_path ) ;
174
+ await work_with_nodejs ( file_path , end_time ) ;
175
175
} else if ( argv . mode === 'dd' ) {
176
- await work_with_dd ( file_path ) ;
176
+ await work_with_dd ( file_path , end_time ) ;
177
177
}
178
178
const took_ms = Date . now ( ) - file_start_time ;
179
179
speedometer . update ( 0 , took_ms ) ;
180
180
} 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
+ }
184
187
} else {
185
188
throw err ;
186
189
}
187
190
}
188
191
}
189
192
}
190
193
191
- async function work_with_dd ( file_path ) {
194
+ async function work_with_dd ( file_path , end_time ) {
192
195
const cmd = argv . read ?
193
196
`dd if=${ file_path } of=/dev/null bs=${ block_size } count=${ block_count } ` :
194
197
`dd if=${ argv . device } of=${ file_path } bs=${ block_size } count=${ block_count } ` ;
@@ -198,7 +201,7 @@ async function work_with_dd(file_path) {
198
201
speedometer . update ( file_size_aligned ) ;
199
202
}
200
203
201
- async function work_with_nsfs ( file_path ) {
204
+ async function work_with_nsfs ( file_path , end_time ) {
202
205
const rand_stream = new RandStream ( file_size_aligned , {
203
206
highWaterMark : 2 * block_size ,
204
207
generator : argv . read ? 'noinit' : argv . generator ,
@@ -232,7 +235,7 @@ async function work_with_nsfs(file_path) {
232
235
await file . close ( fs_context ) ;
233
236
}
234
237
235
- async function work_with_nodejs ( file_path ) {
238
+ async function work_with_nodejs ( file_path , end_time ) {
236
239
const rand_stream = new RandStream ( file_size_aligned , {
237
240
highWaterMark : 2 * block_size ,
238
241
generator : argv . read ? 'noinit' : argv . generator ,
0 commit comments