@@ -5,6 +5,7 @@ import IClientContext from '../contracts/IClientContext';
55import IResultsProvider , { ResultsProviderFetchNextOptions } from './IResultsProvider' ;
66import { ArrowBatch } from './utils' ;
77import { LZ4 } from '../utils' ;
8+ import { LogLevel } from '../contracts/IDBSQLLogger' ;
89
910export default class CloudFetchResultHandler implements IResultsProvider < ArrowBatch > {
1011 private readonly context : IClientContext ;
@@ -68,17 +69,43 @@ export default class CloudFetchResultHandler implements IResultsProvider<ArrowBa
6869 return batch ;
6970 }
7071
72+ private logDownloadMetrics ( url : string , fileSizeBytes : number , downloadTimeMs : number ) : void {
73+ const speedMBps = fileSizeBytes / ( 1024 * 1024 ) / ( downloadTimeMs / 1000 ) ;
74+ const cleanUrl = url . split ( '?' ) [ 0 ] ;
75+
76+ this . context
77+ . getLogger ( )
78+ . log ( LogLevel . info , `Result File Download speed from cloud storage ${ cleanUrl } : ${ speedMBps . toFixed ( 4 ) } MB/s` ) ;
79+
80+ const speedThresholdMBps = this . context . getConfig ( ) . cloudFetchSpeedThresholdMBps ;
81+ if ( speedMBps < speedThresholdMBps ) {
82+ this . context
83+ . getLogger ( )
84+ . log (
85+ LogLevel . warn ,
86+ `Results download is slower than threshold speed of ${ speedThresholdMBps . toFixed (
87+ 4 ,
88+ ) } MB/s: ${ speedMBps . toFixed ( 4 ) } MB/s`,
89+ ) ;
90+ }
91+ }
92+
7193 private async downloadLink ( link : TSparkArrowResultLink ) : Promise < ArrowBatch > {
7294 if ( Date . now ( ) >= link . expiryTime . toNumber ( ) ) {
7395 throw new Error ( 'CloudFetch link has expired' ) ;
7496 }
7597
98+ const startTime = Date . now ( ) ;
7699 const response = await this . fetch ( link . fileLink , { headers : link . httpHeaders } ) ;
77100 if ( ! response . ok ) {
78101 throw new Error ( `CloudFetch HTTP error ${ response . status } ${ response . statusText } ` ) ;
79102 }
80103
81104 const result = await response . arrayBuffer ( ) ;
105+ const downloadTimeMs = Date . now ( ) - startTime ;
106+
107+ this . logDownloadMetrics ( link . fileLink , result . byteLength , downloadTimeMs ) ;
108+
82109 return {
83110 batches : [ Buffer . from ( result ) ] ,
84111 rowCount : link . rowCount . toNumber ( true ) ,
0 commit comments