@@ -446,6 +446,7 @@ func (a *cascadeAdapter) CascadeSupernodeDownload(
446446 bytesWritten int64
447447 chunkIndex int
448448 startedEmitted bool
449+ downloadStart time.Time
449450 )
450451
451452 // 3. Receive streamed responses
@@ -509,7 +510,11 @@ func (a *cascadeAdapter) CascadeSupernodeDownload(
509510 }
510511 }
511512 }
512- in .EventLogger (ctx , toSdkEvent (x .Event .EventType ), x .Event .Message , edata )
513+ // Avoid blocking Recv loop on event handling; dispatch asynchronously
514+ evtType := toSdkEvent (x .Event .EventType )
515+ go func (ed event.EventData , et event.EventType , msg string ) {
516+ in .EventLogger (ctx , et , msg , ed )
517+ }(edata , evtType , x .Event .Message )
513518 }
514519
515520 // 3b. Actual data chunk
@@ -520,7 +525,10 @@ func (a *cascadeAdapter) CascadeSupernodeDownload(
520525 }
521526 if ! startedEmitted {
522527 if in .EventLogger != nil {
523- in .EventLogger (ctx , event .SDKDownloadStarted , "Download started" , event.EventData {event .KeyActionID : in .ActionID })
528+ // mark start to compute throughput at completion
529+ downloadStart = time .Now ()
530+ // Emit started asynchronously to avoid blocking
531+ go in .EventLogger (ctx , event .SDKDownloadStarted , "Download started" , event.EventData {event .KeyActionID : in .ActionID })
524532 }
525533 startedEmitted = true
526534 }
@@ -538,7 +546,25 @@ func (a *cascadeAdapter) CascadeSupernodeDownload(
538546 a .logger .Info (ctx , "download complete" , "bytes_written" , bytesWritten , "path" , in .OutputPath , "action_id" , in .ActionID )
539547
540548 if in .EventLogger != nil {
541- in .EventLogger (ctx , event .SDKDownloadCompleted , "Download completed" , event.EventData {event .KeyActionID : in .ActionID , event .KeyOutputPath : in .OutputPath })
549+ // Compute metrics if we marked a start
550+ var elapsed float64
551+ var throughput float64
552+ if ! downloadStart .IsZero () {
553+ elapsed = time .Since (downloadStart ).Seconds ()
554+ mb := float64 (bytesWritten ) / (1024.0 * 1024.0 )
555+ if elapsed > 0 {
556+ throughput = mb / elapsed
557+ }
558+ }
559+ // Emit completion asynchronously with metrics
560+ go in .EventLogger (ctx , event .SDKDownloadCompleted , "Download completed" , event.EventData {
561+ event .KeyActionID : in .ActionID ,
562+ event .KeyOutputPath : in .OutputPath ,
563+ event .KeyBytesTotal : bytesWritten ,
564+ event .KeyChunks : chunkIndex ,
565+ event .KeyElapsedSeconds : elapsed ,
566+ event .KeyThroughputMBS : throughput ,
567+ })
542568 }
543569 return & CascadeSupernodeDownloadResponse {
544570 Success : true ,
0 commit comments