• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Performance issue with large data(such as images)

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic