Subject | Re: [Firebird-Java] Blob Performance hints? |
---|---|
Author | William L. Thomson Jr. |
Post date | 2003-05-08T18:51:08Z |
Rick,
On Thu, 2003-05-08 at 14:23, Rick Fincher wrote:
> Hi All,
>
> I'm working on a servlet that stores and reads blobs from Firebird using
> Jaybird. All is working OK, except the speed of retrieving the blobs seems
> very slow compared to a write.
>
> Anybody have any hints on how to improve performance?
Yes, make sure the blob segment size in the db is larger than the
largest blob if possible. I noticed a slight difference in performance
when I did that.
However you can easily have blobs larger than the largest segment size.
> Should Iincrease the initial size of the byte array and/or match it to
> multiples of the block size of the blob's database?
? I am not sure why you are going this route?
> I'm using getBinaryStream to get the blob stream from the result set.
>
> java.io.InputStream in = rs.getBinaryStream("BINARYFILE");
Any reason why? I would try using rs.getString and see if you notice a
performance diff.
Here is a snippet from one of my servlets that retrieves images stored
in blobs.
//ServletOutputStream sos = response.getOutputStream();
PrintWriter print_writer = response.getWriter();
response.setContentLength(result_set.getString(1).length());
if(result_set.getString("FILE_NAME").indexOf("jpg")!=-1) response.setContentType("image/jpeg");
else if(result_set.getString("FILE_NAME").indexOf("jpeg")!=-1) response.setContentType("image/jpeg");
else if(result_set.getString("FILE_NAME").indexOf("png")!=-1) response.setContentType("image/png");
else if(result_set.getString("FILE_NAME").indexOf("gif")!=-1) response.setContentType("image/gif");
//sos.print(result_set.getString(1));
//sos.close();
print_writer.print(result_set.getString(1));
print_writer.close();
I played around with the ServletOutputStream, but saw no difference in
performance. I think it was slower? Not sure on that one, so I stuck
with what I knew instead of what was suggested.
Now if you go to my site under portfolio you will notice it takes
forever for my pics to be extracted and displayed. This is due to me
needing to backup and restore my DB.
For some reason I have notice speed improvements after several blob
inserts to restore the db from a backup.
Now this is sort of an anomaly on my site. Since I have the same picture
servlet, and set up on another site that the pictures are extracted in a
matter of milliseconds.
http://www.elvisplace.com
All data and images on both sites are in a Firebird DB using Jaybird
1.0. The db for Elvis' Place is 10 times the size of my db, has
thousands of pics, where I only have like 20. Yet mine take a while, and
the others do not.
So there are a few things for you to look into. Hopefully you are not up
against an anomaly like I am on my site.
I will be restoring my db soon, when I upgrade the OS on my db server.
That made a difference last time, although I think I may be using a copy
of the db that was not restored, just transferred.
Anyway hope that helps out.
--
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