You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Mikael Claesson <mi...@yahoo.com> on 2000/08/17 12:45:47 UTC

using modules written in C?

I've always done all my serious cgi-programming in C,
but now I've been forced to lern perl and I kinda
figure it's not that bad. And with mod_perl it looks
even better.

I plan to keep all lowerlevel database stuff in C, and
embed it in a perl module. Will this make things run
slower than if I made it all in perl?

Will apache keep the module in memory between
requests? Does this mean that I'll have to be more
careful to free all memory that I allocate and such?
No more cowboy coding?

There seems to be a module that keeps a constant mysql
database connection open. Will this speed things up
much? Can I use that connection in the C code (in the
homegrown perl module)?


__________________________________________________
Do You Yahoo!?
Send instant messages & get email alerts with Yahoo! Messenger.
http://im.yahoo.com/

Re: using modules written in C?

Posted by Stas Bekman <st...@stason.org>.
On Thu, 17 Aug 2000, Barrie Slaymaker wrote:

> Mikael Claesson wrote:
> > 
> > with mod_perl it looks even better.
> 
> Cool.  Welcome.
> 
> > I plan to keep all lowerlevel database stuff in C, and
> > embed it in a perl module. Will this make things run
> > slower than if I made it all in perl?
> 
> Usually faster, but whether that's significant in your application
> (ie will the users notice) is hard to say.  It's primarily
> about productivity & maintainance vs. performance tradeoff.
> 
> XS code is a good way to preserve your existing code, I suspect.

XS or SWIG, you can find an introduction to both in the Advanced Perl
Programming book. 

For a wonderfull series of XS articles see: 
http://www.perlmonth.com/columns/modules/modules.html?issue=6
http://www.perlmonth.com/columns/modules/modules.html?issue=7
http://www.perlmonth.com/columns/modules/modules.html?issue=8
http://www.perlmonth.com/columns/modules/modules.html?issue=9
http://www.perlmonth.com/columns/modules/modules.html?issue=10

And of course: perldoc perl, which gives:

perlembed           Perl ways to embed perl in your C or C++ application
perlapio            Perl internal IO abstraction interface
perlxs              Perl XS application programming interface
perlxstut           Perl XS tutorial
perlguts            Perl internal functions for those doing extensions
perlcall            Perl calling conventions from C

[snipped the rest of nice comments]

_____________________________________________________________________
Stas Bekman              JAm_pH     --   Just Another mod_perl Hacker
http://stason.org/       mod_perl Guide  http://perl.apache.org/guide 
mailto:stas@stason.org   http://apachetoday.com http://jazzvalley.com
http://singlesheaven.com http://perlmonth.com   perl.org   apache.org



Re: using modules written in C?

Posted by Barrie Slaymaker <ba...@slaysys.com>.
Mikael Claesson wrote:
> 
> with mod_perl it looks even better.

Cool.  Welcome.

> I plan to keep all lowerlevel database stuff in C, and
> embed it in a perl module. Will this make things run
> slower than if I made it all in perl?

Usually faster, but whether that's significant in your application
(ie will the users notice) is hard to say.  It's primarily
about productivity & maintainance vs. performance tradeoff.

XS code is a good way to preserve your existing code, I suspect.

> Will apache keep the module in memory between
> requests?

That's one of the primary advantages of mod_perl.  The other
(as I see it) is tight integration with Apache internals.

> Does this mean that I'll have to be more
> careful to free all memory that I allocate and such?

Very much so.

> No more cowboy coding?

'fraid not.

> There seems to be a module that keeps a constant mysql
> database connection open. Will this speed things up
> much? Can I use that connection in the C code (in the
> homegrown perl module)?

Yes, yes, and yes.  It might be too much of a pain to call into
perl from your C code, but you might be able to get the database
connection handle from DBI and pass it in to your C code.  Hard to
tell without knowing more about your C code and why it needs to
stay in C.  However, it should be pretty trivial to cache your
database connection yourself in your C code: just use your own
connection open routine that reuses the previous connection if
it's still valid, and never close.  That's probably easier.

Before going much further, you should probably read The Guide, as
it answers the questions you've asked (except the last) in great
detail, and more:

   http://perl.apache.org/guide/

You might also get Writing Apache Modules with Perl and C, often
referred to as "the Eagle book", by Lincoln Stein and Doug MacEachern.

HTH,

Barrie


> 
> __________________________________________________
> Do You Yahoo!?
> Send instant messages & get email alerts with Yahoo! Messenger.
> http://im.yahoo.com/

Re: using modules written in C?

Posted by Perrin Harkins <pe...@primenet.com>.
On Thu, 17 Aug 2000, Mikael Claesson wrote:
> I plan to keep all lowerlevel database stuff in C, and
> embed it in a perl module. Will this make things run
> slower than if I made it all in perl?

It shouldn't.  Keep in mind though, when you use DBI from perl you are
still doing all the low-level database stuff in C.  DBI is all C code
with a perl interface.

Ultimately, most database applications under mod_perl have their
performance bottleneck at the database, which means you get a good return
on your effort by writing your application in the way that's easiest for
you to maintain (maybe in C, in your case) and then spending your
optimization time tuning the database and the SQL.

- Perrin