-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
12 changed files
with
258 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
63 changes: 63 additions & 0 deletions
63
test/benchmarks/driver_bench/src/suites/parallel_bench/gridfs_multi_file_download.mts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { createReadStream, createWriteStream, promises as fs } from 'node:fs'; | ||
import path from 'node:path'; | ||
import { pipeline } from 'node:stream/promises'; | ||
|
||
import { driver, type mongodb, PARALLEL_DIRECTORY, TEMP_DIRECTORY } from '../../driver.mjs'; | ||
|
||
export const taskSize = 262.144; | ||
|
||
let bucket: mongodb.GridFSBucket; | ||
|
||
export async function before() { | ||
await driver.drop(); | ||
await driver.create(); | ||
await driver.resetTmpDir(); | ||
|
||
bucket = driver.bucket(driver.client.db(driver.DB_NAME)); | ||
await bucket.drop().catch(() => null); | ||
|
||
const gridfs_multi = path.resolve(PARALLEL_DIRECTORY, 'gridfs_multi'); | ||
|
||
const files = (await fs.readdir(gridfs_multi)).map(filename => | ||
path.resolve(gridfs_multi, filename) | ||
); | ||
|
||
const uploadPromises = files.map(async filename => { | ||
const fileStream = createReadStream(filename); | ||
const uploadStream = bucket.openUploadStream(filename); | ||
return await pipeline(fileStream, uploadStream); | ||
}); | ||
|
||
await Promise.all(uploadPromises); | ||
} | ||
|
||
export async function beforeEach() { | ||
await driver.resetTmpDir(); | ||
} | ||
|
||
export async function run() { | ||
const files = await bucket | ||
.find() | ||
.map(({ _id }) => ({ | ||
path: path.resolve(TEMP_DIRECTORY, `${_id}.txt`), | ||
_id | ||
})) | ||
.toArray(); | ||
|
||
const downloads = files.map(async ({ _id, path }) => { | ||
const fileStream = createWriteStream(path); | ||
const downloadStream = bucket.openDownloadStream(_id); | ||
return await pipeline(downloadStream, fileStream); | ||
}); | ||
|
||
await Promise.all(downloads); | ||
} | ||
|
||
export async function afterEach() { | ||
await driver.resetTmpDir(); | ||
} | ||
|
||
export async function after() { | ||
await driver.drop(); | ||
await driver.close(); | ||
} |
46 changes: 46 additions & 0 deletions
46
test/benchmarks/driver_bench/src/suites/parallel_bench/gridfs_multi_file_upload.mts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { createReadStream, promises as fs } from 'node:fs'; | ||
import path from 'node:path'; | ||
import { Readable } from 'node:stream'; | ||
import { pipeline } from 'node:stream/promises'; | ||
|
||
import { driver, type mongodb, PARALLEL_DIRECTORY } from '../../driver.mjs'; | ||
|
||
export const taskSize = 262.144; | ||
|
||
let bucket: mongodb.GridFSBucket; | ||
|
||
const directory = path.resolve(PARALLEL_DIRECTORY, 'gridfs_multi'); | ||
|
||
export async function before() { | ||
await driver.drop(); | ||
await driver.create(); | ||
|
||
bucket = driver.bucket(driver.client.db(driver.DB_NAME)); | ||
|
||
await bucket.drop().catch(() => null); | ||
} | ||
|
||
export async function beforeEach() { | ||
// Create the bucket. | ||
const stream = bucket.openUploadStream('setup-file.txt'); | ||
const oneByteFile = Readable.from('a'); | ||
await pipeline(oneByteFile, stream); | ||
} | ||
|
||
export async function run() { | ||
const files = await fs.readdir(directory); | ||
|
||
const uploadPromises = files.map(async filename => { | ||
const file = path.resolve(directory, filename); | ||
const fileStream = createReadStream(file); | ||
const uploadStream = bucket.openUploadStream(file); | ||
return await pipeline(fileStream, uploadStream); | ||
}); | ||
|
||
await Promise.all(uploadPromises); | ||
} | ||
|
||
export async function after() { | ||
await driver.drop(); | ||
await driver.close(); | ||
} |
74 changes: 74 additions & 0 deletions
74
test/benchmarks/driver_bench/src/suites/parallel_bench/ldjson_multi_file_export.mts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { createReadStream, createWriteStream, promises as fs } from 'node:fs'; | ||
import path from 'node:path'; | ||
import readline from 'node:readline/promises'; | ||
import stream from 'node:stream/promises'; | ||
|
||
import { driver, EJSON, type mongodb, PARALLEL_DIRECTORY, TEMP_DIRECTORY } from '../../driver.mjs'; | ||
|
||
export const taskSize = 565; | ||
|
||
let collection: mongodb.Collection; | ||
|
||
export async function before() { | ||
await driver.drop(); | ||
await driver.create(); | ||
await driver.resetTmpDir(); | ||
|
||
collection = driver.client.db(driver.DB_NAME).collection(driver.COLLECTION_NAME); | ||
|
||
const ldjson_multi = path.resolve(PARALLEL_DIRECTORY, 'ldjson_multi'); | ||
|
||
const files = (await fs.readdir(ldjson_multi)).map(fileName => | ||
path.resolve(ldjson_multi, fileName) | ||
); | ||
|
||
const uploads = files.map(async fileName => { | ||
const fileStream = createReadStream(fileName); | ||
const lineReader = readline.createInterface({ | ||
input: fileStream | ||
}); | ||
|
||
const operations = []; | ||
|
||
for await (const line of lineReader) { | ||
operations.push({ | ||
insertOne: { | ||
document: JSON.parse(line) | ||
} | ||
}); | ||
} | ||
|
||
fileStream.close(); | ||
lineReader.close(); | ||
|
||
return await collection.bulkWrite(operations); | ||
}); | ||
|
||
await Promise.all(uploads); | ||
} | ||
|
||
export async function beforeEach() { | ||
await driver.resetTmpDir(); | ||
} | ||
|
||
export async function run() { | ||
const skips = Array.from({ length: 100 }, (_, index) => index * 5000); | ||
|
||
const promises = skips.map(async skip => { | ||
const documentCursor = collection.find({}, { skip, limit: 5000 }); | ||
documentCursor.map(doc => EJSON.stringify(doc)); | ||
const outputStream = createWriteStream(path.resolve(TEMP_DIRECTORY, `tmp-${skip}.txt`)); | ||
return await stream.pipeline(documentCursor.stream(), outputStream); | ||
}); | ||
|
||
await Promise.all(promises); | ||
} | ||
|
||
export async function afterEach() { | ||
await driver.resetTmpDir(); | ||
} | ||
|
||
export async function after() { | ||
await driver.drop(); | ||
await driver.close(); | ||
} |
49 changes: 49 additions & 0 deletions
49
test/benchmarks/driver_bench/src/suites/parallel_bench/ldjson_multi_file_upload.mts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { createReadStream, promises as fs } from 'node:fs'; | ||
import path from 'node:path'; | ||
import readline from 'node:readline/promises'; | ||
|
||
import { driver, type mongodb, PARALLEL_DIRECTORY } from '../../driver.mjs'; | ||
|
||
export const taskSize = 565; | ||
|
||
const directory = path.resolve(PARALLEL_DIRECTORY, 'ldjson_multi'); | ||
let collection: mongodb.Collection; | ||
|
||
export async function beforeEach() { | ||
await driver.drop(); | ||
await driver.create(); | ||
|
||
collection = driver.client.db(driver.DB_NAME).collection(driver.COLLECTION_NAME); | ||
} | ||
|
||
export async function run() { | ||
const files = await fs.readdir(directory); | ||
const uploads = files.map(async file => { | ||
const fileStream = createReadStream(path.resolve(directory, file)); | ||
const lineReader = readline.createInterface({ | ||
input: fileStream | ||
}); | ||
|
||
const operations = []; | ||
|
||
for await (const line of lineReader) { | ||
operations.push({ | ||
insertOne: { | ||
document: JSON.parse(line) | ||
} | ||
}); | ||
} | ||
|
||
fileStream.close(); | ||
lineReader.close(); | ||
|
||
return await collection.bulkWrite(operations); | ||
}); | ||
|
||
await Promise.all(uploads); | ||
} | ||
|
||
export async function after() { | ||
await driver.drop(); | ||
await driver.close(); | ||
} |