I have made a SSRS Bulk reporter that queries a report from SSRS using a HTTPWebRequest and a HTTPWebResponse to get the stream and save it as a file to a PDF.
However, the client has complained that this is taking long. I have tested it, and this function is taking +- 15.5seconds. If I put a break in-between the GetResponseStream and the file-writer, and I wait for about 3 seconds before stepping to the next part, it shaves 4 seconds off the total time?
Can anyone explain this/or give some advise as to make it a bit faster?
This is the function:
Public Function ExportReport(ByVal QueryStringParameters As String, ByVal FileName As String) As String
Dim PDFName As String = ReportFolderPath & FileName & ".pdf"
'Create a http request or connecting to the report server.
Dim ReportHTTPRequest As HttpWebRequest = Nothing
'Create a http response to catch the data stream returned from the http request.
Dim ReportHTTPResponse As HttpWebResponse = Nothing
'Create a stream to read the binary data from the http reponse.
Dim ReportStream As Stream = Nothing
Dim ReportFileStream As FileStream = Nothing
'Create an array of bytes to get the binary data from the stream.
Dim ReportBytes As Byte()
Dim ReportBuffer As Integer = 204800
Dim ReportBytesRead As Integer = 0
'Create a webrequest to get the report with all the report parameters included.
ReportHTTPRequest = WebRequest.Create(ReportServerURL & QueryStringParameters)
ReportHTTPRequest.Credentials = CredentialCache.DefaultCredentials
'Get the response from the request.
ReportHTTPResponse = ReportHTTPRequest.GetResponse()
'Read the binary stream from the http response.
ReportStream = ReportHTTPResponse.GetResponseStream()
ReportBytes = New Byte(ReportBuffer) {}
ReportBytesRead = ReportStream.Read(ReportBytes, 0, ReportBuffer)
ReportFileStream = New FileStream(PDFName, FileMode.Create)
Do While ReportStream.CanRead And ReportBytesRead > 0
ReportFileStream.Write(ReportBytes, 0, ReportBytesRead)
ReportBytesRead = ReportStream.Read(ReportBytes, 0, ReportBuffer)
Loop
ReportHTTPResponse.Close()
ReportStream.Close()
ReportFileStream.Close()
Return PDFName
End Function
a magic thing that worked for me, try a buffer size of 32768