Compare commits

...

2 Commits

Author SHA1 Message Date
Florent BEAUCHAMP
365e44fbb9 usb nbd for al exports 2023-07-27 08:37:13 +02:00
Florent BEAUCHAMP
b4f13838a6 wip 2023-07-26 17:10:21 +02:00
4 changed files with 47 additions and 8 deletions

View File

@@ -0,0 +1,32 @@
import NbdClient from "./index.mjs";
async function bench(){
const client = new NbdClient({
address:'172.16.210.14',
port: 8077,
exportname: 'bench_export'
})
await client.connect()
console.log('connected', client.exportSize)
for(let chunk_size=16*1024; chunk_size < 16*1024*1024; chunk_size *=2){
let i=0
const start = + new Date()
for await(const block of client.readBlocks(chunk_size) ){
i++
if((i*chunk_size) % (16*1024*1024) ===0){
process.stdout.write('.')
}
if(i*chunk_size > 1024*1024*1024) break
}
console.log(chunk_size,Math.round( (i*chunk_size/1024/1024*1000)/ (new Date() - start)))
}
}
bench()

View File

@@ -307,11 +307,11 @@ export default class NbdClient {
})
}
async *readBlocks(indexGenerator) {
async *readBlocks(indexGenerator = 2*1024*1024) {
// default : read all blocks
if (indexGenerator === undefined) {
if (typeof indexGenerator === 'number') {
const exportSize = this.#exportSize
const chunkSize = 2 * 1024 * 1024
const chunkSize = indexGenerator
indexGenerator = function* () {
const nbBlocks = Math.ceil(Number(exportSize / BigInt(chunkSize)))
for (let index = 0; BigInt(index) < nbBlocks; index++) {
@@ -319,6 +319,7 @@ export default class NbdClient {
}
}
}
const readAhead = []
const readAheadMaxLength = this.#readAhead
const makeReadBlockPromise = (index, size) => {

View File

@@ -64,8 +64,12 @@ class Vdi {
})
}
async _getNbdClient(ref) {
const nbdInfos = await this.call('VDI.get_nbd_info', ref)
async _getNbdClient(ref) {
const nbdInfos = [{
address:'172.16.210.14',
port: 8077,
exportname: 'bench_export'
}]//await this.call('VDI.get_nbd_info', ref)
if (nbdInfos.length > 0) {
// a little bit of randomization to spread the load
const nbdInfo = nbdInfos[Math.floor(Math.random() * nbdInfos.length)]
@@ -94,13 +98,15 @@ class Vdi {
query.base = baseRef
}
let nbdClient, stream
try {
if (this._preferNbd) {
if (this._preferNbd || true) {
nbdClient = await this._getNbdClient(ref)
}
// the raw nbd export does not need to peek ath the vhd source
if (nbdClient !== undefined && format === VDI_FORMAT_RAW) {
if (nbdClient !== undefined && format === VDI_FORMAT_RAW || true) {
stream = createNbdRawStream(nbdClient)
} else {
// raw export without nbd or vhd exports needs a resource stream

View File

@@ -15,7 +15,7 @@ const { fuHeader, checksumStruct } = require('./_structs')
const assert = require('node:assert')
exports.createNbdRawStream = async function createRawStream(nbdClient) {
const stream = Readable.from(nbdClient.readBlocks())
const stream = Readable.from(nbdClient.readBlocks(524288))
stream.on('error', () => nbdClient.disconnect())
stream.on('end', () => nbdClient.disconnect())