Skip site navigation (1) Skip section navigation (2)

RE: Re: [ADMIN] High memory usage [PATCH]

From: "Rainer Mager" <rmager(at)vgkk(dot)com>
To: "Dave Cramer" <Dave(at)micro-automation(dot)net>, "Bruce Momjian" <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: "PostgreSQL jdbc list" <pgsql-jdbc(at)postgresql(dot)org>
Subject: RE: Re: [ADMIN] High memory usage [PATCH]
Date: 2001-06-22 04:56:17
Message-ID: NEBBJBCAFMMNIHGDLFKGIELIEFAA.rmager@vgkk.com (view raw or flat)
Thread:
Lists: pgsql-adminpgsql-jdbcpgsql-patches
Good questions, I'll answer what I can...

> 1) what is the problem that this is trying to solve, I assume from the
> subject that it is some sort of high memory usage?

Yes it involves memory usage and a memory leak. Basically, the way the code
was before the patch, each instantiation of a PreparedStatement created 2
new ThreadLocal objects. According to Sun's Javadocs, these objects are not
freed until the thread is completed. For a single thread app or main thread
of an application (in our case a server) the thread NEVER goes away.
Therefore these ThreadLocal objects just keep adding up and using memory,
forever.

The patch removes the use of these ThreadLocals.


> 2) I am trying to understand how a statement would ever be used
> by more than
> one thread at a time? I would think that it would be impossible to share
> statements across threads.

This I can't really answer. The code appeared to be written to be thread
safe so I attempted to continue that. Whether thread safe for a Statement is
necessary or not I can't directly say. Although, I agree with you, I can't
imagine a need to use a single Statement in multiple threads.


> 3) The double locking method used is alledgedly unsafe on SMP machines
> http://www.javaworld.com/javaworld/jw-02-2001/jw-0209-double_p.html.

Interesting. I wasn't aware of this. If question #2 is answered such that
thread safe isn't necessary, then this problem goes away pretty easily. If
thread safety is needed then this would have to be rewritten, I can look
into doing this if you like.


> Dave

--Rainer



In response to

Responses

pgsql-admin by date

Next:From: Kostis MentzelosDate: 2001-06-22 08:35:41
Subject: Re: rename a table
Previous:From: Yasuo OhgakiDate: 2001-06-22 02:31:08
Subject: Re: Gradual increase in CPU utilization by postmaster

pgsql-patches by date

Next:From: Marko KreenDate: 2001-06-22 08:52:42
Subject: Re: use GUC for cmdline
Previous:From: Tom LaneDate: 2001-06-22 01:09:20
Subject: Re: use GUC for cmdline

pgsql-jdbc by date

Next:From: Gunnar RønningDate: 2001-06-22 11:42:12
Subject: Re: Re: [ADMIN] High memory usage [PATCH]
Previous:From: Dave CramerDate: 2001-06-22 00:33:59
Subject: Re: Re: [ADMIN] High memory usage [PATCH]

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group