pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedTwo minor fixes to reduce resource usage in JDBC drivers
2+ messages / 2 participants
[nested] [flat]
* Two minor fixes to reduce resource usage in JDBC drivers
@ 2000-12-26 20:44 Barry Lind <barry@xythos.com>
2000-12-28 23:56 ` Re: Two minor fixes to reduce resource usage in JDBC drivers Bruce Momjian <pgman@candle.pha.pa.us>
0 siblings, 1 reply; 2+ messages in thread
From: Barry Lind @ 2000-12-26 20:44 UTC (permalink / raw)
To: pgsql-patches@postgresql.org; +Cc: pgsql-interfaces
Attached are patches for two fixes to reduce memory usage by the JDBC
drivers.
The first fix fixes the PreparedStatement object to not allocate
unnecessary objects when converting native types to Stings. The old
code used the following format:
(new Integer(x)).toString()
whereas this can more efficiently be occompilshed by:
Integer.toString(x);
avoiding the unnecessary object creation.
The second fix is to release some resources on the close() of a
ResultSet. Currently the close() method on ResultSet is a noop. The
purpose of the close() method is to release resources when the ResultSet
is no longer needed. The fix is to free the tuples cached by the
ResultSet when it is closed (by clearing out the Vector object that
stores the tuples). This is important for my application, as I have a
cache of Statement objects that I reuse. Since the Statement object
maintains a reference to the ResultSet and the ResultSet kept references
to the old tuples, my cache was holding on to a lot of memory.
thanks,
--Barry
Attachments:
patch.diff (text/plain, 5.2K) download
*** ./org/postgresql/jdbc1/PreparedStatement.java.orig Tue Dec 26 11:50:03 2000
--- ./org/postgresql/jdbc1/PreparedStatement.java Tue Dec 26 11:15:52 2000
***************
*** 164,170 ****
*/
public void setByte(int parameterIndex, byte x) throws SQLException
{
! set(parameterIndex, (new Integer(x)).toString());
}
/**
--- 164,170 ----
*/
public void setByte(int parameterIndex, byte x) throws SQLException
{
! set(parameterIndex, Integer.toString(x));
}
/**
***************
*** 177,183 ****
*/
public void setShort(int parameterIndex, short x) throws SQLException
{
! set(parameterIndex, (new Integer(x)).toString());
}
/**
--- 177,183 ----
*/
public void setShort(int parameterIndex, short x) throws SQLException
{
! set(parameterIndex, Integer.toString(x));
}
/**
***************
*** 190,196 ****
*/
public void setInt(int parameterIndex, int x) throws SQLException
{
! set(parameterIndex, (new Integer(x)).toString());
}
/**
--- 190,196 ----
*/
public void setInt(int parameterIndex, int x) throws SQLException
{
! set(parameterIndex, Integer.toString(x));
}
/**
***************
*** 203,209 ****
*/
public void setLong(int parameterIndex, long x) throws SQLException
{
! set(parameterIndex, (new Long(x)).toString());
}
/**
--- 203,209 ----
*/
public void setLong(int parameterIndex, long x) throws SQLException
{
! set(parameterIndex, Long.toString(x));
}
/**
***************
*** 216,222 ****
*/
public void setFloat(int parameterIndex, float x) throws SQLException
{
! set(parameterIndex, (new Float(x)).toString());
}
/**
--- 216,222 ----
*/
public void setFloat(int parameterIndex, float x) throws SQLException
{
! set(parameterIndex, Float.toString(x));
}
/**
***************
*** 229,235 ****
*/
public void setDouble(int parameterIndex, double x) throws SQLException
{
! set(parameterIndex, (new Double(x)).toString());
}
/**
--- 229,235 ----
*/
public void setDouble(int parameterIndex, double x) throws SQLException
{
! set(parameterIndex, Double.toString(x));
}
/**
*** ./org/postgresql/jdbc1/ResultSet.java.orig Tue Dec 26 11:50:03 2000
--- ./org/postgresql/jdbc1/ResultSet.java Tue Dec 26 11:22:41 2000
***************
*** 127,133 ****
*/
public void close() throws SQLException
{
! // No-op
}
/**
--- 127,134 ----
*/
public void close() throws SQLException
{
! //release resources held (memory for tuples)
! rows.setSize(0);
}
/**
*** ./org/postgresql/jdbc2/PreparedStatement.java.orig Tue Dec 26 11:50:04 2000
--- ./org/postgresql/jdbc2/PreparedStatement.java Tue Dec 26 11:14:33 2000
***************
*** 164,170 ****
*/
public void setByte(int parameterIndex, byte x) throws SQLException
{
! set(parameterIndex, (new Integer(x)).toString());
}
/**
--- 164,170 ----
*/
public void setByte(int parameterIndex, byte x) throws SQLException
{
! set(parameterIndex, Integer.toString(x));
}
/**
***************
*** 177,183 ****
*/
public void setShort(int parameterIndex, short x) throws SQLException
{
! set(parameterIndex, (new Integer(x)).toString());
}
/**
--- 177,183 ----
*/
public void setShort(int parameterIndex, short x) throws SQLException
{
! set(parameterIndex, Integer.toString(x));
}
/**
***************
*** 190,196 ****
*/
public void setInt(int parameterIndex, int x) throws SQLException
{
! set(parameterIndex, (new Integer(x)).toString());
}
/**
--- 190,196 ----
*/
public void setInt(int parameterIndex, int x) throws SQLException
{
! set(parameterIndex, Integer.toString(x));
}
/**
***************
*** 203,209 ****
*/
public void setLong(int parameterIndex, long x) throws SQLException
{
! set(parameterIndex, (new Long(x)).toString());
}
/**
--- 203,209 ----
*/
public void setLong(int parameterIndex, long x) throws SQLException
{
! set(parameterIndex, Long.toString(x));
}
/**
***************
*** 216,222 ****
*/
public void setFloat(int parameterIndex, float x) throws SQLException
{
! set(parameterIndex, (new Float(x)).toString());
}
/**
--- 216,222 ----
*/
public void setFloat(int parameterIndex, float x) throws SQLException
{
! set(parameterIndex, Float.toString(x));
}
/**
***************
*** 229,235 ****
*/
public void setDouble(int parameterIndex, double x) throws SQLException
{
! set(parameterIndex, (new Double(x)).toString());
}
/**
--- 229,235 ----
*/
public void setDouble(int parameterIndex, double x) throws SQLException
{
! set(parameterIndex, Double.toString(x));
}
/**
*** ./org/postgresql/jdbc2/ResultSet.java.orig Tue Dec 26 11:50:04 2000
--- ./org/postgresql/jdbc2/ResultSet.java Tue Dec 26 11:22:46 2000
***************
*** 128,134 ****
*/
public void close() throws SQLException
{
! // No-op
}
/**
--- 128,135 ----
*/
public void close() throws SQLException
{
! //release resources held (memory for tuples)
! rows.setSize(0);
}
/**
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Two minor fixes to reduce resource usage in JDBC drivers
2000-12-26 20:44 Two minor fixes to reduce resource usage in JDBC drivers Barry Lind <barry@xythos.com>
@ 2000-12-28 23:56 ` Bruce Momjian <pgman@candle.pha.pa.us>
0 siblings, 0 replies; 2+ messages in thread
From: Bruce Momjian @ 2000-12-28 23:56 UTC (permalink / raw)
To: Barry Lind <barry@xythos.com>; +Cc: pgsql-patches@postgresql.org; pgsql-interfaces
Thanks. Applied.
---------------------------------------------------------------------------
inline patch 1: ./org/postgresql/jdbc1/PreparedStatement.java, ./org/postgresql/jdbc1/ResultSet.java, ./org/postgresql/jdbc2/PreparedStatement.java and 1 more (+16/-14 lines) download inline-1.patch
*** ./org/postgresql/jdbc1/PreparedStatement.java.orig Tue Dec 26 11:50:03 2000
--- ./org/postgresql/jdbc1/PreparedStatement.java Tue Dec 26 11:15:52 2000
***************
*** 164,170 ****
*/
public void setByte(int parameterIndex, byte x) throws SQLException
{
! set(parameterIndex, (new Integer(x)).toString());
}
/**
--- 164,170 ----
*/
public void setByte(int parameterIndex, byte x) throws SQLException
{
! set(parameterIndex, Integer.toString(x));
}
/**
***************
*** 177,183 ****
*/
public void setShort(int parameterIndex, short x) throws SQLException
{
! set(parameterIndex, (new Integer(x)).toString());
}
/**
--- 177,183 ----
*/
public void setShort(int parameterIndex, short x) throws SQLException
{
! set(parameterIndex, Integer.toString(x));
}
/**
***************
*** 190,196 ****
*/
public void setInt(int parameterIndex, int x) throws SQLException
{
! set(parameterIndex, (new Integer(x)).toString());
}
/**
--- 190,196 ----
*/
public void setInt(int parameterIndex, int x) throws SQLException
{
! set(parameterIndex, Integer.toString(x));
}
/**
***************
*** 203,209 ****
*/
public void setLong(int parameterIndex, long x) throws SQLException
{
! set(parameterIndex, (new Long(x)).toString());
}
/**
--- 203,209 ----
*/
public void setLong(int parameterIndex, long x) throws SQLException
{
! set(parameterIndex, Long.toString(x));
}
/**
***************
*** 216,222 ****
*/
public void setFloat(int parameterIndex, float x) throws SQLException
{
! set(parameterIndex, (new Float(x)).toString());
}
/**
--- 216,222 ----
*/
public void setFloat(int parameterIndex, float x) throws SQLException
{
! set(parameterIndex, Float.toString(x));
}
/**
***************
*** 229,235 ****
*/
public void setDouble(int parameterIndex, double x) throws SQLException
{
! set(parameterIndex, (new Double(x)).toString());
}
/**
--- 229,235 ----
*/
public void setDouble(int parameterIndex, double x) throws SQLException
{
! set(parameterIndex, Double.toString(x));
}
/**
*** ./org/postgresql/jdbc1/ResultSet.java.orig Tue Dec 26 11:50:03 2000
--- ./org/postgresql/jdbc1/ResultSet.java Tue Dec 26 11:22:41 2000
***************
*** 127,133 ****
*/
public void close() throws SQLException
{
! // No-op
}
/**
--- 127,134 ----
*/
public void close() throws SQLException
{
! //release resources held (memory for tuples)
! rows.setSize(0);
}
/**
*** ./org/postgresql/jdbc2/PreparedStatement.java.orig Tue Dec 26 11:50:04 2000
--- ./org/postgresql/jdbc2/PreparedStatement.java Tue Dec 26 11:14:33 2000
***************
*** 164,170 ****
*/
public void setByte(int parameterIndex, byte x) throws SQLException
{
! set(parameterIndex, (new Integer(x)).toString());
}
/**
--- 164,170 ----
*/
public void setByte(int parameterIndex, byte x) throws SQLException
{
! set(parameterIndex, Integer.toString(x));
}
/**
***************
*** 177,183 ****
*/
public void setShort(int parameterIndex, short x) throws SQLException
{
! set(parameterIndex, (new Integer(x)).toString());
}
/**
--- 177,183 ----
*/
public void setShort(int parameterIndex, short x) throws SQLException
{
! set(parameterIndex, Integer.toString(x));
}
/**
***************
*** 190,196 ****
*/
public void setInt(int parameterIndex, int x) throws SQLException
{
! set(parameterIndex, (new Integer(x)).toString());
}
/**
--- 190,196 ----
*/
public void setInt(int parameterIndex, int x) throws SQLException
{
! set(parameterIndex, Integer.toString(x));
}
/**
***************
*** 203,209 ****
*/
public void setLong(int parameterIndex, long x) throws SQLException
{
! set(parameterIndex, (new Long(x)).toString());
}
/**
--- 203,209 ----
*/
public void setLong(int parameterIndex, long x) throws SQLException
{
! set(parameterIndex, Long.toString(x));
}
/**
***************
*** 216,222 ****
*/
public void setFloat(int parameterIndex, float x) throws SQLException
{
! set(parameterIndex, (new Float(x)).toString());
}
/**
--- 216,222 ----
*/
public void setFloat(int parameterIndex, float x) throws SQLException
{
! set(parameterIndex, Float.toString(x));
}
/**
***************
*** 229,235 ****
*/
public void setDouble(int parameterIndex, double x) throws SQLException
{
! set(parameterIndex, (new Double(x)).toString());
}
/**
--- 229,235 ----
*/
public void setDouble(int parameterIndex, double x) throws SQLException
{
! set(parameterIndex, Double.toString(x));
}
/**
*** ./org/postgresql/jdbc2/ResultSet.java.orig Tue Dec 26 11:50:04 2000
--- ./org/postgresql/jdbc2/ResultSet.java Tue Dec 26 11:22:46 2000
***************
*** 128,134 ****
*/
public void close() throws SQLException
{
! // No-op
}
/**
--- 128,135 ----
*/
public void close() throws SQLException
{
! //release resources held (memory for tuples)
! rows.setSize(0);
}
/**
[ Charset UTF-8 unsupported, skipping... ]
[ Charset UTF-8 unsupported, skipping... ]
--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2000-12-28 23:56 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-12-26 20:44 Two minor fixes to reduce resource usage in JDBC drivers Barry Lind <barry@xythos.com>
2000-12-28 23:56 ` Bruce Momjian <pgman@candle.pha.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox