Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 98ba417

Browse files
committed
perf: expose importer concurrency controls when adding files
Adds two new arguments to the cli & http interface: `--file-import-concurrency` and `--block-write-concurrency` See ipfs-inactive/js-ipfs-unixfs-importer#41 for futher discussion.
1 parent f98023b commit 98ba417

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
"ipfs-repo": "^0.29.0",
108108
"ipfs-unixfs": "~0.1.16",
109109
"ipfs-unixfs-exporter": "^0.38.0",
110-
"ipfs-unixfs-importer": "^0.40.0",
110+
"ipfs-unixfs-importer": "ipfs/js-ipfs-unixfs-importer#concurrent-file-import",
111111
"ipfs-utils": "~0.4.0",
112112
"ipld": "~0.25.0",
113113
"ipld-bitcoin": "~0.3.0",

src/cli/commands/add.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,20 @@ module.exports = {
4949
default: false,
5050
describe: 'Only chunk and hash, do not write'
5151
},
52+
'block-write-concurrency': {
53+
type: 'integer',
54+
default: 10,
55+
describe: 'After a file has been chunked, this controls how many chunks to hash and add to the block store concurrently'
56+
},
5257
chunker: {
5358
default: 'size-262144',
5459
describe: 'Chunking algorithm to use, formatted like [size-{size}, rabin, rabin-{avg}, rabin-{min}-{avg}-{max}]'
5560
},
61+
'file-import-concurrency': {
62+
type: 'integer',
63+
default: 50,
64+
describe: 'How many files to import at once'
65+
},
5666
'enable-sharding-experiment': {
5767
type: 'boolean',
5868
default: false
@@ -124,7 +134,10 @@ module.exports = {
124134
wrapWithDirectory: argv.wrapWithDirectory,
125135
pin: argv.pin,
126136
chunker: argv.chunker,
127-
preload: argv.preload
137+
preload: argv.preload,
138+
nonatomic: argv.nonatomic,
139+
fileImportConcurrency: argv.fileImportConcurrency,
140+
blockWriteConcurrency: argv.blockWriteConcurrency
128141
}
129142

130143
if (options.enableShardingExperiment && argv.isDaemonOn()) {

src/core/components/files-regular/add-async-iterator.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ module.exports = function (self) {
2222
: Infinity
2323
}, options, {
2424
strategy: 'balanced',
25-
chunker: chunkerOptions.chunker,
26-
chunkerOptions: chunkerOptions.chunkerOptions
25+
...chunkerOptions
2726
})
2827

2928
// CID v0 is for multihashes encoded with sha2-256

src/core/components/files-regular/utils.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,12 @@ const parseChunkerString = (chunker) => {
4545
}
4646
return {
4747
chunker: 'fixed',
48-
chunkerOptions: {
49-
maxChunkSize: size
50-
}
48+
maxChunkSize: size
5149
}
5250
} else if (chunker.startsWith('rabin')) {
5351
return {
5452
chunker: 'rabin',
55-
chunkerOptions: parseRabinString(chunker)
53+
...parseRabinString(chunker)
5654
}
5755
} else {
5856
throw new Error(`Unrecognized chunker option: ${chunker}`)

src/http/api/resources/files-regular.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ exports.add = {
159159
'only-hash': Joi.boolean(),
160160
pin: Joi.boolean().default(true),
161161
'wrap-with-directory': Joi.boolean(),
162+
'file-import-concurrency': Joi.number().integer().min(0).default(50),
163+
'block-write-concurrency': Joi.number().integer().min(0).default(10),
162164
chunker: Joi.string(),
163165
trickle: Joi.boolean(),
164166
preload: Joi.boolean().default(true)
@@ -218,7 +220,9 @@ exports.add = {
218220
pin: request.query.pin,
219221
chunker: request.query.chunker,
220222
trickle: request.query.trickle,
221-
preload: request.query.preload
223+
preload: request.query.preload,
224+
fileImportConcurrency: request.query.fileImportConcurrency,
225+
blockWriteConcurrency: request.query.blockWriteConcurrency
222226
})
223227
},
224228
async function (source) {

0 commit comments

Comments
 (0)