@@ -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,40 @@ 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 . getLogger ( ) . log (
77+ LogLevel . info ,
78+ `Result File Download speed from cloud storage ${ cleanUrl } : ${ speedMBps . toFixed ( 4 ) } MB/s`
79+ ) ;
80+
81+ const speedThresholdMBps = this . context . getConfig ( ) . cloudFetchSpeedThresholdMBps ;
82+ if ( speedMBps < speedThresholdMBps ) {
83+ this . context . getLogger ( ) . log (
84+ LogLevel . warn ,
85+ `Results download is slower than threshold speed of ${ speedThresholdMBps . toFixed ( 4 ) } MB/s: ${ speedMBps . toFixed ( 4 ) } MB/s`
86+ ) ;
87+ }
88+ }
89+
7190 private async downloadLink ( link : TSparkArrowResultLink ) : Promise < ArrowBatch > {
7291 if ( Date . now ( ) >= link . expiryTime . toNumber ( ) ) {
7392 throw new Error ( 'CloudFetch link has expired' ) ;
7493 }
7594
95+ const startTime = Date . now ( ) ;
7696 const response = await this . fetch ( link . fileLink , { headers : link . httpHeaders } ) ;
7797 if ( ! response . ok ) {
7898 throw new Error ( `CloudFetch HTTP error ${ response . status } ${ response . statusText } ` ) ;
7999 }
80100
81101 const result = await response . arrayBuffer ( ) ;
102+ const downloadTimeMs = Date . now ( ) - startTime ;
103+
104+ this . logDownloadMetrics ( link . fileLink , result . byteLength , downloadTimeMs ) ;
105+
82106 return {
83107 batches : [ Buffer . from ( result ) ] ,
84108 rowCount : link . rowCount . toNumber ( true ) ,
0 commit comments