struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Richard Sayre <richardsa...@gmail.com>
Subject Re: Performance issue with large data(such as images)
Date Tue, 09 Jun 2009 16:20:56 GMT
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

On Tue, Jun 9, 2009 at 12:49 PM, fireapple<taizhang1981@gmail.com> wrote:
>
> 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!
> --
> View this message in context: http://www.nabble.com/Performance-issue-with-large-data%28such-as-images%29-tp23945029p23945029.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

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


Mime
View raw message