SSRS Warm Up Script

In SSRS 2005, after a period of inactivity (no calls to Reporting services), the first call to RS is very slow. This is more of an IIS issue than reporting services. The app pool generally winds down if there is no activity for a certain period of time. When the subsequent (first) request comes into reporting services, it has to restart everything hence the slowness.

In order to overcome this issue I wrote a SSRS Warm Up script. This is a windows service which executes at regular intervals, on the time elapse event I call the SSRS web service which executes and retrieves the PDF for a dummy report. This way if the app pool recycles, the warm up services will kick in and keep the server ready for subsequent requests.

I tested this by recycling the app pool to simulate cold start.

Test Result :  Executing my dummy report on cold start took almost 20 sec. After Warm up took 6 sec


Windows Service

Imports SsrsWarmUp.Core
Imports System.Timers
Imports System.Configuration

Public Class SsrsWarmUpService
    Private _warmUpTimer As Timer = Nothing
    Private _warmUpCore As WarmUpCore
    Private warmUpLock As New Object

    Public Sub New()
        _warmUpCore = New WarmUpCore
        _warmUpTimer = New Timer()
        _warmUpTimer.Interval = Convert.ToDouble(ConfigurationManager.AppSettings(“ExecuteInterval”))
        AddHandler _warmUpTimer.Elapsed, New System.Timers.ElapsedEventHandler(AddressOf Me.warmUpTimer_Elapsed)

    End Sub

    Protected Overrides Sub OnStart(ByVal args() As String)
        Catch ex As Exception
            EventLog.WriteEntry(“SsrsWarmUp Service”, ex.Message)
        End Try
    End Sub

    Protected Overrides Sub OnStop()
        Catch ex As Exception
            EventLog.WriteEntry(“SsrsWarmUp Service”, ex.Message)
        End Try
    End Sub
    Protected Sub warmUpTimer_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs)
        SyncLock warmUpLock
        End SyncLock
    End Sub

End Class

WarmupCore Class

Imports System.Configuration
Imports System.IO

Public Class WarmUpCore

    Public Sub ExecuteReport()
        Dim rs As New ssrs.ReportingService()
        rs.Credentials = New MyICredentials()
        Dim ResultStream() As Byte = Nothing
        Dim OptionalParam As String = Nothing
        Dim optionalParams As ssrs.ParameterValue() = Nothing
        Dim optionalWarnings As ssrs.Warning() = Nothing
        Dim StreamIdentifiers() As String = Nothing
        ResultStream = rs.Render(ConfigurationManager.AppSettings(“ExecuteReport”), “PDF”, Nothing, “<DeviceInfo><StreamRoot>/RSWebServiceXS/</StreamRoot></DeviceInfo>”, Nothing, Nothing, Nothing, OptionalParam, OptionalParam, optionalParams, optionalWarnings, StreamIdentifiers)
    End Sub
    Private Sub WritePdfBytes(ByVal pdfBytes As System.Byte())
        Dim filePath = “c:\ssrsWarmUp.Pdf”
        Dim theFile As FileStream
        If File.Exists(filePath) Then
        End If
        theFile = File.Create(filePath)
        GetStreamFromByte(theFile, pdfBytes)

    End Sub
    Private Sub GetStreamFromByte(ByRef theFile As FileStream, ByVal docData As Byte())
        theFile.Position = 0
        theFile.Write(docData, 0, docData.Length)
    End Sub
End Class

Note: In Sql Server 2008 this issue may not exist as there is no IIS to control.