SitePoint Sponsor

User Tag List

Page 1 of 3 123 LastLast
Results 1 to 25 of 64
  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Time to find some ways of making my site run faster

    Hey pple,
    I've recently finished doing another update to my website to try and make the pages (especially the ones pulling images from the DB) run faster,
    For now ill just take the example of my videos page, it pulls 2 images from the DB, 1st is black/white and the 2nd is colored one, when some1 mouseover the 1st image then the 2nd image (colored one) should replace it, the annoying problem is the delay ! there's like 5 or even more seconds delay until the images are changed, how to make this run faster...?

    Thanks in advance!
    Some of the current codes:
    Code ASP:
    <%
     do until RS.eof
      title = RS("title")
      author = RS("author")
      link = RS("link")
      pic = RS("FileID")
      If Counting = 8 then
       Response.Write "<br/>"
       %>
       <a title="header=[<%=title%>] body=[<b>Video Author:</b> <%=author%>] delay=[100] fade=[off]" href="#" onclick="ytplayer.loadVideoById('<%=link%>', 0)"><img border="0" width="120" height="90" src="pics.asp?FileID=<%=pic%>" onmouseover="this.src='pics.asp?FileID2=<%=pic%>'" onmouseout="this.src='pics.asp?FileID=<%=pic%>'" /></a>
       <%
       Counting = 1
      Else
      %>
      <a title="header=[<%=Title%>] body=[<b>Video Author:</b> <%=author%>] delay=[100] fade=[off]" href="#" onclick="ytplayer.loadVideoById('<%=Link%>', 0)"><img border="0" width="120" height="90" src="pics.asp?FileID=<%=pic%>" onmouseover="this.src='pics.asp?FileID2=<%=pic%>'" onmouseout="this.src='pics.asp?FileID=<%=pic%>'" /></a>
      <%
      Counting = Counting + 1
      End If
      rs.movenext
     loop
    rs.close
    conn.Close
    Set rs= Nothing
    Set conn= Nothing
    %>

    Form that gets the images:
    Code ASP:
    FileID = Request.QueryString("fileID")
    if fileID <> "" then
    ' If image1 was requested then it pulls only image number 1
     sql = "SELECT BinaryData FROM movies WHERE FileID = " & FileID
     rs.Open sql, conn, 3, 3
     Response.BinaryWrite rs("BinaryData")
     rs.close
     conn.Close
     Set rs= Nothing
     Set conn= Nothing
     Response.End
    ' Finished getting image number 1 
    Else
    ' If image number 2 was requested, then it skips the first part
    ' of this page and starts from here
    FileID2 = Request.QueryString("FileID2")
     If FileID2 <> "" then
      sql = "SELECT BinaryData2 FROM Vids WHERE FileID = " & FileID2
      rs.Open sql, conn, 3, 3
      Response.BinaryWrite rs("BinaryData2")
      rs.close
      conn.Close
      Set rs = Nothing
      Set conn = Nothing
     End if
    End if

    Any kind of advice is appreciated, i just got the same delay problem on my gallery / adoption pages and its really annoying.
    P.S. Some1 mentioned earlier doing this in arrays to try and run it faster, he just wasn't sure if images can be stored in arrays, if they can i'd like to hear how can i do that with arrays..
    Thanks, Ulthane

  2. #2
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the only way to make it faster is to download two images and stack them on top of one another. then use javascript to do a show-hide on onmouseover.

    there are tons of javascript examples that do just that - just google around and you will find them.

  3. #3
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Is boxover.js one of them?

    download two images and stack them on top of one another.
    And how do i do that?

  4. #4
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you have internet explorer as a browser there is example code here:

    Using visibility as part of your page style

    check out the demo to see what I mean

  5. #5
    SitePoint Enthusiast Atle Iversen's Avatar
    Join Date
    Jul 2010
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Depending on your site, you probably shouldn't pull images from a database if you can avoid it...

    If you use shared hosting you should consider moving your images to Amazon S3 or similar to improve the "download" speed of images. If you have your own dedicated server with a lightning fast back-end it *might* be faster than S3, but S3 ensures good speed even when traffic spikes hit you.

    The *percepted* speed depends on pre-loading images (but of course the user must wait longer until anything happens then)...

    Good luck :-)
    PpcSoft iKnow - Never forget anything important again (My blog)

  6. #6
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    if you have internet explorer as a browser there is example code here:

    Using visibility as part of your page style

    check out the demo to see what I mean
    k understood what that is, after looking at the example a few times i still dont understand how should i do that using my code, i mean i dont use stuff like that...
    Code:
    IMG {position:absolute; top:100; left:100; height:160}
    my code is way different than that example, it helped me understand how to put images on top of each another but how to do it using my code, not a clue...

  7. #7
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,037
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Atle Iversen View Post
    Depending on your site, you probably shouldn't pull images from a database if you can avoid it...
    I have to agree with this. The biggest bottleneck in your system is that you are loading images into a database and then retrieving them from the database. Those calls in themselves are likely more resource intensive than anything else you are doing.

    If you truly want to improve the speed of the system (especially if the images are large), store them in the file system and save their path to the database.

    The second thing you can do to speed things up is use GetRows to save your database query to a multidimensional array instead of looping through a database recordset.
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  8. #8
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    If you truly want to improve the speed of the system (especially if the images are large), store them in the file system and save their path to the database.
    ok, I guess thats what ill do, so ill save the images in a folder called PetImages and then just save the paths to the database, now:

    The second thing you can do to speed things up is use GetRows to save your database query to a multidimensional array instead of looping through a database recordset.
    Ill need some example on that...

    Edit* how do i upload the path to the DB btw? tried like that:
    rs.Fields("path").Value = Upload.Fields("db") & "\photos\" & FileName
    Or that:
    rs.Fields("path").Value = Upload.Fields(Folder, FileName)

    No luck
    Thanks for the help

  9. #9
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,037
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    I have to go out for a bit now but I'll dig through my old files...

    I created a simple staff section for a website about 10 years ago that allowed you to upload a snapshot of each individual with a little biography. It would upload the image to a folder and save the text of the path to a database column. It was a pretty simple system but I'll see if I have it archived and post the relevant code.
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  10. #10
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hey ulthane. I thought you were using Lewis Moten's uploader class? When did you start saving images in the database?
    Ian Anderson
    www.siteguru.co.uk

  11. #11
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,037
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Ok, so I dug up that old website I was referring to and it used an file upload class that I think I got from ASPIN www.aspin.com The header on the code is as follows:
    HTML Code:
    '***************************************
    ' File:      Upload.asp
    ' Author: Jacob "Beezle" Gilley
    ' Email:  I removed the email address
    ' Date:   12/07/2000
    ' Comments: The code for the Upload, CByteString, 
    '            CWideString    subroutines was originally 
    '            written by Philippe Collignon...or so 
    '            he claims. Also, I am not responsible
    '            for any ill effects this script may
    '            cause and provide this script "AS IS".
    '            Enjoy!
    '****************************************
    Anyway, what I did was create a multipart/form-data form with a text field to name the file and a file input to browse and find the file you want to upload. The form posts to a script that uses the upload class to save the file to the file system so you have to have permission to do that on your server.

    On a successful upload I run an insert query as follows but you'll have to modify it for your uploader class (my connection object is Conn and the class allows saving to either disk or database):
    Code:
    ' Check if any files were uploaded
    If Uploader.Files.Count = 0 Then
        Response.Write "File(s) not uploaded."
    Else
        ' Loop through the uploaded files
        For Each File In Uploader.Files.Items
            
            ' Check where the user wants to save the file
            If Uploader.Form("saveto") = "disk" Then
      
                'SAVE THE FILE USING Server.MapPath("")
                Dim savePath
                savePath = Server.MapPath("images")
                savePath = savePath & "\"
                File.SaveToDisk  savePath
            
            End If
            
    
            'WRITE IMAGE DETAILS TO THE DATABASE 
            Dim strQuery, objRS, imgLink, insName
    
            imgLink = File.FileName
    
            insName = Uploader.Form("fullname")
    
            strQuery = "INSERT INTO Pictures(Name, imgLink) VALUES('"&insName&"', '"&imgLink&"')"
    
            Set objRS = Conn.Execute(strQuery)
    
        Next
    
    End If
    Let me know if that makes sense and if so, I'll elaborate on GetRows next.
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  12. #12
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Really really sorry for taking so long to reply, im working on 2 more projects in the same time and didnt had time at all to get back to this one.

    However thanks for the help Awasson, i got it working, Need some explains / examples on that GetRow stuff now

    Siteguru: i always uploaded photos to the DB using lewis moten's guides, only the Gallery photos went to a folder since they didnt have any addational field with them, well now it seems stupid doing that, so i guess ill make folders for the images now ;p

    Thanks for the help

  13. #13
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,037
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    No worries, I know what it's like to juggle a bunch of jobs at the same time.

    I wrote an article for SP about 6 years ago about ASP GetRows() because I was so impressed with the performance and flexibility it provided but the thought at that time was that Classic ASP wouldn't be in use much longer so SP never published it. It's ironic though because I still maintain at least one large scale Classic ASP web application which expanded greatly over the last year and it seems there are a few others out there too

    I just de-archived and re-read the last draft and if you can overlook the writing style, it's not a bad explanation. I've attached it to this post with some example code.

    * I use GetRows() constantly when I have to manipulate big datasets in ASP code. The only thing you need to wrap your head around is that you're dealing with a two dimensioned array for all of your data so you have to manage it differently than you would with a one dimensional array or a regular recordset.

    Let me know how that works out for you.

    Cheers,
    Andrew
    Attached Files Attached Files
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  14. #14
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Once you get your head around it, GetRows works really well. Especially for larger scale or busy web applications that use Access as the backend database. The big advantage is that you can retrieve the dataset and then close the database connection early, allowing you scope to manipulate the dataset as you require. (Access only allows a low number of concurrent [at the same time] connections).
    Ian Anderson
    www.siteguru.co.uk

  15. #15
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    getting an error ...
    Microsoft VBScript runtime (0x800A0009)
    Subscript out of range: 'UBound'

    Thats how i tried to build it up:

    Code ASP:
    <%
    Dim Conn, rs, vid, arr
    db = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("db/animals.mdb")
    Set Conn = Server.CreateObject("ADODB.Connection")
    Conn.Open db
    vid = "SELECT * FROM Vids ORDER BY FileID DESC"
    Set rs = Conn.Execute(vid)
    arr = rs.GetRows
    Set rs = Nothing
    Dim iCounter, Counting
    Counting = 1
    For iCounter = 0 to UBound(arr,5)  ' error here
    if counting = 8 then
     Response.Write "<br/>"
    %>
    <a href="header=[<%=table1(3,iCounter)%>] body=[<b>Video Author:</b> <%=table1(4,iCounter)%>] delay=[100] fade=[off] href="#" onclick="ytplayer.loadvideobyid('<%=table1(5,iCounter)%>', 0)"><img border="0" width="120" height="90" src="<%=table1(1,iCounter)%>" onmouseover="this.src=<%=table1(2,iCounter)%>" onmouseout="this.src=<%=table1(1,iCounter)%>" /></a>
    <%
    Counting = 1
    else
    %>
    <a href="header=[<%=table1(3,iCounter)%>] body=[<b>Video Author:</b> <%=table1(4,iCounter)%>] delay=[100] fade=[off] href="#" onclick="ytplayer.loadvideobyid('<%=table1(5,iCounter)%>', 0)"><img border="0" width="120" height="90" src="<%=table1(1,iCounter)%>" onmouseover="this.src=<%=table1(2,iCounter)%>" onmouseout="this.src=<%=table1(1,iCounter)%>" /></a>
    <%
    counting= counting+1
    end if
    Next
    %>

  16. #16
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Ian Anderson
    www.siteguru.co.uk

  17. #17
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    i acutally guessed it, i thought it meant the amount of coluums i got in the table (since the example awasson gave me had arr,2 and the table really had just 2 coluums, well 3 but icounter started at 0.)

    that page isnt much different than the example i got, it doesnt explain what all those stuff means....so ill just ask already...
    what is vbCrLf, vbtab, what is the number that arr goes with (that arr,number) whats the difference between Ubound and Lbound (what are they exactly doing)

    thanks..

  18. #18
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    i got it done, but there is only 1 prob
    My onmouseover doesnt work.. no errors or anything the pic just wont change. how do i solve it?

  19. #19
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,037
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ulthane View Post
    i acutally guessed it, i thought it meant the amount of coluums i got in the table (since the example awasson gave me had arr,2 and the table really had just 2 coluums, well 3 but icounter started at 0.)

    that page isnt much different than the example i got, it doesnt explain what all those stuff means....so ill just ask already...
    what is vbCrLf, vbtab, what is the number that arr goes with (that arr,number) whats the difference between Ubound and Lbound (what are they exactly doing)

    thanks..
    Ok, I'll have a look at the code in just a minute but first here's answers to your questions.

    Don't worry about vbCrLf, vbtab... They just give you paragraph returns and tabs in the source code so it's well formatted when you inspect the html of the examples.

    Ubound and Lbound are the upper bounds and lower bounds of the array and are used in the for-next loop. For a one dimensional array you would use the following to get the upper bound Ubound(arr) but for a 2 dimensional array you have to use UBound(arr,2).

    Your code is using:
    For iCounter = 0 to UBound(arr,5)

    it should be:
    For iCounter = 0 to UBound(arr,2)

    Don't forget once this actually works you'll have to clean a few things up to make sure errors are handled nicely and the code is as efficient as possible. Things like checking that the array actually is an array and setting variables instead of using functions for upper bounds of loops:

    if isarray(arr) then
    limit = UBound(arr,2)
    For iCounter = 0 to limit
    ' Code in here
    next
    end if
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  20. #20
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    thanks for the reply awasson , but why do i need to check if its really an array if i declare it as one already ?;P

    Also i got a few problems...
    Title : Working
    author : working
    Pic 1 : working
    pic 2 (onmouseover) : doesnt work
    Vid link (to change between videos) : Doesnt work

    need help on solving those...thanks

  21. #21
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    oh sorry for another post, i just cant edit the previous one, i got it solved ! some missing '' made the problem

    going to test it out in the site itself and see if there's a change in the loading speed

    Thanks aloot guys

    Edit * Yeah nice, there's improvement in the loading speed, in IE i got about 1 sec delay until the image appears, so on other browsers like chrome / firefox should be alot faster
    also that could be cause of free hosting company, probably could be faster with a paid one ;p

  22. #22
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,037
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Great! Glad that made an improvement. I think originally you had a 5+ second delay and now your down to about a second. Every little bit helps. I've got a hosting company I use for high traffic or mission critical sites. It's more expensive than regular shared hosting but man, the response time is fast!

    TIP: I'm not sure what you're using for layout if you use html tables for your layout, the images will not become visible until all of the table code is rendered. I just duplicated a product catalog for a client that was originally done in tables and we shaved at least a second off the time it takes to render the images by using div's with css positioning.

    ALSO: The reason you test the array is in case the database query returned empty and your array wasn't populated. If that happens and you try to find the UBOUND or loop through it, your visitors will get a vbscript error.

    For production code, I like to do a few things like that and when I'm doing database calls that end up using getrows I use the following and include a string called message for troubleshooting (Assuming Conn is your connection string):
    Code:
    strQuery = "SELECT * FROM my-DB-Table"
    on error resume next
    Set objRS     = Conn.Execute(strQuery)
    if err.number<>0 then 
        message = message & "<p><strong>Warning:</strong> An error occured during this database transaction. </p>"
        message = message & "<p>" & err.number & "<br />" & err.description & "<br />"
        message = message & "Database Query: " & strQuery & "</p>"
        err.Clear
    else
        if NOT objRS.EOF AND NOT objRS.BOF then
            arrQuery = objRS.GetRows
        end if                
    end if
    set objRS = nothing
    
    if isarray(arrQuery) then
        'Now you can safely do something with : arrQuery
    end if
    
    ' response.write message 'Uncomment for troubleshooting
    You can take that further and wrap that up into a custom function and easily return arrays just passing a SQL string.
    Last edited by awasson; Nov 13, 2010 at 18:22. Reason: Clarification
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  23. #23
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Is it an acceptable way of using GetRows? im getting an error when trying to run it...
    Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

    Code ASP:
    DB = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("db.mdb")
    Set Conn = Server.CreateObject("ADODB.Connection")
    Conn.Open DB
    sql = "SELECT FileID, Desc FROM Animals WHERE (animaltype= 'special msg')"
    Conn.Execute(sql)
    arr = Conn.GetRows

    thanks

  24. #24
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    We've been here before.

    [Desc]

    Ian Anderson
    www.siteguru.co.uk

  25. #25
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    didnt solve it ;p
    btw i forgot to mention that the error is on the arr = conn.getrows line


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •