Subject Re: [Firebird-Java] Picture Servlet Problems possibly OT
Author William L. Thomson Jr.
Rick,

On Thu, 2003-06-05 at 21:20, Rick Fincher wrote:
> Hi William,
>
> You responded to my question about the performance of blob reads a few weeks
> ago with a code snippet using getByte.

Yes, I have a few of these servlets around, and I grabbed code from a
different one before. Further more I am not sure why on this one I am
using getString()?

> I had similar problems to yours because I was using Win 2000 to develop and
> Linux to deploy.

Well I am usually Linux only. However I had to put a site on a machine
for a kiosk. That machine is a win2k laptop.

> Some of my files were many megabytes so this only uses a small memory
> buffer. If your files are small and you can afford the memory make your
> buffer bigger than your average file and you will get better performance.
> Keep in mind that you have a separate buffer for each simultaneous download,
> so a busy site might chew up a lot of RAM.
>
> That's in the "new byte[2048]" line.

Thanks for the code. I did some test setting the buffer the same size as
the segment size in the db.

I can't seem to see a performance difference between doing what you
suggested or simply using

sos.write(result_set.getBytes(1));

The average time from the above was like 1 milliseconds faster than the code you provide?

Here is the code I was testing

ServletOutputStream sos = response.getOutputStream();
response.setContentType("image/jpeg");
response.setContentLength(result_set.getBytes(1).length);
long start_time = System.currentTimeMillis();
sos.write(result_set.getBytes(1));
System.out.println("Elapsed Time : "+(System.currentTimeMillis()-start_time));
sos.flush();
sos.close();

ServletOutputStream sos = response.getOutputStream();
response.setContentType("image/jpeg");
response.setContentLength(result_set.getBytes(1).length);
long start_time = System.currentTimeMillis();
BufferedInputStream bis = new BufferedInputStream(result_set.getBinaryStream(1));
byte bindata[] = new byte[2048];
int bytesread = 0;
while((bytesread=bis.read(bindata,0,bindata.length))!=-1) {
sos.write(bindata,0,bytesread);
}
bis.close();
System.out.println("Elapsed Time : "+(System.currentTimeMillis()-start_time));
sos.flush();
sos.close();

When the buffer was larger, 32767 the segment size of blobs in the db,
it seems performance degraded. I did not test out any other combinations
between 2048-32767.

> Hope this helps,

Yes, thank you.


--
Sincerely,
William L. Thomson Jr.
Support Group
Obsidian-Studios, Inc.
3548 Jamestown Ln.
Jacksonville, FL 32223
Phone/Fax 904.260.2445
http://www.obsidian-studios.com