• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Performance issue with large data(such as images)

 
will zhang
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9295
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic