From: | Barry Lind <barry(at)xythos(dot)com> |
---|---|
To: | David Wall <dwall(at)Yozons(dot)com> |
Cc: | pgsql-jdbc <pgsql-jdbc(at)postgresql(dot)org> |
Subject: | Re: setBlob loop performance? |
Date: | 2002-08-27 07:54:50 |
Message-ID: | 3D6B304A.1010001@xythos.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
David,
Both of these issues look like bugs to me. Please submit a patch. I
agree that using a 4 or 8k buffer for reading/writing between the
streams is much better than how the code is currently implemented.
Also, setBlob should be calling close on the input stream when it is done.
Is there anything else that can be done to improve this. I have always
found the jdbc spec for Blobs to be limited in the blob creation area.
Is there anything you would like to see in the driver to make this
easier for you?
thanks,
--Barry
David Wall wrote:
>In the 7.2.2 codeset, PreparedStatement.setBlob() shows a loop as it reads a
>byte from the input stream (the blob) and writes it to the output stream
>(PG's LO routines).
>
>This seems highly inefficient since most large objects are, well, large...
>So if I want to insert a 1MB image, this will loop a million times. Is
>there a reason it's not read in chunks (even a 4096 sized array would reduce
>such a loop down to 250 iterations)?
>
>This is much worse than the 7.1 code which simply took my byte array and
>wrote it all to the LargeObject stream in one call.
>
>+++
> public void setBlob(int i, Blob x) throws SQLException
> {
> InputStream l_inStream = x.getBinaryStream();
> int l_length = (int) x.length();
> LargeObjectManager lom = connection.getLargeObjectAPI();
> int oid = lom.create();
> LargeObject lob = lom.open(oid);
> OutputStream los = lob.getOutputStream();
> try
> {
> // could be buffered, but then the OutputStream
>returned by LargeObject
> // is buffered internally anyhow, so there would be
>no performance
> // boost gained, if anything it would be worse!
> int c = l_inStream.read();
> int p = 0;
> while (c > -1 && p < l_length)
> {
> los.write(c);
> c = l_inStream.read();
> p++;
> }
> los.close();
> }
> catch (IOException se)
> {
> throw new PSQLException("postgresql.unusual", se);
> }
> // lob is closed by the stream so don't call lob.close()
> setInt(i, oid);
> }
>
>+++
>
>Since the getBinaryStream() returns an InputStream, should this routine
>close that inputstream once it's done, or does the Blob itself have to
>somehow know that a stream it creates can be closed and discarded (and if
>so, how?)?
>
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 3: if posting/reading through Usenet, please send an appropriate
>subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
>message can get through to the mailing list cleanly
>
>
>
From | Date | Subject | |
---|---|---|---|
Next Message | Warren Massengill | 2002-08-27 10:50:29 | Re: JDK development kit |
Previous Message | Dave Cramer | 2002-08-27 02:51:48 | Re: JDK development kit |