.NET or Mono functions in PG

Lists: pgsql-hackers
From: "Gevik Babakhani" <pgdev(at)xs4all(dot)nl>
To: <pgsql-hackers(at)postgresql(dot)org>
Subject: .NET or Mono functions in PG
Date: 2007-11-30 13:31:44
Message-ID: 001201c83355$59d3ab20$0a01a8c0@gevmus
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


I am investigating the possibility of having stored procedures
and functions written in .NET language flavors. I remember a long time
ago there was a gborg project wanting to implement it, but that is long
gone I guess. anyway....

I think there are two possibilities:

a) Use of MS.NET core and implement it only for Windows.
b) Use of Mono core and have the possibility to run it also on *nix systems.
c) Or perhaps a hybrid of the above would be possible.

Any implementation would require to invoke/call an external runtime (Mono or
MS.CRL).
I wonder what the performance would be.

I would like to have your opinion about this idea.

Regards,
Gevik Babakhani

------------------------------------------------
PostgreSQL NL http://www.postgresql.nl
TrueSoftware BV http://www.truesoftware.nl
------------------------------------------------


From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Gevik Babakhani" <pgdev(at)xs4all(dot)nl>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: .NET or Mono functions in PG
Date: 2007-11-30 14:16:40
Message-ID: 162867790711300616q1366679fo802df2b21963c31@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello

I thought about it. It can be great project. Oracle has similar
project. Performance will be same as PL/Java probably. There is slow
only first call.

Regards
Pavel Stehule

On 30/11/2007, Gevik Babakhani <pgdev(at)xs4all(dot)nl> wrote:
>
> I am investigating the possibility of having stored procedures
> and functions written in .NET language flavors. I remember a long time
> ago there was a gborg project wanting to implement it, but that is long
> gone I guess. anyway....
>
> I think there are two possibilities:
>
> a) Use of MS.NET core and implement it only for Windows.
> b) Use of Mono core and have the possibility to run it also on *nix systems.
> c) Or perhaps a hybrid of the above would be possible.
>
> Any implementation would require to invoke/call an external runtime (Mono or
> MS.CRL).
> I wonder what the performance would be.
>
> I would like to have your opinion about this idea.
>
> Regards,
> Gevik Babakhani
>
> ------------------------------------------------
> PostgreSQL NL http://www.postgresql.nl
> TrueSoftware BV http://www.truesoftware.nl
> ------------------------------------------------
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend
>


From: "Jonah H(dot) Harris" <jonah(dot)harris(at)gmail(dot)com>
To: "Gevik Babakhani" <pgdev(at)xs4all(dot)nl>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: .NET or Mono functions in PG
Date: 2007-11-30 14:20:32
Message-ID: 36e682920711300620q3a655c38x7fab457e6c0cb8b6@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Nov 30, 2007 8:31 AM, Gevik Babakhani <pgdev(at)xs4all(dot)nl> wrote:
> I am investigating the possibility of having stored procedures
> and functions written in .NET language flavors. I remember a long time
> ago there was a gborg project wanting to implement it, but that is long
> gone I guess. anyway....

Yeah, I have a copy of the old PL/.NET backed up somewhere. IIRC, it
needs to be rewritten, but it would be possible to make it work for
both Mono and .NET.

--
Jonah H. Harris, Sr. Software Architect | phone: 732.331.1324
EnterpriseDB Corporation | fax: 732.331.1301
499 Thornall Street, 2nd Floor | jonah(dot)harris(at)enterprisedb(dot)com
Edison, NJ 08837 | http://www.enterprisedb.com/


From: "Jonah H(dot) Harris" <jonah(dot)harris(at)gmail(dot)com>
To: "Gevik Babakhani" <pgdev(at)xs4all(dot)nl>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: .NET or Mono functions in PG
Date: 2007-11-30 15:09:54
Message-ID: 36e682920711300709x3fd21175u8156ab0e1eeb41f3@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Nov 30, 2007 9:20 AM, Jonah H. Harris <jonah(dot)harris(at)gmail(dot)com> wrote:
> Yeah, I have a copy of the old PL/.NET backed up somewhere. IIRC, it
> needs to be rewritten, but it would be possible to make it work for
> both Mono and .NET.

Actually, it was PL/Mono. I'll dig through my stuff and post it
somewhere for you.

--
Jonah H. Harris, Sr. Software Architect | phone: 732.331.1324
EnterpriseDB Corporation | fax: 732.331.1301
499 Thornall Street, 2nd Floor | jonah(dot)harris(at)enterprisedb(dot)com
Edison, NJ 08837 | http://www.enterprisedb.com/


From: "Gevik Babakhani" <pgdev(at)xs4all(dot)nl>
To: "'Jonah H(dot) Harris'" <jonah(dot)harris(at)gmail(dot)com>
Cc: <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: .NET or Mono functions in PG
Date: 2007-11-30 15:11:57
Message-ID: 002701c83363$59b21100$0a01a8c0@gevmus
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

It would we great. Thank you.

Regards,
Gevik Babakhani
------------------------------------------------
PostgreSQL NL http://www.postgresql.nl
TrueSoftware BV http://www.truesoftware.nl
------------------------------------------------

> -----Original Message-----
> From: pgsql-hackers-owner(at)postgresql(dot)org
> [mailto:pgsql-hackers-owner(at)postgresql(dot)org] On Behalf Of
> Jonah H. Harris
> Sent: Friday, November 30, 2007 4:10 PM
> To: Gevik Babakhani
> Cc: pgsql-hackers(at)postgresql(dot)org
> Subject: Re: [HACKERS] .NET or Mono functions in PG
>
> On Nov 30, 2007 9:20 AM, Jonah H. Harris
> <jonah(dot)harris(at)gmail(dot)com> wrote:
> > Yeah, I have a copy of the old PL/.NET backed up somewhere.
> IIRC, it
> > needs to be rewritten, but it would be possible to make it work for
> > both Mono and .NET.
>
> Actually, it was PL/Mono. I'll dig through my stuff and post
> it somewhere for you.
>
> --
> Jonah H. Harris, Sr. Software Architect | phone: 732.331.1324
> EnterpriseDB Corporation | fax: 732.331.1301
> 499 Thornall Street, 2nd Floor |
> jonah(dot)harris(at)enterprisedb(dot)com
> Edison, NJ 08837 | http://www.enterprisedb.com/
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq
>


From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Gevik Babakhani <pgdev(at)xs4all(dot)nl>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: .NET or Mono functions in PG
Date: 2007-11-30 15:19:26
Message-ID: 20071130151926.GB22321@svr2.hagander.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Nov 30, 2007 at 02:31:44PM +0100, Gevik Babakhani wrote:
>
> I am investigating the possibility of having stored procedures
> and functions written in .NET language flavors. I remember a long time
> ago there was a gborg project wanting to implement it, but that is long
> gone I guess. anyway....
>
> I think there are two possibilities:
>
> a) Use of MS.NET core and implement it only for Windows.
> b) Use of Mono core and have the possibility to run it also on *nix systems.
> c) Or perhaps a hybrid of the above would be possible.
>
> Any implementation would require to invoke/call an external runtime (Mono or
> MS.CRL).
> I wonder what the performance would be.
>
> I would like to have your opinion about this idea.

I did look at this at some earlier point as well. One big problem at that
time was that once you embedded mono, yuo had all sorts of threads running
in your backend ;-)

Another way to do it is "the PL/J" way (I think). Which is starting up a
separate process with the VM in it and then do RPC of some kind to it.
Which has more overhead per call, but lower per backend etc. And a lot less
"dangerous".

I never got past the thinking stage though. But it would certanily be nice
to have!

//Magnus


From: "Gevik Babakhani" <pgdev(at)xs4all(dot)nl>
To: "'Magnus Hagander'" <magnus(at)hagander(dot)net>
Cc: <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: .NET or Mono functions in PG
Date: 2007-11-30 15:43:03
Message-ID: 002b01c83367$b1b8b760$0a01a8c0@gevmus
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

> I did look at this at some earlier point as well. One big
> problem at that time was that once you embedded mono, you had
> all sorts of threads running in your backend ;-)

yes, threads running around could become a show stopper for both Mono and
MS.NET
This is something I want to be sure of before I begin.

> Another way to do it is "the PL/J" way (I think). Which is
> starting up a separate process with the VM in it and then do
> RPC of some kind to it.
> Which has more overhead per call, but lower per backend etc.
> And a lot less "dangerous".

This is actually my plan B, hence it is less dangerous.
I am thinking the "started process" can stay alive and act
as a service of some kind to handle/answer calls form multiple
backends and shutdown itself after a period of time being
idle.

Regards,
Gevik Babakhani
------------------------------------------------
PostgreSQL NL http://www.postgresql.nl
TrueSoftware BV http://www.truesoftware.nl
------------------------------------------------


From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Gevik Babakhani <pgdev(at)xs4all(dot)nl>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: .NET or Mono functions in PG
Date: 2007-11-30 15:48:11
Message-ID: 20071130154811.GD22321@svr2.hagander.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Nov 30, 2007 at 04:43:03PM +0100, Gevik Babakhani wrote:
> > I did look at this at some earlier point as well. One big
> > problem at that time was that once you embedded mono, you had
> > all sorts of threads running in your backend ;-)
>
> yes, threads running around could become a show stopper for both Mono and
> MS.NET
> This is something I want to be sure of before I begin.

Yaeh.

> > Another way to do it is "the PL/J" way (I think). Which is
> > starting up a separate process with the VM in it and then do
> > RPC of some kind to it.
> > Which has more overhead per call, but lower per backend etc.
> > And a lot less "dangerous".
>
> This is actually my plan B, hence it is less dangerous.
> I am thinking the "started process" can stay alive and act
> as a service of some kind to handle/answer calls form multiple
> backends and shutdown itself after a period of time being
> idle.

Yes, you should have just one such process with .Net managed threads
running inside it. You just need to find a good RPC library to pass things
back and forth between the backend running natively and this special
process running in .net.

//Magnus


From: "Jonah H(dot) Harris" <jonah(dot)harris(at)gmail(dot)com>
To: "Gevik Babakhani" <pgdev(at)xs4all(dot)nl>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: .NET or Mono functions in PG
Date: 2007-11-30 18:15:04
Message-ID: 36e682920711301015y1808dd2dm9a66e23defde9609@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Nov 30, 2007 10:09 AM, Jonah H. Harris <jonah(dot)harris(at)gmail(dot)com> wrote:
> Actually, it was PL/Mono. I'll dig through my stuff and post it
> somewhere for you.

Just searched my backups and can't seem to find it :( It was on gborg
CVS. Where is that now?

--
Jonah H. Harris, Sr. Software Architect | phone: 732.331.1324
EnterpriseDB Corporation | fax: 732.331.1301
499 Thornall Street, 2nd Floor | jonah(dot)harris(at)enterprisedb(dot)com
Edison, NJ 08837 | http://www.enterprisedb.com/


From: Magnus Hagander <magnus(at)hagander(dot)net>
To: "Jonah H(dot) Harris" <jonah(dot)harris(at)gmail(dot)com>
Cc: Gevik Babakhani <pgdev(at)xs4all(dot)nl>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: .NET or Mono functions in PG
Date: 2007-11-30 18:21:48
Message-ID: 475054BC.5020606@hagander.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Jonah H. Harris wrote:
> On Nov 30, 2007 10:09 AM, Jonah H. Harris <jonah(dot)harris(at)gmail(dot)com> wrote:
>> Actually, it was PL/Mono. I'll dig through my stuff and post it
>> somewhere for you.
>
> Just searched my backups and can't seem to find it :( It was on gborg
> CVS. Where is that now?

Dead.
But Marc has a tarball of the whole thing somewhere and can find it.

//Magnus


From: "Jonah H(dot) Harris" <jonah(dot)harris(at)gmail(dot)com>
To: "Magnus Hagander" <magnus(at)hagander(dot)net>
Cc: "Gevik Babakhani" <pgdev(at)xs4all(dot)nl>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: .NET or Mono functions in PG
Date: 2007-11-30 18:27:05
Message-ID: 36e682920711301027u44176e99g5a1bb2182863fa38@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Nov 30, 2007 1:21 PM, Magnus Hagander <magnus(at)hagander(dot)net> wrote:
> > Just searched my backups and can't seem to find it :( It was on gborg
> > CVS. Where is that now?
>
> Dead.
> But Marc has a tarball of the whole thing somewhere and can find it.

OK, I'll see if I can get a copy of it.

--
Jonah H. Harris, Sr. Software Architect | phone: 732.331.1324
EnterpriseDB Corporation | fax: 732.331.1301
499 Thornall Street, 2nd Floor | jonah(dot)harris(at)enterprisedb(dot)com
Edison, NJ 08837 | http://www.enterprisedb.com/


From: James Mansion <james(at)mansionfamily(dot)plus(dot)com>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: Gevik Babakhani <pgdev(at)xs4all(dot)nl>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: .NET or Mono functions in PG
Date: 2007-12-01 12:09:09
Message-ID: 47514EE5.3090808@mansionfamily.plus.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Magnus Hagander wrote:
> I did look at this at some earlier point as well. One big problem at that
> time was that once you embedded mono, yuo had all sorts of threads running
> in your backend ;-)
>
Is that necessarily a problem? You have to compile with a
thread-capable libc and take some
care that the heap implementation is well tuned, but there's no reason
why the mono housekeeping
threads should cause you any problem is there? It should be much like
the embedded Java.
> Another way to do it is "the PL/J" way (I think). Which is starting up a
> separate process with the VM in it and then do RPC of some kind to it.
> Which has more overhead per call, but lower per backend etc. And a lot less
> "dangerous".
>
>
Given that one would want to embed to have very low latency both on
trigger invocation and
on calls back into the data engine, I don't really see the point personally.

I'm not sure how important it is to make the embeded interface look like
a standard
interface (in that way that the embedded CLR in MSSQL does - mostly) or
whether
it can be a thin wrapper over the C API. I think there's good mileage
in starting
with the thin wrapper, then at least some common business logic code can
be used.

James


From: Magnus Hagander <magnus(at)hagander(dot)net>
To: James Mansion <james(at)mansionfamily(dot)plus(dot)com>
Cc: Gevik Babakhani <pgdev(at)xs4all(dot)nl>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: .NET or Mono functions in PG
Date: 2007-12-01 12:20:38
Message-ID: 47515196.6030203@hagander.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

James Mansion wrote:
> Magnus Hagander wrote:
>> I did look at this at some earlier point as well. One big problem at that
>> time was that once you embedded mono, yuo had all sorts of threads
>> running
>> in your backend ;-)
>>
> Is that necessarily a problem? You have to compile with a
> thread-capable libc and take some
> care that the heap implementation is well tuned, but there's no reason
> why the mono housekeeping
> threads should cause you any problem is there? It should be much like
> the embedded Java.

Depends on what you mean by a problem. It's something you need to think
about, and think hard about, and be sure you deal with. But it can be done.

And yes, the housekeeping threads could be a problem. If you end up with
for example something called on the GC thread calling back out into
"native mode", while the backend is doing something completely different.

And yes, it would be the same as embedding Java. And it has been done
with pl/java, so it can be done :)

An interesting thing could be to look at if code could be "stolen from"
or even better shared with pl/java, if this is the road to go down.

>> Another way to do it is "the PL/J" way (I think). Which is starting up a
>> separate process with the VM in it and then do RPC of some kind to it.
>> Which has more overhead per call, but lower per backend etc. And a lot
>> less
>> "dangerous".
>>
>>
> Given that one would want to embed to have very low latency both on
> trigger invocation and
> on calls back into the data engine, I don't really see the point
> personally.
>
> I'm not sure how important it is to make the embeded interface look like
> a standard
> interface (in that way that the embedded CLR in MSSQL does - mostly) or
> whether
> it can be a thin wrapper over the C API. I think there's good mileage
> in starting
> with the thin wrapper, then at least some common business logic code can
> be used.

Agreed, that'd be a good start. But it would certainly be convenient if
you could have access compatible with the System.Data stuff, since
there's bound to be a lot of code (and coders) that know about that...

//Magnus


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: James Mansion <james(at)mansionfamily(dot)plus(dot)com>, Gevik Babakhani <pgdev(at)xs4all(dot)nl>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: .NET or Mono functions in PG
Date: 2007-12-01 16:23:58
Message-ID: 21030.1196526238@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Magnus Hagander <magnus(at)hagander(dot)net> writes:
> James Mansion wrote:
>> Is that necessarily a problem?
> ...
> And yes, it would be the same as embedding Java. And it has been done
> with pl/java, so it can be done :)

It is also pretty well established that if pltcl or plperl cause the
backend to become multithreaded, things break horribly. I strongly
suspect that the only reason we've not seen similar reports about
other PLs that might introduce extra threads is that the market
penetration of other PLs is epsilon.

regards, tom lane


From: James Mansion <james(at)mansionfamily(dot)plus(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Magnus Hagander <magnus(at)hagander(dot)net>, Gevik Babakhani <pgdev(at)xs4all(dot)nl>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: .NET or Mono functions in PG
Date: 2007-12-03 08:59:32
Message-ID: 4753C574.1050304@mansionfamily.plus.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:
> It is also pretty well established that if pltcl or plperl cause the
> backend to become multithreaded, things break horribly. I strongly
>
Isn't that something that needs to be fixed? Its one thing not to allow
for multiple threads to
be in your code, but not having a threaded library linked in is going to
become more and
more of a problem.

James