Re: mod_perl and mySql
From: Chris Faust <[EMAIL PROTECTED]> > Thanks Paul, that tells me to stop going crazy over it at least :).. Yeah, don't go crazy. I didn't see this in the thread, so I'll include it; a snippet from the Apache::DBI docs: PerlModule Apache::DBI # this comes before all other modules using DBI Do NOT change anything in your scripts. The usage of this module is absolutely transparent ! > The difference in performance between now and before mod_perl is just so > amazing I was trying to squeeze everything I could out of it. If Perl loading was a big problem for you, then mod_perl should provide an enormous win. There are some things to be careful of with mod_perl and DBI, but they are rare. A quick example, a lot of our scripts declare their own package name: # test.mpl # Some set up work here... my $obj = TestModPerl->new; # Other optional stuff here. package TestModPerl; sub new { # get a DB connection and do other things. } # Methods that do the work If this were a straight CGI script, the DB handled would go out of scope at program termination and the connection would close. In mod_perl, the DB handle's DESTROY() method will NEVER be called, and the connection will stay open without ever getting used again. The result? You run out of connections as soon as you have handled max_connections requests. To solve this, just use Apache::DBI like shown in the docs. By the way, your first post included this piece of code: my $database = "DBI:mysql:database=$db_name:host=$db_location"; $db = DBI->connect($database,$db_username,$db_password) or die "Cannot Connect: " . $db->errstr(); This won't quite work. If the DB connection fails, then $db won't be defined and you won't be able to say: $db->errstr(). Instead, your statement could read: $db = DBI->connect($database,$db_username,$db_password) or die "Cannot Connect: " . $DBI::errstr; --- Rodney Broom President, R.Broom Consulting http://www.rbroom.com/ - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
RE: mod_perl and mySql
>> Glad to hear that about MPW; thanks. Its the truth, those 2 books have really saved my butt more then once - so it should be me thanking you!!. >> Regarding use of persistent connections, I wonder if you really need >> them. To give an example from another language, PHP offers >> mysql_connect() >> and mysql_pconnect() connections, which set up regular or persistent >> connections. But it turns out that the difference in overhead between >> the two call is minimal because MySQL's client/server protocol is so >> efficient for connection establishment. >> >> Also, persistent connections can have certain negative effects. For one >> thing, because a connection remains open for a longer time, even when no >> script is actively using it, you can more easily end up bumping >> up against >> your server's max-simultaneous-connection limit. With non-persistent >> connections, this is less of an issue. >> Thanks Paul, that tells me to stop going crazy over it at least :).. The difference in performance between now and before mod_perl is just so amazing I was trying to squeeze everything I could out of it. -Chris - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Re: mod_perl and mySql
At 7:55 -0500 1/5/03, Chris Faust wrote: Hello Group, Due to ever increasing traffic I'm converting my site into mod_perl and quite honestly I'm confused about persistent DB connection and DB connection pooling.. I know there is tons of info out there on the goggle groups and on perl.apache.com, I also picked up "Mod_Perl Developers cookbook" and I also have the awesome "Mysql" and "MySql and Perl for the web". (BTW so far the little mod_perl section in "MySql and Perl for the web" has proven more useful then anything I've found in the whole Mod_Perl dev cookbook). Glad to hear that about MPW; thanks. Gee, maybe I should quote your paragraph on the book's companion web site! :-) Regarding use of persistent connections, I wonder if you really need them. To give an example from another language, PHP offers mysql_connect() and mysql_pconnect() connections, which set up regular or persistent connections. But it turns out that the difference in overhead between the two call is minimal because MySQL's client/server protocol is so efficient for connection establishment. Also, persistent connections can have certain negative effects. For one thing, because a connection remains open for a longer time, even when no script is actively using it, you can more easily end up bumping up against your server's max-simultaneous-connection limit. With non-persistent connections, this is less of an issue. I've seen so many example and different ways to do it, that I have no idea if I'm doing things the safest and most optimized way. For example I've read a bunch of posts where people said to do pooling its only a matter of doing your connect like "$db || DBI->CONNECT", which just gives me a syntax error. I also hear in one place that "Apache::DBI" takes care of making sure the connection stays alive but then I hear in another that is something that I will need to take care of. Below is how I've set things up, hopefully someone out there that really knows can tell me if I'm doing something wrong or if it could be done better!! Right now as it stands everything is running perfect under mod_perl, again I'm just not sure I'm doing everything the correct way. Thanks in Advance! -Chris - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
RE: mod_perl and mySql
We don't cache connections, either, and the connection overhead appears to be trivial, connecting to a remote MySQL server over the local Ethernet. 50,000 to 100,000 Apache::ASP pages served per day, some with many rather complex queries. Tom Haapanen [EMAIL PROTECTED] -Original Message- From: Michael Bacarella [mailto:[EMAIL PROTECTED]] Sent: Sunday, 05 January, 2003 11:40 To: Chris Faust Cc: MySql Mailing List Subject: Re: mod_perl and mySql Are you sure it would help? MySQL is damn fast at taking connections. When we converted to mod_perl I made a mental note to switch to persistent connections. It turns out that it still ran fast enough even though every hit results in an RDBMS connection. And at this point we're doing 5M of them per day. It has never been a bottleneck for us. -M > Due to ever increasing traffic I'm converting my site into mod_perl and > quite honestly I'm confused about persistent DB connection and DB connection > pooling.. I know there is tons of info out there on the goggle groups and on > perl.apache.com, I also picked up "Mod_Perl Developers cookbook" and I also > have the awesome "Mysql" and "MySql and Perl for the web". (BTW so far the > little mod_perl section in "MySql and Perl for the web" has proven more > useful then anything I've found in the whole Mod_Perl dev cookbook). - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
RE: mod_perl and mySql
You mean overall? The move to mod_perl is more because the site is so perl heavy, its perl that is driving the change more then anything else. I just figure If I'm going to do it, I want to do as much of it as I can :).. Thanks -Chris >> -Original Message- >> From: Michael Bacarella [mailto:[EMAIL PROTECTED]] >> Sent: Sunday, January 05, 2003 11:40 AM >> To: Chris Faust >> Cc: MySql Mailing List >> Subject: Re: mod_perl and mySql >> >> >> Are you sure it would help? MySQL is damn fast at taking connections. >> >> When we converted to mod_perl I made a mental note to switch >> to persistent connections. It turns out that it still >> ran fast enough even though every hit results in an RDBMS >> connection. And at this point we're doing 5M of them per day. >> >> It has never been a bottleneck for us. >> >> -M >> >> > Due to ever increasing traffic I'm converting my site into mod_perl and >> > quite honestly I'm confused about persistent DB connection and >> DB connection >> > pooling.. I know there is tons of info out there on the goggle >> groups and on >> > perl.apache.com, I also picked up "Mod_Perl Developers >> cookbook" and I also >> > have the awesome "Mysql" and "MySql and Perl for the web". >> (BTW so far the >> > little mod_perl section in "MySql and Perl for the web" has proven more >> > useful then anything I've found in the whole Mod_Perl dev cookbook). - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Re: mod_perl and mySql
- Original Message - From: "Chris Faust" <[EMAIL PROTECTED]> To: "MySql Mailing List" <[EMAIL PROTECTED]> Sent: Sunday, January 05, 2003 1:55 PM Subject: mod_perl and mySql > For example I've read > a bunch of posts where people said to do pooling its only a matter of > doing your connect like "$db || DBI->CONNECT", which just gives me > a syntax error. That looks odd. Perhaps you meant: "$db ||= DBI->connect ( ..." ? That will connect if $db is no longer defined (or when $db eq ""): in other words, when you lost the connection. Sorry, that is all the usefulness I have to contribute, if at all. :) - Mark - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Re: mod_perl and mySql
Are you sure it would help? MySQL is damn fast at taking connections. When we converted to mod_perl I made a mental note to switch to persistent connections. It turns out that it still ran fast enough even though every hit results in an RDBMS connection. And at this point we're doing 5M of them per day. It has never been a bottleneck for us. -M > Due to ever increasing traffic I'm converting my site into mod_perl and > quite honestly I'm confused about persistent DB connection and DB connection > pooling.. I know there is tons of info out there on the goggle groups and on > perl.apache.com, I also picked up "Mod_Perl Developers cookbook" and I also > have the awesome "Mysql" and "MySql and Perl for the web". (BTW so far the > little mod_perl section in "MySql and Perl for the web" has proven more > useful then anything I've found in the whole Mod_Perl dev cookbook). - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php