You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by alexis <al...@gmail.com> on 2011/05/05 20:19:51 UTC

storing images

Hello all, im facing an issue, ive been testing for a while different approaches without success.

I have a servlet that basically does

. creates an image
. store the image on disk
. returns an html <img> tag pointing to the stored image.

reason why the servlet doesnt returns the image directly using a response type image/png is the servlet is called from an ajax script, this ajax script renders the inner text inside a div on a jsp page on the same context that the server runs. ajax can only render html on divs, there's no way to return binary content (the image) from the servlet to the ajax script.


So, i have to create the image on the servlet (done) , store the image on the disk (done), and return the <img> tab also done. Thing is, where im able to store the image from the servlet im not able to read it from the jsp. 

I tried with /tmp, i tried with servletcontext.getpath to store the file on that dir, nothing seems to work. where should i store and reference those images to be written by the servlet and read by the jsp?

thanks in advance


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: storing images

Posted by David kerber <dc...@verizon.net>.
On 5/5/2011 2:19 PM, alexis wrote:
> Hello all, im facing an issue, ive been testing for a while different approaches without success.
>
> I have a servlet that basically does
>
> . creates an image
> . store the image on disk
> . returns an html<img>  tag pointing to the stored image.
>
> reason why the servlet doesnt returns the image directly using a response type image/png is the servlet is called from an ajax script, this ajax script renders the inner text inside a div on a jsp page on the same context that the server runs. ajax can only render html on divs, there's no way to return binary content (the image) from the servlet to the ajax script.
>
>
> So, i have to create the image on the servlet (done) , store the image on the disk (done), and return the<img>  tab also done. Thing is, where im able to store the image from the servlet im not able to read it from the jsp.
>
> I tried with /tmp, i tried with servletcontext.getpath to store the file on that dir, nothing seems to work. where should i store and reference those images to be written by the servlet and read by the jsp?

Will java.io.tmpdir work?

D

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: storing images

Posted by alexis <al...@gmail.com>.
perfect, ill check this.

Thanks for the answer.


On May 5, 2011, at 5:42 PM, Leo Donahue - PLANDEVX wrote:

>> -----Original Message-----
>> From: Caldarale, Charles R [mailto:Chuck.Caldarale@unisys.com]
>> Subject: RE: storing images
>> 
>>> From: alexis [mailto:alzrck@gmail.com]
>>> Subject: storing images
>> 
>> 
>> You have a couple of options:
>> 
>> 1) Create a dummy webapp whose sole purpose is to provide a location for
>> the dynamically generated images.  Create some directory outside of
>> Tomcat's file structure to hold the images, and place a <Context>
>> element in conf/Catalina/[host]/[dummyAppName].xml with a docBase
>> attribute (and nothing else) that points to that directory.  The <img>
>> tags should refer to [dummyAppName] as the URL for retrieving the
>> images.
>> 
>> - Chuck
>> 
> 
> That is exactly what we did for our web app that generates images.
> http://planning.maricopa.gov/agsoutput/_ags_mapad578dbb026f4429aa755f471b259bd3.jpg
> 
> our 2011 images were not so great... regarding the mosaic.
> 
> 
> Leo
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: storing images

Posted by Leo Donahue - PLANDEVX <Le...@mail.maricopa.gov>.
>-----Original Message-----
>From: Caldarale, Charles R [mailto:Chuck.Caldarale@unisys.com]
>Subject: RE: storing images
>
>> From: alexis [mailto:alzrck@gmail.com]
>> Subject: storing images
>
>
>You have a couple of options:
>
>1) Create a dummy webapp whose sole purpose is to provide a location for
>the dynamically generated images.  Create some directory outside of
>Tomcat's file structure to hold the images, and place a <Context>
>element in conf/Catalina/[host]/[dummyAppName].xml with a docBase
>attribute (and nothing else) that points to that directory.  The <img>
>tags should refer to [dummyAppName] as the URL for retrieving the
>images.
>
> - Chuck
>

That is exactly what we did for our web app that generates images.
http://planning.maricopa.gov/agsoutput/_ags_mapad578dbb026f4429aa755f471b259bd3.jpg

our 2011 images were not so great... regarding the mosaic.


Leo

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: storing images

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: alexis [mailto:alzrck@gmail.com] 
> Subject: storing images

> So, i have to create the image on the servlet (done) , store 
> the image on the disk (done), and return the <img> tab also 
> done. Thing is, where im able to store the image from the 
> servlet im not able to read it from the jsp. 

As David suggests, java.io.tmpdir is probably a bit safer than /tmp, since you have some control over that and it can be isolated from other programs running on the same box.

The real problem is how to retrieve the images once stored.  Tomcat normally uses its built-in DefaultServlet to deliver static content, but that only works with files stored within a given webapp (and you should never write into a webapp's deployment directory).

You have a couple of options:

1) Create a dummy webapp whose sole purpose is to provide a location for the dynamically generated images.  Create some directory outside of Tomcat's file structure to hold the images, and place a <Context> element in conf/Catalina/[host]/[dummyAppName].xml with a docBase attribute (and nothing else) that points to that directory.  The <img> tags should refer to [dummyAppName] as the URL for retrieving the images.

 - or -

2) Create a subclass of DefaultServlet that knows where you put the images, and direct image references to it via the appropriate servlet-mapping in your WEB-INF/web.xml file.  Not sure which methods of the DefaultServlet you'll have to override.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: storing images

Posted by Joseph Morgan <jo...@ignitesales.com>.
Alexis,

We do this exact same thing all the time.  I solve the concurrency on
the image problem by adding a small session hash value to the image
name.  It does mean we may get 10 of the same images if 10 concurrent
access are happening, but it also allows us clean things up without
worry of destroying an image someone is using.

-----Original Message-----
From: alexis [mailto:alzrck@gmail.com] 
Sent: Friday, May 06, 2011 8:38 AM
To: Tomcat Users List
Subject: Re: storing images

Image is built using a jfreechart object, once created it's stored as
attribute in servletcontext, at this stage image is complete before the
set.

What im not sure if setattribute is synchronized, if not i can
synchronize the method that creates and store the image.

Enviado desde blackberry

-----Original Message-----
From: sebb <se...@gmail.com>
Date: Fri, 6 May 2011 14:05:14 
To: Tomcat Users List<us...@tomcat.apache.org>
Reply-To: "Tomcat Users List" <us...@tomcat.apache.org>
Subject: Re: storing images

If multiple threads try to create the image at the same time it is
possible that one thread will see a partial file - or the file may be
locked.

If you are not doing this already, I suggest creating the file with a
unique temporary name and then renaming it once complete.
The rename may fail if another thread has meanwhile created it, but
that can easily be allowed for.

Trying to lock the file whilst it is created is likely to be harder to
implement; however it might be worth it if the file creation is very
expensive in system resources.

On 6 May 2011 13:48, Thad Humphries <th...@gmail.com> wrote:
> I'd store the image to java.io.tmpdir and retrieve it with a servlet.
I
> doing this now with my Ajax application.
>
> On Thu, May 5, 2011 at 2:19 PM, alexis <al...@gmail.com> wrote:
>
>> Hello all, im facing an issue, ive been testing for a while different
>> approaches without success.
>>
>> I have a servlet that basically does
>>
>> . creates an image
>> . store the image on disk
>> . returns an html <img> tag pointing to the stored image.
>>
>> reason why the servlet doesnt returns the image directly using a
response
>> type image/png is the servlet is called from an ajax script, this
ajax
>> script renders the inner text inside a div on a jsp page on the same
context
>> that the server runs. ajax can only render html on divs, there's no
way to
>> return binary content (the image) from the servlet to the ajax
script.
>>
>>
>> So, i have to create the image on the servlet (done) , store the
image on
>> the disk (done), and return the <img> tab also done. Thing is, where
im able
>> to store the image from the servlet im not able to read it from the
jsp.
>>
>> I tried with /tmp, i tried with servletcontext.getpath to store the
file on
>> that dir, nothing seems to work. where should i store and reference
those
>> images to be written by the servlet and read by the jsp?
>>
>> thanks in advance
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>
>
> --
> "Hell hath no limits, nor is circumscrib'd In one self-place; but
where we
> are is hell, And where hell is, there must we ever be" --Christopher
> Marlowe, *Doctor Faustus* (v, 121-24)
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: storing images

Posted by alexis <al...@gmail.com>.
Image is built using a jfreechart object, once created it's stored as attribute in servletcontext, at this stage image is complete before the set.

What im not sure if setattribute is synchronized, if not i can synchronize the method that creates and store the image.

Enviado desde blackberry

-----Original Message-----
From: sebb <se...@gmail.com>
Date: Fri, 6 May 2011 14:05:14 
To: Tomcat Users List<us...@tomcat.apache.org>
Reply-To: "Tomcat Users List" <us...@tomcat.apache.org>
Subject: Re: storing images

If multiple threads try to create the image at the same time it is
possible that one thread will see a partial file - or the file may be
locked.

If you are not doing this already, I suggest creating the file with a
unique temporary name and then renaming it once complete.
The rename may fail if another thread has meanwhile created it, but
that can easily be allowed for.

Trying to lock the file whilst it is created is likely to be harder to
implement; however it might be worth it if the file creation is very
expensive in system resources.

On 6 May 2011 13:48, Thad Humphries <th...@gmail.com> wrote:
> I'd store the image to java.io.tmpdir and retrieve it with a servlet. I
> doing this now with my Ajax application.
>
> On Thu, May 5, 2011 at 2:19 PM, alexis <al...@gmail.com> wrote:
>
>> Hello all, im facing an issue, ive been testing for a while different
>> approaches without success.
>>
>> I have a servlet that basically does
>>
>> . creates an image
>> . store the image on disk
>> . returns an html <img> tag pointing to the stored image.
>>
>> reason why the servlet doesnt returns the image directly using a response
>> type image/png is the servlet is called from an ajax script, this ajax
>> script renders the inner text inside a div on a jsp page on the same context
>> that the server runs. ajax can only render html on divs, there's no way to
>> return binary content (the image) from the servlet to the ajax script.
>>
>>
>> So, i have to create the image on the servlet (done) , store the image on
>> the disk (done), and return the <img> tab also done. Thing is, where im able
>> to store the image from the servlet im not able to read it from the jsp.
>>
>> I tried with /tmp, i tried with servletcontext.getpath to store the file on
>> that dir, nothing seems to work. where should i store and reference those
>> images to be written by the servlet and read by the jsp?
>>
>> thanks in advance
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>
>
> --
> "Hell hath no limits, nor is circumscrib'd In one self-place; but where we
> are is hell, And where hell is, there must we ever be" --Christopher
> Marlowe, *Doctor Faustus* (v, 121-24)
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: storing images

Posted by sebb <se...@gmail.com>.
If multiple threads try to create the image at the same time it is
possible that one thread will see a partial file - or the file may be
locked.

If you are not doing this already, I suggest creating the file with a
unique temporary name and then renaming it once complete.
The rename may fail if another thread has meanwhile created it, but
that can easily be allowed for.

Trying to lock the file whilst it is created is likely to be harder to
implement; however it might be worth it if the file creation is very
expensive in system resources.

On 6 May 2011 13:48, Thad Humphries <th...@gmail.com> wrote:
> I'd store the image to java.io.tmpdir and retrieve it with a servlet. I
> doing this now with my Ajax application.
>
> On Thu, May 5, 2011 at 2:19 PM, alexis <al...@gmail.com> wrote:
>
>> Hello all, im facing an issue, ive been testing for a while different
>> approaches without success.
>>
>> I have a servlet that basically does
>>
>> . creates an image
>> . store the image on disk
>> . returns an html <img> tag pointing to the stored image.
>>
>> reason why the servlet doesnt returns the image directly using a response
>> type image/png is the servlet is called from an ajax script, this ajax
>> script renders the inner text inside a div on a jsp page on the same context
>> that the server runs. ajax can only render html on divs, there's no way to
>> return binary content (the image) from the servlet to the ajax script.
>>
>>
>> So, i have to create the image on the servlet (done) , store the image on
>> the disk (done), and return the <img> tab also done. Thing is, where im able
>> to store the image from the servlet im not able to read it from the jsp.
>>
>> I tried with /tmp, i tried with servletcontext.getpath to store the file on
>> that dir, nothing seems to work. where should i store and reference those
>> images to be written by the servlet and read by the jsp?
>>
>> thanks in advance
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>
>
> --
> "Hell hath no limits, nor is circumscrib'd In one self-place; but where we
> are is hell, And where hell is, there must we ever be" --Christopher
> Marlowe, *Doctor Faustus* (v, 121-24)
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: storing images

Posted by Thad Humphries <th...@gmail.com>.
I'd store the image to java.io.tmpdir and retrieve it with a servlet. I
doing this now with my Ajax application.

On Thu, May 5, 2011 at 2:19 PM, alexis <al...@gmail.com> wrote:

> Hello all, im facing an issue, ive been testing for a while different
> approaches without success.
>
> I have a servlet that basically does
>
> . creates an image
> . store the image on disk
> . returns an html <img> tag pointing to the stored image.
>
> reason why the servlet doesnt returns the image directly using a response
> type image/png is the servlet is called from an ajax script, this ajax
> script renders the inner text inside a div on a jsp page on the same context
> that the server runs. ajax can only render html on divs, there's no way to
> return binary content (the image) from the servlet to the ajax script.
>
>
> So, i have to create the image on the servlet (done) , store the image on
> the disk (done), and return the <img> tab also done. Thing is, where im able
> to store the image from the servlet im not able to read it from the jsp.
>
> I tried with /tmp, i tried with servletcontext.getpath to store the file on
> that dir, nothing seems to work. where should i store and reference those
> images to be written by the servlet and read by the jsp?
>
> thanks in advance
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>


-- 
"Hell hath no limits, nor is circumscrib'd In one self-place; but where we
are is hell, And where hell is, there must we ever be" --Christopher
Marlowe, *Doctor Faustus* (v, 121-24)

Re: storing images

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Alexis,

On 5/6/2011 12:37 PM, alexis wrote:
> small images (never more than 35kB) in a LAN. :)

Martin's comment was, as usual, off-topic and hot terribly helpful.

Martin, use of the JAI doesn't have anything to do with bandwidth unless
you think that compression can only be done using it.

Presumably, Alexis is encoding the images in a standard, web-acceptable
format such as PNG or JPEG (or even GIF) all of which are compressed.
So, that problem has been solved.

This thread is all about image generation and caching.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk3K3nAACgkQ9CaO5/Lv0PDqrwCfUruinn7LjMB6SelBaAi+o/GB
3hIAnjcWJCfzA+c5qDBuKJb9uTwj7Gh1
=gcVz
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: storing images

Posted by alexis <al...@gmail.com>.
small images (never more than 35kB) in a LAN. :)


On May 6, 2011, at 1:12 PM, Martin Gainty wrote:

> 
> depends on available bandwidth as well as the memory available on the client side
> if bandwidth is an issue you may want to implement some manner of compression with jai (Java Advanced Imaging)
> 
> http://download.oracle.com/docs/cd/E17802_01/products/products/java-media/jai/forDevelopers/jai-apidocs/com/sun/media/jai/codec/TIFFEncodeParam.html
> 
> if your app is rendering small pics where clarity is not a requirement you probably will never have an issue
> if your app is rendering large maps then you'll need to look at JAI or implement compression algorithm with another tool.
> Martin 
> ______________________________________________ 
> Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
> 
> Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
> Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.
> 
> 
> 
> 
>> Subject: Re: storing images
>> To: users@tomcat.apache.org
>> From: alzrck@gmail.com
>> Date: Fri, 6 May 2011 14:52:50 +0000
>> 
>> I understand, but i have top 12 images of 35kbytes, no more.
>> 
>> Encoding load is an issue yes, but the images are reflecting callcenters call queues and some stuff related so the need to refresh and rebuild the images is a requirement. What im thinking is to avoid the generation upon servlet calls (servlet only reads and presents the image to callers) and start a different thread with a listener in charge to periodically rebuild images.
>> 
>> Do you believe regarding memory it can cause a big issue? In worst case it's 450kbytes when all images are created and stored.
>> 
>> 
>> Enviado desde blackberry
>> 
>> -----Original Message-----
>> From: Christopher Schultz <ch...@christopherschultz.net>
>> Date: Fri, 06 May 2011 09:48:45 
>> To: Tomcat Users List<us...@tomcat.apache.org>
>> Reply-To: "Tomcat Users List" <us...@tomcat.apache.org>
>> Subject: Re: storing images
>> 
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>> 
>> Alexis,
>> 
>> On 5/5/2011 8:19 PM, alexis wrote:
>>> Im storing the images as servletcontext attribute.
>> 
>> Uh... in memory? That's a bad idea IMO for two reasons:
>> 
>> 1. Large memory requirements
>> 
>> 2. Likely repeated encoding into a file format like JPEG, PNG, etc.
>> 
>> If you store the files on the disk, you can stream them as often as
>> you'd like. If you get a request for an image that already exists, you
>> can serve it up, otherwise, you can create it.
>> 
>> You can even create a hash of lock objects or something so that you can
>> "lock" the file as it's being written so that the file is only written
>> once even if multiple clients are requesting it.
>> 
>> - -chris
>> -----BEGIN PGP SIGNATURE-----
>> Version: GnuPG v1.4.10 (MingW32)
>> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>> 
>> iEYEARECAAYFAk3D/D0ACgkQ9CaO5/Lv0PAYQQCcCy9k9SxH3YSHxekqSzJQKwPz
>> nPAAn3XrYoxXE3E3+FXZ1XfBu3/v9pmW
>> =rQaQ
>> -----END PGP SIGNATURE-----
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>> 
> 		 	   		  


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: storing images

Posted by Martin Gainty <mg...@hotmail.com>.
depends on available bandwidth as well as the memory available on the client side
if bandwidth is an issue you may want to implement some manner of compression with jai (Java Advanced Imaging)

http://download.oracle.com/docs/cd/E17802_01/products/products/java-media/jai/forDevelopers/jai-apidocs/com/sun/media/jai/codec/TIFFEncodeParam.html

if your app is rendering small pics where clarity is not a requirement you probably will never have an issue
if your app is rendering large maps then you'll need to look at JAI or implement compression algorithm with another tool.
Martin 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
 
Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.




> Subject: Re: storing images
> To: users@tomcat.apache.org
> From: alzrck@gmail.com
> Date: Fri, 6 May 2011 14:52:50 +0000
> 
> I understand, but i have top 12 images of 35kbytes, no more.
> 
> Encoding load is an issue yes, but the images are reflecting callcenters call queues and some stuff related so the need to refresh and rebuild the images is a requirement. What im thinking is to avoid the generation upon servlet calls (servlet only reads and presents the image to callers) and start a different thread with a listener in charge to periodically rebuild images.
> 
> Do you believe regarding memory it can cause a big issue? In worst case it's 450kbytes when all images are created and stored.
> 
> 
> Enviado desde blackberry
> 
> -----Original Message-----
> From: Christopher Schultz <ch...@christopherschultz.net>
> Date: Fri, 06 May 2011 09:48:45 
> To: Tomcat Users List<us...@tomcat.apache.org>
> Reply-To: "Tomcat Users List" <us...@tomcat.apache.org>
> Subject: Re: storing images
> 
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Alexis,
> 
> On 5/5/2011 8:19 PM, alexis wrote:
> > Im storing the images as servletcontext attribute.
> 
> Uh... in memory? That's a bad idea IMO for two reasons:
> 
> 1. Large memory requirements
> 
> 2. Likely repeated encoding into a file format like JPEG, PNG, etc.
> 
> If you store the files on the disk, you can stream them as often as
> you'd like. If you get a request for an image that already exists, you
> can serve it up, otherwise, you can create it.
> 
> You can even create a hash of lock objects or something so that you can
> "lock" the file as it's being written so that the file is only written
> once even if multiple clients are requesting it.
> 
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
> 
> iEYEARECAAYFAk3D/D0ACgkQ9CaO5/Lv0PAYQQCcCy9k9SxH3YSHxekqSzJQKwPz
> nPAAn3XrYoxXE3E3+FXZ1XfBu3/v9pmW
> =rQaQ
> -----END PGP SIGNATURE-----
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
 		 	   		  

Re: [OT] storing images

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Alexis,

On 5/13/2011 11:14 AM, alexis wrote:
> upon new data, what i only build new are the series, then i get the
> object on the servletcontext and set the new data inside this object
> (if exists, if not, the whole chart object is created)

That's good to know, though the series is where the bulk of the data is
stored, of course. I'd be interested to see what the overhead of the
JFreeChart object is with no series data.

Also, if you discard the series data anyway when you re-build, are you
really buying yourself anything by keeping the JFreeChart object laying
around?

> On May 13, 2011, at 11:47 AM, Christopher Schultz wrote:
>> Hopefully not "println" as that may corrupt your image and will
>> definitely add an unnecessary trailing newline.
> 
>> So, you re-encode the image every time it's served to a client. I'm
>> suggesting that when you render the JFreeChart, you go all the way to a
>> JPEG (or image format of your choice) and store /that/ in the
>> ServletContext.
> 
> Yes, you're right 1 encoding against n encodings, no matter how 
> small is the cpu save, it's saved n times so it makes the
> difference.
>
> And yes, out.print it is and not out.prinln, changed :)

I would use write(byte[]), but that's just me.

>> What profiler are you using? I use YourKit and it tells me the sizes of
>> object trees fairly easily.
> 
> 
> jvisualvm from the standard jdk. i saw that a heap dump can be done
> and then find what uses the dumped [heap].

You could do that. I've never really used VisualVM so I'm unsure of it's
capabilities.

>> If you store the raw bytes of the JPEG image in memory, they will take
>> up exactly the same size as the file does on disk. So if you look at the
>> image information from your web browser and it says, say, 180k for the
>> image, then that's how much memory it will take when it's sitting in
>> your ServletContext.
> 
> Im modifying it right now and testing.

Cool. Let us know how it goes.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk3NTaIACgkQ9CaO5/Lv0PAhsACgi7XX655a1/4Kof0/hRV4LZvH
NYAAn19mmPWgmWQjmYntH2aEE8C1bVhJ
=dvb7
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: [OT] storing images

Posted by alexis <al...@gmail.com>.
On May 13, 2011, at 11:47 AM, Christopher Schultz wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Alexis,
> 
> Marking off-topic because this has nothing whatsoever to do with Tomcat.
> 
> On 5/11/2011 5:06 PM, alexis wrote:
>> For real time purposes, im building images
> 
> I get it.
> 
>> We'll going to images, what i store in servletcontext is NOT
>> practically the image, as those images are being constructed using
>> jfreechart, what i store in memory is the JFreeChart object  (and
>> inside the JFreeChart object i store some other objects like the
>> dataseries, Custom Labels, etc)
> 
> Ouch. You may be storing much more in memory than necessary. When you
> get new data, do you update the existing JFreeChart object, or do you
> create one from scratch (new series, etc.) each time the image is
> requested /and/ needs to be re-generated?
> 

upon new data, what i only build new are the series, then i get the object on the servletcontext and set the new data inside this object (if exists, if not, the whole chart object is created)



>> after i store this object inside
>> servletcontext, my servet returns out.println("<img
>> src=\"getImage?img=skill1_239423948.png\">"); so the ajax script sets
>> this as innerhtml for a div in the jsp, and the jsp calls getimage
>> servlet requesting the image.
> 
> Okay.
> 
>> What happens here is
>> 
>> 1. _239423948 is a random value that i add to avoid browser caching
>> of the image, so as i receive it, it's discarded
> 
> You could also use a random request parameter value, but there's little
> practical difference.
> 
>> 2. i read the JFreeChart object from the servletcontext regarding skill1
>> 
>> 3. i call a method from the object that is called writeChartAsJPEG
>> (self explaining) , set the response type to image/jpeg and then i do
>> out.println(JFreeChart); which renders the image that is finally shown
>> by the browser.
> 
> Hopefully not "println" as that may corrupt your image and will
> definitely add an unnecessary trailing newline.
> 
> So, you re-encode the image every time it's served to a client. I'm
> suggesting that when you render the JFreeChart, you go all the way to a
> JPEG (or image format of your choice) and store /that/ in the
> ServletContext.

Yes, you're right 1 encoding against n encodings, no matter how small is the cpu save, it's saved n times so it makes the difference.

And yes, out.print it is and not out.prinln, changed :)


> 
>> It's working without any problem, im constantly profiling the webapp
>> to see how it behaves and before/after the image implementation i
>> have noticed no change at all on the memory and cpu usage.
> 
> I think you'll notice that CPU usage is reduced dramatically if you
> aren't re-encoding the image upon every request. Inverse cosine
> transforms aren't free ;)


completely agree, ties to the above note.

> 
>> What i dont know exactly is how much memory uses a JFreeChart object
>> stored in the servletcontext, if there's a way to know it please let me
>> know so i can check it and let you know.
> 
> What profiler are you using? I use YourKit and it tells me the sizes of
> object trees fairly easily.
> 

jvisualvm from the standard jdk. i saw that a heap dump can be done and then find what uses the dumped heat.


> If you store the raw bytes of the JPEG image in memory, they will take
> up exactly the same size as the file does on disk. So if you look at the
> image information from your web browser and it says, say, 180k for the
> image, then that's how much memory it will take when it's sitting in
> your ServletContext.

Im modifying it right now and testing.

thanks again.


> 
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
> 
> iEYEARECAAYFAk3NRJsACgkQ9CaO5/Lv0PCG8wCgqwxiCsRZSQkzHbyirOiJWJD2
> SwoAnj4nOKAEV15cRi7hlb3aMlgB88+n
> =xWLg
> -----END PGP SIGNATURE-----
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: [OT] storing images

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Alexis,

Marking off-topic because this has nothing whatsoever to do with Tomcat.

On 5/11/2011 5:06 PM, alexis wrote:
> For real time purposes, im building images

I get it.

> We'll going to images, what i store in servletcontext is NOT
> practically the image, as those images are being constructed using
> jfreechart, what i store in memory is the JFreeChart object  (and
> inside the JFreeChart object i store some other objects like the
> dataseries, Custom Labels, etc)

Ouch. You may be storing much more in memory than necessary. When you
get new data, do you update the existing JFreeChart object, or do you
create one from scratch (new series, etc.) each time the image is
requested /and/ needs to be re-generated?

> after i store this object inside
> servletcontext, my servet returns out.println("<img
> src=\"getImage?img=skill1_239423948.png\">"); so the ajax script sets
> this as innerhtml for a div in the jsp, and the jsp calls getimage
> servlet requesting the image.

Okay.

> What happens here is
> 
> 1. _239423948 is a random value that i add to avoid browser caching
> of the image, so as i receive it, it's discarded

You could also use a random request parameter value, but there's little
practical difference.

> 2. i read the JFreeChart object from the servletcontext regarding skill1
>
> 3. i call a method from the object that is called writeChartAsJPEG
> (self explaining) , set the response type to image/jpeg and then i do
> out.println(JFreeChart); which renders the image that is finally shown
> by the browser.

Hopefully not "println" as that may corrupt your image and will
definitely add an unnecessary trailing newline.

So, you re-encode the image every time it's served to a client. I'm
suggesting that when you render the JFreeChart, you go all the way to a
JPEG (or image format of your choice) and store /that/ in the
ServletContext.

> It's working without any problem, im constantly profiling the webapp
> to see how it behaves and before/after the image implementation i
> have noticed no change at all on the memory and cpu usage.

I think you'll notice that CPU usage is reduced dramatically if you
aren't re-encoding the image upon every request. Inverse cosine
transforms aren't free ;)

> What i dont know exactly is how much memory uses a JFreeChart object
> stored in the servletcontext, if there's a way to know it please let me
> know so i can check it and let you know.

What profiler are you using? I use YourKit and it tells me the sizes of
object trees fairly easily.

If you store the raw bytes of the JPEG image in memory, they will take
up exactly the same size as the file does on disk. So if you look at the
image information from your web browser and it says, say, 180k for the
image, then that's how much memory it will take when it's sitting in
your ServletContext.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk3NRJsACgkQ9CaO5/Lv0PCG8wCgqwxiCsRZSQkzHbyirOiJWJD2
SwoAnj4nOKAEV15cRi7hlb3aMlgB88+n
=xWLg
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: storing images

Posted by alexis <al...@gmail.com>.
Sorry guys ive been not so clear. here's the deal , ill explain the whole process trying to resume so nobody gets bored reading :)

final images are 400x300px (sometimes png, sometimes jpg) containing pie charts, bar charts, etc. The webapp is constantly connected getting information from a pbx in different call centers and building tables to be displayed by jsp pages for real time reports and storing in a postgres database historical data which is accesed by others jsp.


For real time purposes, im building images, so thinking for example in a "skill" image and having 10 agents in one call center queue, for skill i can have top 10 images (image skill-1 is created first time is requested and stored on servlet context, so if every agent is requested one by one (very rare) will be 10 images stored in memory), if another webapp user requests again skill-1 image, this one will be created again and will overwrite the existing one on the servletcontext, meaning that if 50 webapp users are requesting skill1 image, in memory ill have only 1 image and ill serve the same one to every user. Once the image is re-created, will be served to all users and so on (images are being requested by an ajax script).

so, in the heaviest scenario i can have 40/50 images tops if all are were requested and that has a tiny chance to occur.

We'll going to images, what i store in servletcontext is NOT practically the image, as those images are being constructed using jfreechart, what i store in memory is the JFreeChart object  (and inside the JFreeChart object i store some other objects like the dataseries, Custom Labels, etc), after i store this object inside servletcontext, my servet returns out.println("<img src=\"getImage?img=skill1_239423948.png\">"); so the ajax script sets this as innerhtml for a div in the jsp, and the jsp calls getimage servlet requesting the image.

What happens here is

1. _239423948 is a random value that i add to avoid browser caching of the image, so as i receive it, it's discarded
2. i read the JFreeChart object from the servletcontext regarding skill1
3. i call a method from the object that is called writeChartAsJPEG (self explaining) , set the response type to image/jpeg and then i do out.println(JFreeChart); which renders the image that is finally shown by the browser.

It's working without any problem, im constantly profiling the webapp to see how it behaves and before/after the image implementation i have noticed no change at all on the memory and cpu usage.

What i dont know exactly is how much memory uses a JFreeChart object stored in the servletcontext, if there's a way to know it please let me know so i can check it and let you know.

Thanks again, sorry by the length of this message.


On May 11, 2011, at 4:05 PM, Christopher Schultz wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Alexis,
> 
> On 5/6/2011 10:52 AM, alexis wrote:
>> I understand, but i have top 12 images of 35kbytes, no more.
> 
> Fair enough.
> 
>> Encoding load is an issue yes, but the images are reflecting
>> callcenters call queues and some stuff related so the need to refresh
>> and rebuild the images is a requirement.
> 
> You might consider going all the way down to the byte-level encoding and
> store the raw bytes of the JPEG or PNG that you want to use. You didn't
> say what you were doing, but it's certainly possible to store a
> java.awt.Image in memory and re-encode it for every request. You may as
> well encode it once and serve the bytes directly with those requests.
> 
>> What im thinking is to avoid the generation upon servlet calls
>> (servlet only reads and presents the image to callers) and start a
>> different thread with a listener in charge to periodically rebuild
>> images.
> 
> I think you're better-off doing lazy up-to-date checking, but that's
> just me... it depends on what your requirements truly are. I always hate
> having background threads running in a webapp.
> 
>> Do you believe regarding memory it can cause a big issue? In worst
>> case it's 450kbytes when all images are created and stored.
> 
> Just be sure to test your caching algorithm and make sure the purge is
> working you expect. Image data can take up memory in a hurry if you have
> a bug in there.
> 
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
> 
> iEYEARECAAYFAk3K3fkACgkQ9CaO5/Lv0PB81gCdE84v3o2RhjwQo+EL1cT5pHBY
> 1PUAoLAulZdm+nlzKsRfPFdWKjPRK/R9
> =b465
> -----END PGP SIGNATURE-----
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: storing images

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Alexis,

On 5/6/2011 10:52 AM, alexis wrote:
> I understand, but i have top 12 images of 35kbytes, no more.

Fair enough.

> Encoding load is an issue yes, but the images are reflecting
> callcenters call queues and some stuff related so the need to refresh
> and rebuild the images is a requirement.

You might consider going all the way down to the byte-level encoding and
store the raw bytes of the JPEG or PNG that you want to use. You didn't
say what you were doing, but it's certainly possible to store a
java.awt.Image in memory and re-encode it for every request. You may as
well encode it once and serve the bytes directly with those requests.

> What im thinking is to avoid the generation upon servlet calls
> (servlet only reads and presents the image to callers) and start a
> different thread with a listener in charge to periodically rebuild
> images.

I think you're better-off doing lazy up-to-date checking, but that's
just me... it depends on what your requirements truly are. I always hate
having background threads running in a webapp.

> Do you believe regarding memory it can cause a big issue? In worst
> case it's 450kbytes when all images are created and stored.

Just be sure to test your caching algorithm and make sure the purge is
working you expect. Image data can take up memory in a hurry if you have
a bug in there.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk3K3fkACgkQ9CaO5/Lv0PB81gCdE84v3o2RhjwQo+EL1cT5pHBY
1PUAoLAulZdm+nlzKsRfPFdWKjPRK/R9
=b465
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: storing images

Posted by alexis <al...@gmail.com>.
I understand, but i have top 12 images of 35kbytes, no more.

Encoding load is an issue yes, but the images are reflecting callcenters call queues and some stuff related so the need to refresh and rebuild the images is a requirement. What im thinking is to avoid the generation upon servlet calls (servlet only reads and presents the image to callers) and start a different thread with a listener in charge to periodically rebuild images.

Do you believe regarding memory it can cause a big issue? In worst case it's 450kbytes when all images are created and stored.


Enviado desde blackberry

-----Original Message-----
From: Christopher Schultz <ch...@christopherschultz.net>
Date: Fri, 06 May 2011 09:48:45 
To: Tomcat Users List<us...@tomcat.apache.org>
Reply-To: "Tomcat Users List" <us...@tomcat.apache.org>
Subject: Re: storing images

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Alexis,

On 5/5/2011 8:19 PM, alexis wrote:
> Im storing the images as servletcontext attribute.

Uh... in memory? That's a bad idea IMO for two reasons:

1. Large memory requirements

2. Likely repeated encoding into a file format like JPEG, PNG, etc.

If you store the files on the disk, you can stream them as often as
you'd like. If you get a request for an image that already exists, you
can serve it up, otherwise, you can create it.

You can even create a hash of lock objects or something so that you can
"lock" the file as it's being written so that the file is only written
once even if multiple clients are requesting it.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk3D/D0ACgkQ9CaO5/Lv0PAYQQCcCy9k9SxH3YSHxekqSzJQKwPz
nPAAn3XrYoxXE3E3+FXZ1XfBu3/v9pmW
=rQaQ
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: storing images

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Alexis,

On 5/5/2011 8:19 PM, alexis wrote:
> Im storing the images as servletcontext attribute.

Uh... in memory? That's a bad idea IMO for two reasons:

1. Large memory requirements

2. Likely repeated encoding into a file format like JPEG, PNG, etc.

If you store the files on the disk, you can stream them as often as
you'd like. If you get a request for an image that already exists, you
can serve it up, otherwise, you can create it.

You can even create a hash of lock objects or something so that you can
"lock" the file as it's being written so that the file is only written
once even if multiple clients are requesting it.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk3D/D0ACgkQ9CaO5/Lv0PAYQQCcCy9k9SxH3YSHxekqSzJQKwPz
nPAAn3XrYoxXE3E3+FXZ1XfBu3/v9pmW
=rQaQ
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: storing images

Posted by Martin Gainty <mg...@hotmail.com>.
yes session variables would be specific to user's session
servlet-context and params are available to any requestor who accesses the servlet

Martin Gainty 
______________________________________________ 
Jogi és Bizalmassági kinyilatkoztatás/Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
 Ez az
üzenet bizalmas.  Ha nem ön az akinek szánva volt, akkor kérjük, hogy
jelentse azt nekünk vissza. Semmiféle továbbítása vagy másolatának
készítése nem megengedett.  Ez az üzenet csak ismeret cserét szolgál és
semmiféle jogi alkalmazhatósága sincs.  Mivel az electronikus üzenetek
könnyen megváltoztathatóak, ezért minket semmi felelöség nem terhelhet
ezen üzenet tartalma miatt.

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.




> Subject: Re: storing images
> To: users@tomcat.apache.org
> From: alzrck@gmail.com
> Date: Fri, 6 May 2011 01:32:40 +0000
> 
> Yes for the ajax.
> 
> If im getting it well, i have no need to tie the user with an image instance. image1 is the same for every users.
> 
> Isnt servletcontext shared within the webapp? Meaning that every session access the same servletcontext?
> 
> Regards
> 
> Enviado desde blackberry
> 
> -----Original Message-----
> From: Martin Gainty <mg...@hotmail.com>
> Date: Thu, 5 May 2011 21:26:12 
> To: Tomcat Users List<us...@tomcat.apache.org>
> Reply-To: "Tomcat Users List" <us...@tomcat.apache.org>
> Subject: RE: storing images
> 
> 
> achieved if you correspond the userid-imageid parameter with the acquired image identifier e.g.
> ?code=1.1 puts user1 image 1 on servlet and returns <img src=servlet?get=1.1>
>  ?code=1.2 puts user1 image 2 on servlet and returns <img src=servlet?get=1.2>
>  ?code=2.1 puts user2 image 1 on servlet and returns <img src=servlet?get=2.1>
> 
> are you using XMLHTTPRequest for ajax ?
> Martin Gainty 
> ______________________________________________ 
> Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
>  Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
> Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.
> 
> 
> 
> 
> > Subject: Re: storing images
> > To: users@tomcat.apache.org
> > From: alzrck@gmail.com
> > Date: Fri, 6 May 2011 00:19:06 +0000
> > 
> > What i did (im testing and profiling it) is.
> > 
> > As the images are around 10/12 and each image has around 30 to 35k.
> > 
> > Im storing the images as servletcontext attribute.
> > 
> > So calling to the servlet with ?code=1 builds and stores image1 on servlet context. And returns html with 
> <img src=servlet?get=1>
> > 
> > So ajax sends that to the jsp that calls servlet?get and that returns the image.
> > 
> > It's working now, what im profiling is to verify no matter how many users are requesting images, image1 is the same for every user and if one user builds up the image again, all others gets the new one.
> > 
> > As those images are stored on servletcontext, all are shared among the webapp so images are not duplicated or triplicated or n-cated.
> > 
> > I dont know if it's a good solution, but up to know it's working and really fast.
> > 
> > 
> > Regards
> > 
> > 
> > Enviado desde blackberry
> > 
> > -----Original Message-----
> > From: Christopher Schultz <ch...@christopherschultz.net>
> > Date: Thu, 05 May 2011 20:00:57 
> > To: Tomcat Users List<us...@tomcat.apache.org>
> > Reply-To: "Tomcat Users List" <us...@tomcat.apache.org>
> > Subject: Re: storing images
> > 
> > -----BEGIN PGP SIGNED MESSAGE-----
> > Hash: SHA1
> > 
> > Alexis,
> > 
> > On 5/5/2011 2:19 PM, alexis wrote:
> > > I have a servlet that basically does
> > > 
> > > . creates an image
> > > . store the image on disk
> > > . returns an html <img> tag pointing to the stored image.
> > > 
> > > there's no way to return binary content (the image) from the servlet to the ajax script.
> > 
> > What about JSON? Not that I think it's a terribly good idea, but it's
> > just a thought.
> > 
> > Another thought is possibly using a database, relational or otherwise,
> > rather than the file system. Of course, you'd have to write your own
> > servlet to access the image from the database instead of the filesystem,
> > so I'm not sure it buys you much over the other solutions presented already.
> > 
> > - -chris
> > -----BEGIN PGP SIGNATURE-----
> > Version: GnuPG v1.4.10 (MingW32)
> > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
> > 
> > iEYEARECAAYFAk3DOjkACgkQ9CaO5/Lv0PDzmgCeK2tN3eH+aVY6ElmFiKRe+cj7
> > WZcAn0Yj9qSklAynFdBeyRsL/wl0TpWD
> > =41U2
> > -----END PGP SIGNATURE-----
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail: users-help@tomcat.apache.org
> > 
>  		 	   		  
 		 	   		  

Re: storing images

Posted by alexis <al...@gmail.com>.
Yes for the ajax.

If im getting it well, i have no need to tie the user with an image instance. image1 is the same for every users.

Isnt servletcontext shared within the webapp? Meaning that every session access the same servletcontext?

Regards

Enviado desde blackberry

-----Original Message-----
From: Martin Gainty <mg...@hotmail.com>
Date: Thu, 5 May 2011 21:26:12 
To: Tomcat Users List<us...@tomcat.apache.org>
Reply-To: "Tomcat Users List" <us...@tomcat.apache.org>
Subject: RE: storing images


achieved if you correspond the userid-imageid parameter with the acquired image identifier e.g.
?code=1.1 puts user1 image 1 on servlet and returns <img src=servlet?get=1.1>
 ?code=1.2 puts user1 image 2 on servlet and returns <img src=servlet?get=1.2>
 ?code=2.1 puts user2 image 1 on servlet and returns <img src=servlet?get=2.1>

are you using XMLHTTPRequest for ajax ?
Martin Gainty 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
 Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.




> Subject: Re: storing images
> To: users@tomcat.apache.org
> From: alzrck@gmail.com
> Date: Fri, 6 May 2011 00:19:06 +0000
> 
> What i did (im testing and profiling it) is.
> 
> As the images are around 10/12 and each image has around 30 to 35k.
> 
> Im storing the images as servletcontext attribute.
> 
> So calling to the servlet with ?code=1 builds and stores image1 on servlet context. And returns html with 
<img src=servlet?get=1>
> 
> So ajax sends that to the jsp that calls servlet?get and that returns the image.
> 
> It's working now, what im profiling is to verify no matter how many users are requesting images, image1 is the same for every user and if one user builds up the image again, all others gets the new one.
> 
> As those images are stored on servletcontext, all are shared among the webapp so images are not duplicated or triplicated or n-cated.
> 
> I dont know if it's a good solution, but up to know it's working and really fast.
> 
> 
> Regards
> 
> 
> Enviado desde blackberry
> 
> -----Original Message-----
> From: Christopher Schultz <ch...@christopherschultz.net>
> Date: Thu, 05 May 2011 20:00:57 
> To: Tomcat Users List<us...@tomcat.apache.org>
> Reply-To: "Tomcat Users List" <us...@tomcat.apache.org>
> Subject: Re: storing images
> 
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Alexis,
> 
> On 5/5/2011 2:19 PM, alexis wrote:
> > I have a servlet that basically does
> > 
> > . creates an image
> > . store the image on disk
> > . returns an html <img> tag pointing to the stored image.
> > 
> > there's no way to return binary content (the image) from the servlet to the ajax script.
> 
> What about JSON? Not that I think it's a terribly good idea, but it's
> just a thought.
> 
> Another thought is possibly using a database, relational or otherwise,
> rather than the file system. Of course, you'd have to write your own
> servlet to access the image from the database instead of the filesystem,
> so I'm not sure it buys you much over the other solutions presented already.
> 
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
> 
> iEYEARECAAYFAk3DOjkACgkQ9CaO5/Lv0PDzmgCeK2tN3eH+aVY6ElmFiKRe+cj7
> WZcAn0Yj9qSklAynFdBeyRsL/wl0TpWD
> =41U2
> -----END PGP SIGNATURE-----
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
 		 	   		  

RE: storing images

Posted by Martin Gainty <mg...@hotmail.com>.
achieved if you correspond the userid-imageid parameter with the acquired image identifier e.g.
?code=1.1 puts user1 image 1 on servlet and returns <img src=servlet?get=1.1>
 ?code=1.2 puts user1 image 2 on servlet and returns <img src=servlet?get=1.2>
 ?code=2.1 puts user2 image 1 on servlet and returns <img src=servlet?get=2.1>

are you using XMLHTTPRequest for ajax ?
Martin Gainty 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
 Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.




> Subject: Re: storing images
> To: users@tomcat.apache.org
> From: alzrck@gmail.com
> Date: Fri, 6 May 2011 00:19:06 +0000
> 
> What i did (im testing and profiling it) is.
> 
> As the images are around 10/12 and each image has around 30 to 35k.
> 
> Im storing the images as servletcontext attribute.
> 
> So calling to the servlet with ?code=1 builds and stores image1 on servlet context. And returns html with 
<img src=servlet?get=1>
> 
> So ajax sends that to the jsp that calls servlet?get and that returns the image.
> 
> It's working now, what im profiling is to verify no matter how many users are requesting images, image1 is the same for every user and if one user builds up the image again, all others gets the new one.
> 
> As those images are stored on servletcontext, all are shared among the webapp so images are not duplicated or triplicated or n-cated.
> 
> I dont know if it's a good solution, but up to know it's working and really fast.
> 
> 
> Regards
> 
> 
> Enviado desde blackberry
> 
> -----Original Message-----
> From: Christopher Schultz <ch...@christopherschultz.net>
> Date: Thu, 05 May 2011 20:00:57 
> To: Tomcat Users List<us...@tomcat.apache.org>
> Reply-To: "Tomcat Users List" <us...@tomcat.apache.org>
> Subject: Re: storing images
> 
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Alexis,
> 
> On 5/5/2011 2:19 PM, alexis wrote:
> > I have a servlet that basically does
> > 
> > . creates an image
> > . store the image on disk
> > . returns an html <img> tag pointing to the stored image.
> > 
> > there's no way to return binary content (the image) from the servlet to the ajax script.
> 
> What about JSON? Not that I think it's a terribly good idea, but it's
> just a thought.
> 
> Another thought is possibly using a database, relational or otherwise,
> rather than the file system. Of course, you'd have to write your own
> servlet to access the image from the database instead of the filesystem,
> so I'm not sure it buys you much over the other solutions presented already.
> 
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
> 
> iEYEARECAAYFAk3DOjkACgkQ9CaO5/Lv0PDzmgCeK2tN3eH+aVY6ElmFiKRe+cj7
> WZcAn0Yj9qSklAynFdBeyRsL/wl0TpWD
> =41U2
> -----END PGP SIGNATURE-----
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
 		 	   		  

Re: storing images

Posted by alexis <al...@gmail.com>.
It's ok, theres no need to keep or persist images on reloads/restart/reboots.

Since images are graphs generates with jfreechart on measurements done live by the same webapp.
So, upon reboot if the getattribute from servletcontext requesting an image returns null, i return a message from the servlet 'building image'

Since the same call forces an image rebuild and the request is from ajax with a setinterval, on next request will be an image available.
Worst scenario is no image for 5 seconds and thats acceptable for the webapp.



Enviado desde blackberry

-----Original Message-----
From: Mark Thomas <ma...@apache.org>
Date: Fri, 06 May 2011 09:09:55 
To: Tomcat Users List<us...@tomcat.apache.org>
Reply-To: "Tomcat Users List" <us...@tomcat.apache.org>
Subject: Re: storing images

On 06/05/2011 01:19, alexis wrote:
> What i did (im testing and profiling it) is.
> 
> As the images are around 10/12 and each image has around 30 to 35k.
> 
> Im storing the images as servletcontext attribute.
> 
> So calling to the servlet with ?code=1 builds and stores image1 on servlet context. And returns html with <img src=servlet?get=1>
> 
> So ajax sends that to the jsp that calls servlet?get and that returns the image.
> 
> It's working now, what im profiling is to verify no matter how many users are requesting images, image1 is the same for every user and if one user builds up the image again, all others gets the new one.
> 
> As those images are stored on servletcontext, all are shared among the webapp so images are not duplicated or triplicated or n-cated.
> 
> I dont know if it's a good solution, but up to know it's working and really fast.

In short you are trading memory for speed. If you have the memory and
need/want the speed then that is a good approach.

A couple of things to think about:
- What happens when the app is reloaded? Do you want to cache the
generated images?
- Do you want to pre-generate these images on application start?

Mark



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: storing images

Posted by alexis <al...@gmail.com>.
Another consideration is that the webapp, has limited users quantity, tops 25 (upon request of the customer) i made a test last night with a load generator and i sent 300 users with 5 requests per second during 30 minutes and it worked without any problem.

Enviado desde blackberry

-----Original Message-----
From: Mark Thomas <ma...@apache.org>
Date: Fri, 06 May 2011 09:09:55 
To: Tomcat Users List<us...@tomcat.apache.org>
Reply-To: "Tomcat Users List" <us...@tomcat.apache.org>
Subject: Re: storing images

On 06/05/2011 01:19, alexis wrote:
> What i did (im testing and profiling it) is.
> 
> As the images are around 10/12 and each image has around 30 to 35k.
> 
> Im storing the images as servletcontext attribute.
> 
> So calling to the servlet with ?code=1 builds and stores image1 on servlet context. And returns html with <img src=servlet?get=1>
> 
> So ajax sends that to the jsp that calls servlet?get and that returns the image.
> 
> It's working now, what im profiling is to verify no matter how many users are requesting images, image1 is the same for every user and if one user builds up the image again, all others gets the new one.
> 
> As those images are stored on servletcontext, all are shared among the webapp so images are not duplicated or triplicated or n-cated.
> 
> I dont know if it's a good solution, but up to know it's working and really fast.

In short you are trading memory for speed. If you have the memory and
need/want the speed then that is a good approach.

A couple of things to think about:
- What happens when the app is reloaded? Do you want to cache the
generated images?
- Do you want to pre-generate these images on application start?

Mark



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: storing images

Posted by Mark Thomas <ma...@apache.org>.
On 06/05/2011 01:19, alexis wrote:
> What i did (im testing and profiling it) is.
> 
> As the images are around 10/12 and each image has around 30 to 35k.
> 
> Im storing the images as servletcontext attribute.
> 
> So calling to the servlet with ?code=1 builds and stores image1 on servlet context. And returns html with <img src=servlet?get=1>
> 
> So ajax sends that to the jsp that calls servlet?get and that returns the image.
> 
> It's working now, what im profiling is to verify no matter how many users are requesting images, image1 is the same for every user and if one user builds up the image again, all others gets the new one.
> 
> As those images are stored on servletcontext, all are shared among the webapp so images are not duplicated or triplicated or n-cated.
> 
> I dont know if it's a good solution, but up to know it's working and really fast.

In short you are trading memory for speed. If you have the memory and
need/want the speed then that is a good approach.

A couple of things to think about:
- What happens when the app is reloaded? Do you want to cache the
generated images?
- Do you want to pre-generate these images on application start?

Mark



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: storing images

Posted by alexis <al...@gmail.com>.
What i did (im testing and profiling it) is.

As the images are around 10/12 and each image has around 30 to 35k.

Im storing the images as servletcontext attribute.

So calling to the servlet with ?code=1 builds and stores image1 on servlet context. And returns html with <img src=servlet?get=1>

So ajax sends that to the jsp that calls servlet?get and that returns the image.

It's working now, what im profiling is to verify no matter how many users are requesting images, image1 is the same for every user and if one user builds up the image again, all others gets the new one.

As those images are stored on servletcontext, all are shared among the webapp so images are not duplicated or triplicated or n-cated.

I dont know if it's a good solution, but up to know it's working and really fast.


Regards


Enviado desde blackberry

-----Original Message-----
From: Christopher Schultz <ch...@christopherschultz.net>
Date: Thu, 05 May 2011 20:00:57 
To: Tomcat Users List<us...@tomcat.apache.org>
Reply-To: "Tomcat Users List" <us...@tomcat.apache.org>
Subject: Re: storing images

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Alexis,

On 5/5/2011 2:19 PM, alexis wrote:
> I have a servlet that basically does
> 
> . creates an image
> . store the image on disk
> . returns an html <img> tag pointing to the stored image.
> 
> there's no way to return binary content (the image) from the servlet to the ajax script.

What about JSON? Not that I think it's a terribly good idea, but it's
just a thought.

Another thought is possibly using a database, relational or otherwise,
rather than the file system. Of course, you'd have to write your own
servlet to access the image from the database instead of the filesystem,
so I'm not sure it buys you much over the other solutions presented already.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk3DOjkACgkQ9CaO5/Lv0PDzmgCeK2tN3eH+aVY6ElmFiKRe+cj7
WZcAn0Yj9qSklAynFdBeyRsL/wl0TpWD
=41U2
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: storing images

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Alexis,

On 5/5/2011 2:19 PM, alexis wrote:
> I have a servlet that basically does
> 
> . creates an image
> . store the image on disk
> . returns an html <img> tag pointing to the stored image.
> 
> there's no way to return binary content (the image) from the servlet to the ajax script.

What about JSON? Not that I think it's a terribly good idea, but it's
just a thought.

Another thought is possibly using a database, relational or otherwise,
rather than the file system. Of course, you'd have to write your own
servlet to access the image from the database instead of the filesystem,
so I'm not sure it buys you much over the other solutions presented already.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk3DOjkACgkQ9CaO5/Lv0PDzmgCeK2tN3eH+aVY6ElmFiKRe+cj7
WZcAn0Yj9qSklAynFdBeyRsL/wl0TpWD
=41U2
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org