Subject | Blob Performance hints? |
---|---|
Author | Rick Fincher |
Post date | 2003-05-08T18:23:23Z |
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?
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'm using getBinaryStream to get the blob stream from the result set.
java.io.InputStream in = rs.getBinaryStream("BINARYFILE");
Thanks for any hints!
The code that does the reading is as follows:
try
{
pStatement = conn.prepareStatement(qStr);
rs = pStatement.executeQuery();
boolean rsEmpty = rs.next();
response.setContentType(rs.getString("MIMETYPE"));
javax.servlet.ServletOutputStream out =
response.getOutputStream();
java.io.InputStream in = rs.getBinaryStream("BINARYFILE");
java.io.ByteArrayOutputStream baos = new
java.io.ByteArrayOutputStream();
int bytes;
byte b[] = new byte[1024];
while (true)
{
bytes = in.read(b);
if (bytes == -1)
{
break;
}
baos.write(b, 0, bytes);
}
b = baos.toByteArray();
response.setContentLength(b.length);
out.write(b, 0, b.length);
out.flush();
out.close();
}
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?
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'm using getBinaryStream to get the blob stream from the result set.
java.io.InputStream in = rs.getBinaryStream("BINARYFILE");
Thanks for any hints!
The code that does the reading is as follows:
try
{
pStatement = conn.prepareStatement(qStr);
rs = pStatement.executeQuery();
boolean rsEmpty = rs.next();
response.setContentType(rs.getString("MIMETYPE"));
javax.servlet.ServletOutputStream out =
response.getOutputStream();
java.io.InputStream in = rs.getBinaryStream("BINARYFILE");
java.io.ByteArrayOutputStream baos = new
java.io.ByteArrayOutputStream();
int bytes;
byte b[] = new byte[1024];
while (true)
{
bytes = in.read(b);
if (bytes == -1)
{
break;
}
baos.write(b, 0, bytes);
}
b = baos.toByteArray();
response.setContentLength(b.length);
out.write(b, 0, b.length);
out.flush();
out.close();
}