locked
Images on fly --- to slow RRS feed

  • Question

  • User1718404859 posted
    I am new to ASP.Net, i have designed a web page which get data from sql server and draw graph based on that data and display it on web page ...it draws 4 images. Following code is on page load event ..._clsDrawGraph is the instance of the class which gets data from sql serve and draws graph Select Case Request.QueryString("image") Case 1 _clsDrawGraph.draw(440,660, response.OutputStream) Case 2 _clsDrawGraph.drawtemp(523,660,Response.OutputStream) Case 3 _clsDrawGraph.DrawRain(232, 384, Response.OutputStream) Case 4 _clsDrawGraph.DrawRH(232, 384, Response.OutputStream) End Select in the design phase <asp:Image id="ImgWind" runat="server" HorizontalAlign="Center" imageurl="Wx.aspx?image=1"></asp:Image> it is working fine...but it is very slow...it takes almost 30 second to display the page...and the graph needs to be update every minute...so it is really very slow. is there any way to fix the prob. thanx in advance
    Tuesday, June 15, 2004 1:44 AM

All replies

  • User1335990741 posted
    I had a similar issue on a project I was working on. My guess is that some code optimizations will speed that up. GDI is not the fastest graphics library but it isn’t that slow. I would first split up your code so that you get your data separate from drawing and looking into caching your data, database access is almost always the slowest part of any web application, take some time to make sure that you get the data as efficiently as possible. In my case I needed the same set of data to render the image as I did for the page that hosted the image. I grabbed the data in the host page and cached it for the image giving it a short cache timeout. My image page doesn’t have to touch the database and can render the image in well under a second. It took a good 10 seconds for the image to show up when I had both pages hitting the database. The sql statement took just less the five seconds to run. Once you have optimized your data access take a good look at your code drawing the image. I’m guessing you can optimize a loop or two in there, making sure you are doing the bare minimum amount of work that you can in the loop, taking out any lines of code that do not absolutely have to be in a loop. When I’m working on speed up I have a Windows Forms app that uses the graphics objects to paint the screen that also has a FPS counter. I then comment out sections of code to figure out what parts of the code I need to work on to speed up the drawing. I hope that gets you on the right path.
    Thursday, June 17, 2004 3:59 PM
  • User-970556239 posted
    I also had a problem like this on a project I am working on. The information I found on speeding up GDI+ was to try to make all the pens and brushes and such global and delete them when you are done. This didn't really help me much. It improved the speed a 1/2 or if I was lucky a 1 at most. Perhaps that was wishful thinking. I also set the drawing properties of my bitmap to high speed. I really didn't noticed a difference time wise between high speed and high quality with anti aliasing but I did notice a difference in the quality of the graphic. It's probably not worth it to go high speed. I also found my slow down was accessing the SQL server. Until the stored procedure was modified it took 4 to 8 seconds to run. After modification query analyzer clocked in at 0 to 1 second.
    Saturday, June 19, 2004 9:17 PM
  • User1718404859 posted
    Thanks for your suggestion...i too think it can be because of SQL server as sql server is on different server then web server. But to draw the graph web page need to connect the database, as graph shows the latest weather information...which is updated every minute. so how can i i do it. Dim con As New SqlConnection(Sql_Con_Str) Dim tempday As Integer = 12 ' DatePart(DateInterval.DayOfYear, Today()) Dim str As String = "Select * from TblRealTimeData where RT_day = '" & tempday & "' And RT_year = '" & Year(Today()) & "' order by RT_Time" Dim s As String = str Dim i As Integer = 0 Dim tmptime As String con.Open() Dim com As New SqlCommand(str, con) com.CommandText = str Dim SqlDR As SqlDataReader SqlDR = com.ExecuteReader If SqlDR.HasRows = True Then 'SETTING THE VALUES hightemp = -100 lowtemp = 100 highRH = -100 lowRH = 100 TotalRain = 0 'GETTING THE VALUES FROM THE DATABASE Do While SqlDR.Read ' tmptime = CStr(SqlDR.Item("RT_time")) tmptime = "1230" Select Case Microsoft.VisualBasic.Len(tmptime) Case 3 hour = CInt(Microsoft.VisualBasic.Left(tmptime, 1)) Case 4 hour = CInt(Microsoft.VisualBasic.Left(tmptime, 2)) Case Else hour = 0 End Select min = CInt(Microsoft.VisualBasic.Right(tmptime, 2)) timeoffset = ((hour * 60) + min) / 6 '+ 1 tempnow = CSng(SqlDR.Item("RT_temp")) tempHist(timeoffset) = tempnow RainHist(timeoffset) = SqlDR.Item("RT_DRain") 'TotalRain = TotalRain + SqlDR.Item("RT_Drain") 'TotalRain = TotalRain + SqlDR.Item("RT_rain") WindDeg = CInt(SqlDR.Item("RT_AvgwindD")) windSpeed = SqlDR.Item("RT_AVgWS") WindGust = SqlDR.Item("RT_MaxWS") If hightemp < SqlDR.Item("RT_Temp") Then hightemp = SqlDR.Item("RT_temp") End If If lowtemp > SqlDR.Item("RT_Temp") Then lowtemp = SqlDR.Item("RT_Temp") End If If highRH < SqlDR.Item("RT_RH") Then highRH = SqlDR.Item("Rt_RH") End If If lowRH > SqlDR.Item("RT_RH") Then lowRH = SqlDR.Item("Rt_RH") End If rhNow = Math.Round(SqlDR.Item("RT_RH"), 2) i = i + 1 Loop End If SqlDR.Close() str = "select top 20 RT_AVgWindD, RT_AvgWS from tblRealTimeData where RT_day = '" & tempday & "' And RT_year = '" & Year(Today()) & "' order by RT_time desc" com.Dispose() com = New SqlCommand(str, con) SqlDR = com.ExecuteReader() i = 0 Do While SqlDR.Read WindDir(i) = CInt(SqlDR.Item("RT_AvgWindD")) windspeedArray(i) = CInt(SqlDR.Item("RT_AvgWS")) i = i + 1 Loop SqlDR.Close() com.Dispose() str = "select top 1 rt_id from tblrealtimedata order by rt_id desc" com = New SqlCommand(str, con) SqlDR = com.ExecuteReader() Do While SqlDR.Read DayTime = SqlDR.Item("RT_ID") Loop SqlDR.Close() com.Dispose() str = "Select H_MaxRH, h_MinRh from tblhourlydata where h_day = '" & tempday & "' and h_year = '" & Year(Today()) & "' order by h_Time asc" com = New SqlCommand(str, con) SqlDR = com.ExecuteReader i = 0 Do While SqlDR.Read rhHistory(i) = SqlDR.Item("H_MaxRH") rhHistoryMin(i) = SqlDR.Item("H_MinRH") i = i + 1 Loop SqlDR.Close() com.Dispose() con.Close() End Sub this is the code which connects to database get some important data to display on graph......
    Edit by moderator - NetProfit: Please use <co<color="black">de></co</color>de> tags!
    Sunday, June 20, 2004 8:52 PM
  • User1718404859 posted
    Looks like my sql connection has problems.....i changed it....now using dataset to get the requested data and then manipulating it(as not i know littile bit more ADO.net than before Good) but prob is that still i cannot figure out where to call this function on page...to make to connect to sql server only once...no four times as it is doing now.... Pls help.
    Sunday, June 20, 2004 11:11 PM