@@ -5,6 +5,7 @@ import IClientContext from '../contracts/IClientContext';
5
5
import IResultsProvider , { ResultsProviderFetchNextOptions } from './IResultsProvider' ;
6
6
import { ArrowBatch } from './utils' ;
7
7
import { LZ4 } from '../utils' ;
8
+ import { LogLevel } from '../contracts/IDBSQLLogger' ;
8
9
9
10
export default class CloudFetchResultHandler implements IResultsProvider < ArrowBatch > {
10
11
private readonly context : IClientContext ;
@@ -68,17 +69,43 @@ export default class CloudFetchResultHandler implements IResultsProvider<ArrowBa
68
69
return batch ;
69
70
}
70
71
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
+
71
93
private async downloadLink ( link : TSparkArrowResultLink ) : Promise < ArrowBatch > {
72
94
if ( Date . now ( ) >= link . expiryTime . toNumber ( ) ) {
73
95
throw new Error ( 'CloudFetch link has expired' ) ;
74
96
}
75
97
98
+ const startTime = Date . now ( ) ;
76
99
const response = await this . fetch ( link . fileLink , { headers : link . httpHeaders } ) ;
77
100
if ( ! response . ok ) {
78
101
throw new Error ( `CloudFetch HTTP error ${ response . status } ${ response . statusText } ` ) ;
79
102
}
80
103
81
104
const result = await response . arrayBuffer ( ) ;
105
+ const downloadTimeMs = Date . now ( ) - startTime ;
106
+
107
+ this . logDownloadMetrics ( link . fileLink , result . byteLength , downloadTimeMs ) ;
108
+
82
109
return {
83
110
batches : [ Buffer . from ( result ) ] ,
84
111
rowCount : link . rowCount . toNumber ( true ) ,
0 commit comments