File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes comparision between loading images from servlet vs. from files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "comparision between loading images from servlet vs. from files" Watch "comparision between loading images from servlet vs. from files" New topic
Author

comparision between loading images from servlet vs. from files

Joe Nguyen
Ranch Hand

Joined: Apr 20, 2001
Posts: 161
I have noticed that loading memory image from serlvet are much slower than loading image from files. Theoretically, I think loading memory image must be faster because a) I call the servlet directly. b) I load images that have been cached in memory as byte arrays. On the other hand, loading images from a file as http://localhost:8080/myImage.gif requires to a) redirect my url to servlet. b) search and load myImage.gif file into memory. c) write byte array to response object.
Would you provide some suggestions, comment?
Thanks
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12675
    
    5
What is your server configuration? Is this Tomcat standalone, or what?

Java Resources at www.wbrogden.com
Joe Nguyen
Ranch Hand

Joined: Apr 20, 2001
Posts: 161
William
I am using IBM web sphere.
For memory images:
All images are kept in oracle db and load to servlet context when servlet engine is started. Servlet will set the content type and write the image byte array to the output stream. I have 15 images to display on a single page, so the above servlet will be invoked 15 times simutaneously.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12675
    
    5
I would certainly expect that to be about as fast as reading a static file. There is some overhead with constructing the request and response objects that is not present when serving files directly. How much time difference are we talking about?
You are writing the byte[] with as single write I assume.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: comparision between loading images from servlet vs. from files
 
Similar Threads
images not loading
3.5 -> 4.0
Loading file from server into browser window
How to reference images in Velocity templates
serve static HTML from app context rather than ROOT