aspose file tools*
The moose likes Struts and the fly likes Performance issue with large data(such as images) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Performance issue with large data(such as images)" Watch "Performance issue with large data(such as images)" New topic
Author

Performance issue with large data(such as images)

will zhang
Ranch Hand

Joined: Sep 11, 2008
Posts: 46
Firstly, I persist the portraits (images) of all users in the db as Strings (large one, say length 5000). Then, I want to get the String and display the portraits of users on the web page(like a topic in a forum). Here I know three solutions but none of them is efficient:
1. Because the image is large, it's not efficient to store it in objects(beans).
2. Because I have many users(say 300), if I store all the maps(userId and image) in the session, the session will be huge.
3. Because I have many users(say 300), if I access the db for each user's image, the worse case is I will have to access db for 300 times.

Is there any solution (such as a design pattern or interceptor) for this performance issue? Many thanks!
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8968
    
    9

I usually place images in the file system. If you don't have a lot of changes in your population, you can probably get away with building when you add/delete them, use ordinary HTML IMG tags and include the images in your WAR.
If you have a more dynamic environment, store them outside the WAR and write a quick-and-dirty Servlet to take a parameter like the user ID, look up or construct the image name and return the image data.


[How To Ask Questions On JavaRanch]
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

5k * 300 == 1500k, call it 2M for the sake of argument. That's not that much memory, although I tend to keep them on the filesystem too-they'll be cached by the browser.
will zhang
Ranch Hand

Joined: Sep 11, 2008
Posts: 46
Thanks, so if I want to persist the images in the db instead of local files, method 2 is the best and durable solution?
will zhang
Ranch Hand

Joined: Sep 11, 2008
Posts: 46
Joe Ess wrote:I usually place images in the file system. If you don't have a lot of changes in your population, you can probably get away with building when you add/delete them, use ordinary HTML IMG tags and include the images in your WAR.
If you have a more dynamic environment, store them outside the WAR and write a quick-and-dirty Servlet to take a parameter like the user ID, look up or construct the image name and return the image data.


Because the user can change their portrait, if I want to store their portraits in the file system, I can only store them outside WAR? I'm not familiar with quick-and-dirty Servlet. Is there any examples?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Performance issue with large data(such as images)