Richard Sayre wrote:
> 
> You should persist the images as bytes, in a binary field or something
> similar.
> 
>> 1. Because the image is large, it's not efficient to store it in
>> objects(beans).
> 
> Well this depends on the Bean.  Is the bean stored in session?  If yes
> then it will take up some memory.  If you dont have alot of memory I
> would not recommend this.
> 
>> 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.
> 
> Again if your requirement is low memory usage then dont store large
> objects in momory for a long time
> 
>> 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.
> 
> Well this is the trade off Memory vs Resources to Connect to a DB.
> Even if the images are not stored in session they will still be held
> in memory when getting them from the DB.
> 
> How often do you need to load all 300 images?  If it is forum style I
> would imangine a limited number of posting per page say max 20.  So
> the would be a maximum of 20 images per page load.
> 
> You could also Store the images in the hard drive of the server, and
> store a URL to the image in the database.  This would reduce the
> memory overhead.  Did you try to do any test to see what the impact of
> retrieveing the data from the database is?
> 
> If you must use the least amount of memory as possible, persist the
> images to the hard drive and store the file reference to the url in
> the database.  Or even store the images as userId_avatar.gif.  That
> way you can link the file to a user id and have no need to store the
> url.  Use a base directory for storing the images.
> 
> Before you guess if something is a performance issue, you should test
> to see what the actual cost of each method of image storing and
> retrival is.
> 
> Rich
> 
> 

Thanks, Rich, 

"You should persist the images as bytes, in a binary field or something
similar."
If I use BLOB, I have to make a lot of change to my code. Therefore, I have
to persist it as String. I used base64 to encode and decode the byte[] into
String. Because I resize the images to small ones. I use a VARCHAR length
about 10k~20k to persist the String.

"How often do you need to load all 300 images?  If it is forum style I
would imangine a limited number of posting per page say max 20.  So
the would be a maximum of 20 images per page load."
If this is true, which method is the best among the above three?

"If you must use the least amount of memory as possible, persist the
images to the hard drive and store the file reference to the url in
the database.  "
If I want to persist images to the hard drive of server. Shall I persist the
data inside WAR or outside? Because user can change their portrait, does it
mean it must be persisted outside WAR?


-- 
View this message in context: 
http://www.nabble.com/Performance-issue-with-large-data%28such-as-images%29-tp23945029p23948048.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to