|
-
Nov 17th, 2009, 05:42 AM
#1
Thread Starter
Hyperactive Member
Loading Images from Database, the Best Practice
hi, any tip on how best to work with database images?
i need to display images on each page in my application, the images are stored in the database.Going to the database on each page hit for a data fetch will not make this application scalable. how best can i work around this. the images depends on each unique user (session) using the application, so i cant cache this data. note, how to fetch is not the issue but implementing sometime more scalable along with less resources (database access, CPU , server memory etc)
any tips?thanx
Nobody is smarter than all of us!
-
Nov 17th, 2009, 05:57 AM
#2
Hyperactive Member
Re: Loading Images from Database, the Best Practice
Have you got the actual image stored in your database or just image file names?
Coz I have always placed filenames on the database then just pull out in the front-end using asp.
Please go to the Thread Tools menu and click Mark Thread Resolved when your post is answered 
If someone helped you today then please consider rating their post.
-
Nov 17th, 2009, 06:23 AM
#3
Re: Loading Images from Database, the Best Practice
Hey,
Agreed. I tend to always store just the image location in the database, and then actually store the image on the file system.
However, this doesn't actually answer your question, as you would still have to render the image from the file system to the client.
One way to ensure optimal performance might be to Cache the image. Are you familiar with this concept?
Gary
-
Nov 17th, 2009, 07:21 AM
#4
Thread Starter
Hyperactive Member
Re: Loading Images from Database, the Best Practice
 Originally Posted by Greyskull
Have you got the actual image stored in your database or just image file names?
Coz I have always placed filenames on the database then just pull out in the front-end using asp.
the actually images files resides in a database, i fetch them & at runtime ,re-create them as jpeg but problem is : i dont want to keep doing this on each page hit
Nobody is smarter than all of us!
-
Nov 17th, 2009, 08:37 AM
#5
Re: Loading Images from Database, the Best Practice
Hey,
In that case, I think the only option would be to Cache the picture.
Or, re-design your application to not store the image in the database.
How big are these images?
Gary
-
Nov 17th, 2009, 09:00 AM
#6
Thread Starter
Hyperactive Member
Re: Loading Images from Database, the Best Practice
 Originally Posted by gep13
Hey,
In that case, I think the only option would be to Cache the picture.
Or, re-design your application to not store the image in the database.
How big are these images?
Gary
The images are around 100kb each and about 10 of these images is shown on each page. can i cache uniquely for each user using a user control?(VaryByParam)
Nobody is smarter than all of us!
-
Nov 17th, 2009, 09:07 AM
#7
Re: Loading Images from Database, the Best Practice
Hey,
You can if you need to.
http://msdn.microsoft.com/en-us/library/ms972379.aspx
Can you provide some details as to what exactly you are trying to achieve?
Gary
-
Nov 17th, 2009, 09:53 AM
#8
Thread Starter
Hyperactive Member
Re: Loading Images from Database, the Best Practice
 Originally Posted by gep13
on each page hit, am fetching images from the database & displaying these images on the web pages. Am sure this method is not scalable (becuase of the datbase fetch on each page hit), so am looking at caching the data so as to go to the database once and only once & re-use the images in the subsequent pages without reverting to the database again for an image fetch. Note, images to be fetch from the database are unique for each user using the application
Nobody is smarter than all of us!
-
Nov 17th, 2009, 10:42 AM
#9
Hyperactive Member
Re: Loading Images from Database, the Best Practice
If you have the images as filenames and stored the images in a local folder you could simply call the Eval function to pull each image through i.e.
Eval("PicURL","images\\thumb_{0}");
But since you have them in your actual db, I read an article before on how to pull them out although not sure how effective it is as I haven't tried it personally.
http://www.sqlteam.com/article/images-and-sql-server
Regards
Please go to the Thread Tools menu and click Mark Thread Resolved when your post is answered 
If someone helped you today then please consider rating their post.
-
Nov 17th, 2009, 11:12 AM
#10
Re: Loading Images from Database, the Best Practice
Hey,
If I were doing your application, then I would definitely look at storing the files on the file system, and just the location in the database, this should make it more scalable. Having said that though, at the end of the day, enterprise databases should eat this type of thing up for lunch.
As a complete example, take a look at this Starter Kit:
http://www.asp.net/downloads/starter-kits/personal/
Gary
-
Nov 17th, 2009, 11:18 AM
#11
Thread Starter
Hyperactive Member
Re: Loading Images from Database, the Best Practice
 Originally Posted by Greyskull
If you have the images as filenames and stored the images in a local folder you could simply call the Eval function to pull each image through i.e.
Eval("PicURL","images\\thumb_{0}");
But since you have them in your actual db, I read an article before on how to pull them out although not sure how effective it is as I haven't tried it personally.
http://www.sqlteam.com/article/images-and-sql-server
Regards
thanx so much for ur replies
they are all good and interesting
what am currently working on, am not working with the file system, just between my code and the database. how retrieve the images from the database is not an issue but my problem is how best to use less resources. i need to display the images from database in each page. i dont want to get down to the database on each page hit becuase that will mean : if the user visits 20 pages, i get down to the database 20 times!, to resolve this, am looking at the asp.net cache stuff and also trying to see if there is also another alternative method to this
Nobody is smarter than all of us!
-
Nov 17th, 2009, 11:20 AM
#12
Re: Loading Images from Database, the Best Practice
Hey,
In this case, I would have said Cache would have been your best option.
Gary
-
Nov 18th, 2009, 10:36 AM
#13
Thread Starter
Hyperactive Member
Re: Loading Images from Database, the Best Practice
 Originally Posted by gep13
Hey,
In this case, I would have said Cache would have been your best option.
Gary
i'd implemented the intended functionality as a user control and cached the user control by setting the below in the user control
<%@ OutputCache Duration ="3600" VaryByControl="onlineUser" Shared ="true" %>
but am running into some issues, the same content of user control is displayed for all users, i needed to cache on a individual user basis. plz , am i missing out any setting?
Nobody is smarter than all of us!
-
Nov 18th, 2009, 10:52 AM
#14
Re: Loading Images from Database, the Best Practice
-
Nov 21st, 2009, 06:15 PM
#15
Re: Loading Images from Database, the Best Practice
Gun, meet foot. 
If you're worried about performance, your first step should be to remove the images from the database and leaving them on disk. With caching, you're increasing load on the server since you're now storing the images in memory, on average 1MB per page - that is quite a lot, especially if you're in a shared hosting environment, but a lot even if it's a dedicated server. I don't believe that caching is a good idea though, it's not a solution but a workaround to a design flaw. You are correct that it is not scalable and in the long term, it can cause more problems than the current convenience is worth. With storing the files on disk, you prevent future database bloat and you don't have that extra step of conversion and handling.
If however, you insist on continuing this way, you want data caching (adding items to the Cache object using Cache.Insert, etc).
-
Nov 24th, 2009, 01:46 AM
#16
Thread Starter
Hyperactive Member
Re: Loading Images from Database, the Best Practice
 Originally Posted by mendhak
Gun, meet foot.
If you're worried about performance, your first step should be to remove the images from the database and leaving them on disk. With caching, you're increasing load on the server since you're now storing the images in memory, on average 1MB per page - that is quite a lot, especially if you're in a shared hosting environment, but a lot even if it's a dedicated server. I don't believe that caching is a good idea though, it's not a solution but a workaround to a design flaw. You are correct that it is not scalable and in the long term, it can cause more problems than the current convenience is worth. With storing the files on disk, you prevent future database bloat and you don't have that extra step of conversion and handling.
If however, you insist on continuing this way, you want data caching (adding items to the Cache object using Cache.Insert, etc).
thanx so much. you are very correct and in fact,i'd switched back to using the filesystem for the images (i couldnt initially because WRITE access ). So, am getting back to my desk to continue with the application
Nobody is smarter than all of us!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|