Re: c function: keep objects in memory for all session or all transaction

Lists: pgsql-hackers
From: Christian Gonzalez <christian(dot)gonzalez(at)sigis(dot)com(dot)ve>
To: pgsql-hackers(at)postgresql(dot)org
Subject: c function: keep objects in memory for all session or all transaction
Date: 2009-09-02 15:29:09
Message-ID: 4A9E8F45.2080106@sigis.com.ve
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi everybody,
I am new PostgreSQL c function programmer. I'm trying to move ahead
a new "PostgreSQL routing library" (http://www.pgroute.org [for now, the
page in only in spanish]).

The point:
There is some way to keep objects in [persisten] memory and then refer
to these from c functions?. In the current version of pgRoute, each
transaction load the graph in memory (using MemoryContext), this isn't a
enterprise solution for routing program. Why I Wish is using a c
function to load the graph in memory [persistent], something like:

SELECT pgr_load_graph('my SQL graph sentence', 'graph name');
example: SELECT pgr_load_graph('SELECT id, source, target,
cost1,cost2,costn,... FROM edge_table WHERE ...','My graph');
would also have a function to unload or delete.

and then, use other function to calculating the shortest path, something
like:
SELECT pgr_get_shortest_path('from','to','cost
column','algorithm','graph name');
example: SELECT
pgr_get_shortest_path(6000,5142,'cost1','dijkstra','My graph');

researching in the PostgreSQL source code I found
"postgresql-8.4.0/src/backend/utils/mmgr/README.TXT", and I think the
indicated MemoryContext that I need to solved my problem is
"TopMemoryContext", but I don't found examples of how can I used it.

I need some guidelines, or way to resolved this. Is posible to put
persisten object in memory through postgresql c funtion?, or my idea is
a crazy idea?

Thanks a lot for your time and answers, ahhh! and for my English writing.


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Christian Gonzalez <christian(dot)gonzalez(at)sigis(dot)com(dot)ve>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: c function: keep objects in memory for all session or all transaction
Date: 2009-09-02 18:29:29
Message-ID: 1251916169.30166.1.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On ons, 2009-09-02 at 10:59 -0430, Christian Gonzalez wrote:
> Is posible to put
> persisten object in memory through postgresql c funtion?

Well, the PL/Perl and PL/Python languages do some variants of this using
their GD and SD variables. So it's surely possible in C as well.
Memory contexts are the right keyword, but note that if you use
TopMemoryContext, you are pretty much just using malloc(). Maybe you
want to try prototyping your functionality in PL/Perl or PL/Python to
get it started.


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Christian Gonzalez <christian(dot)gonzalez(at)sigis(dot)com(dot)ve>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: c function: keep objects in memory for all session or all transaction
Date: 2009-09-02 19:13:12
Message-ID: 603c8f070909021213o605fa483w81b1a18787337fee@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Sep 2, 2009 at 11:29 AM, Christian
Gonzalez<christian(dot)gonzalez(at)sigis(dot)com(dot)ve> wrote:
> The point:
> There is some way to keep objects in [persisten] memory and then refer to
> these from c functions?.  In the current version of pgRoute, each
> transaction load the graph in memory (using MemoryContext), this isn't a
> enterprise solution for routing program.  Why I Wish is using a c function
> to load the graph in memory [persistent], something like:

Well note that whatever you allocate in TopMemoryContext (or wherever)
is going to be private to a single backend. If it's shared data, you
probably want to put it in a table, I would think...

...Robert


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Christian Gonzalez <christian(dot)gonzalez(at)sigis(dot)com(dot)ve>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: c function: keep objects in memory for all session or all transaction
Date: 2009-09-02 19:17:23
Message-ID: 4A9EC4C3.8090106@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Peter Eisentraut wrote:
> On ons, 2009-09-02 at 10:59 -0430, Christian Gonzalez wrote:
>
>> Is posible to put
>> persisten object in memory through postgresql c funtion?
>>
>
> Well, the PL/Perl and PL/Python languages do some variants of this using
> their GD and SD variables. So it's surely possible in C as well.
> Memory contexts are the right keyword, but note that if you use
> TopMemoryContext, you are pretty much just using malloc(). Maybe you
> want to try prototyping your functionality in PL/Perl or PL/Python to
> get it started.
>
>

But if you want something visible to all sessions, something like
pg_memcache might be what you need. see
<http://cvs.pgfoundry.org/cgi-bin/cvsweb.cgi/~checkout~/pgmemcache/pgmemcache/README.pgmemcache?rev=1.11>
for some details.

cheers

andrew


From: Christian Gonzalez <christian(dot)gonzalez(at)sigis(dot)com(dot)ve>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: c function: keep objects in memory for all session or all transaction
Date: 2009-09-02 19:37:00
Message-ID: 4A9EC95C.4080108@sigis.com.ve
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Ohh Thanks to all for your answers,
pgmemcache does exactly what I need, or how I need it, that is to
put my graph into a persistent memory for all transactions that have
permissions.

Thanks again,
Christian Gonzalez

El 02/09/09 14:47, Andrew Dunstan escribió:
>
>
> Peter Eisentraut wrote:
>> On ons, 2009-09-02 at 10:59 -0430, Christian Gonzalez wrote:
>>> Is posible to put persisten object in memory through postgresql c
>>> funtion?
>>
>> Well, the PL/Perl and PL/Python languages do some variants of this using
>> their GD and SD variables. So it's surely possible in C as well.
>> Memory contexts are the right keyword, but note that if you use
>> TopMemoryContext, you are pretty much just using malloc(). Maybe you
>> want to try prototyping your functionality in PL/Perl or PL/Python to
>> get it started.
>>
>
>
> But if you want something visible to all sessions, something like
> pg_memcache might be what you need. see
> <http://cvs.pgfoundry.org/cgi-bin/cvsweb.cgi/~checkout~/pgmemcache/pgmemcache/README.pgmemcache?rev=1.11>
> for some details.
>
> cheers
>
> andrew
>