mirror of
https://github.com/vatesfr/xen-orchestra.git
synced 2026-11-09 17:06:13 -06:00
fix(xapi): implement Throttling on Xapi/Remote read
This commit is contained in:
committed by
Bastien Nollet
parent
73aa66a219
commit
d58efc7b2d
26
@xen-orchestra/disk-transform/src/Throttled.mts
Normal file
26
@xen-orchestra/disk-transform/src/Throttled.mts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { Throttle } from '@vates/generator-toolbox'
|
||||
import { Disk, DiskBlock } from './Disk.mjs'
|
||||
import { DiskPassthrough } from './DiskPassthrough.mjs'
|
||||
|
||||
export class ThrottledDisk extends DiskPassthrough {
|
||||
#throttle: Throttle
|
||||
constructor(source: Disk, throttle: Throttle) {
|
||||
super(source)
|
||||
this.#throttle = throttle
|
||||
}
|
||||
async buildDiskBlockGenerator(): Promise<AsyncGenerator<DiskBlock>> {
|
||||
const generator = await this.source.buildDiskBlockGenerator()
|
||||
//throttle want to be able to know the length of the data
|
||||
async function* generatorWithLength() {
|
||||
for await (const { index, data } of generator) {
|
||||
yield {
|
||||
index,
|
||||
data,
|
||||
length: data.length,
|
||||
}
|
||||
}
|
||||
}
|
||||
const throttledGenerator = this.#throttle.createThrottledGenerator(generatorWithLength())
|
||||
return throttledGenerator as AsyncGenerator<DiskBlock>
|
||||
}
|
||||
}
|
||||
@@ -9,4 +9,5 @@ export { RawDisk } from './RawDisk.mjs'
|
||||
export { ReadAhead } from './ReadAhead.mjs'
|
||||
export { SynchronizedDisk } from './SynchronizedDisk.mjs'
|
||||
export { TimeoutDisk } from './Timeout.mjs'
|
||||
export { ThrottledDisk } from './Throttled.mjs'
|
||||
export { ProgressHandler } from './ProgressHandler.mjs'
|
||||
|
||||
Reference in New Issue
Block a user