locked
Download PDF from SSRS using HttpClientConnection performance ISSUE RRS feed

  • Question

  • User1580727775 posted

    Dear Team

    Scnario : Download 1000 PDF from report server.
    PDF Size : varies from 30KB to 250KB
    Business Requirement: Shall be completed in one  hour
    Infrastructure Setup: report server and the sql Job that downloads the files and store everything are in SAME server.
    Current Code"

     Dim httpConn As ConnectionManager = Dts.Connections("ReportServer " & strServer)
            Dim clientConn As HttpClientConnection = New HttpClientConnection(httpConn.AcquireConnection(Nothing))
            Dim docItemID As String = CType(Dts.Variables("User::DocItemID").Value, String)
            Dim ReportFileName As String = CType(Dts.Variables("User::FolderLocation").Value, String) & docItemID
            Dim TransportFee As Decimal = CType(Dts.Variables("User::TransportFee").Value, Decimal)
            clientConn.ServerURL = "http://XXXX" & strServer & "/ReportServer?/XXXX-Reports/" & strString & "&docItemId=" & docItemID & "&type=3&rs:Command=Render&rs:Format=PDF&rc:Toolbar=False"
            clientConn.DownloadFile(ReportFileName & ".pdf", True)





    Problem: Even if server CPU usage is not much that means server is not busy, still in one hour only 300 files are getting downloaded.
    Can you please suggest what other options we have to handle this situation? Now can we download 1000 pdf in one hour.

    Shall we increase the CPU core or do you think any other class can give better performance than HttpClientConnection.

    Thanks in advance



    Thursday, September 21, 2017 8:50 AM

All replies

  • User347430248 posted

    Hi joydeepsen,

    I find one code in C#. I can see that you are using VB.Net.

    so I convert that code to VB.Net using code convertor.

    Dim _downloadUrls As Queue(Of String) = New Queue(Of String)
    
         
         Private Sub downloadFile(ByVal urls As IEnumerable(Of String))
             For Each url In urls
                 _downloadUrls.Enqueue(url)
             Next
             ' Starts the download
             btnGetDownload.Text = "Downloading..."
             btnGetDownload.Enabled = false
             progressBar1.Visible = true
             lblFileName.Visible = true
             DownloadFile
         End Sub
         
         Private Sub DownloadFile()
             If _downloadUrls.Any Then
                 Dim client As WebClient = New WebClient
                 client.DownloadProgressChanged = (client.DownloadProgressChanged + client_DownloadProgressChanged)
                 client.DownloadFileCompleted = (client.DownloadFileCompleted + client_DownloadFileCompleted)
                 Dim url = _downloadUrls.Dequeue
                 Dim FileName As String = url.Substring((url.LastIndexOf("/") + 1), (url.Length  _
                                 - (url.LastIndexOf("/") - 1)))
                 client.DownloadFileAsync(New Uri(url), ("C:\Test4\" + FileName))
                 lblFileName.Text = url
                 Return
             End If
             
             ' End of the download
             btnGetDownload.Text = "Download Complete"
         End Sub
         
         Private Sub client_DownloadFileCompleted(ByVal sender As Object, ByVal e As AsyncCompletedEventArgs)
             If (Not (e.Error) Is Nothing) Then
                 ' handle error scenario
                 Throw e.Error
             End If
             
             If e.Cancelled Then
                 ' handle cancelled scenario
             End If
             
             DownloadFile
         End Sub
         
         Private Sub client_DownloadProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs)
             Dim bytesIn As Double = Double.Parse(e.BytesReceived.ToString)
             Dim totalBytes As Double = Double.Parse(e.TotalBytesToReceive.ToString)
             Dim percentage As Double = (bytesIn  _
                         / (totalBytes * 100))
             progressBar1.Value = Integer.Parse(Math.Truncate(percentage).ToString)
         End Sub
     

    below is a links for the original code that you can try to refer to get more information.

    How to Async download multiple files using webclient simultaneously?

    it can download multiple files simultaneously which can help you to increase performance.

    the above code is just an example, you need to modify it as per your requirement.

    Regards

    Deepak

    Thursday, September 21, 2017 11:07 PM
  • User1580727775 posted

    thanks for the reply. The whole process happens through a sql agent job which intern calls a SSIS/DTSX package. There is a Foreach ADO Enumerator in the SSIS package. In each iteration, a documentId is passed to the report server and downloads one pdf at a time. each call looks like 

    http://servername/ReportServer?/APPNAME-Reports/InvoiceGE&docItemId=1847311&type=3&rs:Command=Render&rs:Format=PDF&rc:Toolbar=False

    So parallel downloading might not be possible in our case.

    Thursday, October 5, 2017 8:45 AM
  • User347430248 posted

    Hi joydeepsen,

    you had mentioned that,"So parallel downloading might not be possible in our case."

    then it will be tough to achieve your requirement with in 1 hour of time.

    you can think that if you just download a single file at a time then performance will be drop and will take much more time to finish this job.

    so you can try to think redesign the whole process if possible and necessary for you to get the better performance.

    Regards

    Deepak

    Tuesday, October 17, 2017 3:00 AM