<div dir="ltr"><div>Hello,<br><br></div>This conversation makes me wonder about how the database connections works behind Dancer.<br><br>Please, suppose we have a simple application with only two routes<br><br>/route1<br> -> call Package->new() to create the structure (and the database handler)<br> -> do queries<br> -> do some stuff<br> -> return value<br><br>/route2<br> -> call Package->new() to create the structure (and the database handler)<br> -> do queries<br> -> do some stuff<br> -> return value<br><br>Do we need to insert Package->end() to for example close the database connections?<br>Is it any difference if we are using the Plugin or make the DB connections directly? Cache?<br><br>Thanks to all for any light.<br></div><div class="gmail_extra"><br><div class="gmail_quote">2016-12-10 22:28 GMT+01:00 Zahir Lalani <span dir="ltr"><<a href="mailto:ZahirLalani@oliver.agency" target="_blank">ZahirLalani@oliver.agency</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thx All<br>
<br>
No transactions - its mainly selects but I will add in Racke's suggestion of finish and see what that does.<br>
<br>
As for Starman - so far not had any issues - but we have set it to limit the max requests so that it gets cleaned every so often. I do want to try out uwsgi - have read very good things - thx for the heads up<br>
<span class="im HOEnZb"><br>
Z<br>
<br>
> -----Original Message-----<br>
> From: dancer-users [mailto:<a href="mailto:dancer-users-bounces@dancer.pm">dancer-users-bounces@<wbr>dancer.pm</a>] On Behalf<br>
</span><div class="HOEnZb"><div class="h5">> Of Hermann Calabria<br>
> Sent: 10 December 2016 21:21<br>
> To: Perl Dancer users mailing list <<a href="mailto:dancer-users@dancer.pm">dancer-users@dancer.pm</a>><br>
> Subject: Re: [dancer-users] High CPU usage on DB<br>
><br>
> If you're using Dancer::Plugin::Database (and I suspect D2 has the same<br>
> issue), you're using transactions, and a crash occurs mid-transaction, note<br>
> that there is no automatic rollback() on die().  I documented this issue here,<br>
> and bigpresh (the plugin author) was kind enough to offer some<br>
> suggestions:<br>
><br>
> <a href="https://github.com/bigpresh/Dancer-Plugin-Database/issues/76" rel="noreferrer" target="_blank">https://github.com/bigpresh/<wbr>Dancer-Plugin-Database/issues/<wbr>76</a><br>
><br>
> With enough of these, you end up with a bunch of unfinished transactions,<br>
> and the obvious problems eventually start occurring -- memory leaks, high<br>
> cpu usage, hung processes, etc.<br>
><br>
> Unrelated, but may be helpful: We gave up on Starman. Just could not get it<br>
> stable in a high-traffic production environment. We switched to uwsgi (with<br>
> nginx) and haven't looked back since. uwsgi is fast, compact, has tons of<br>
> useful options.  It is used by Python stacks, so it is well-supported and<br>
> updated, including commercial support if you need it.<br>
><br>
> Good luck on your project!<br>
><br>
> -----Original Message-----<br>
> From: Zahir Lalani<br>
> Sent: Saturday, December 10, 2016 1:52 AM<br>
> To: Perl Dancer users mailing list<br>
> Subject: Re: [dancer-users] High CPU usage on DB<br>
><br>
> Hi Warren<br>
><br>
> We are looking into the processes more - we are also looking at all the fine<br>
> tuning of PG parameters to make sure none of those are having an impact<br>
><br>
> On the Dancer side - maybe I need to check that we are doing things<br>
> correctly. We use Dancer2::Plugin::Database in the following way.<br>
><br>
> In each module that performs DB requests, we 'use' the above package<br>
><br>
> In a typical DB layer request we will do:<br>
><br>
> Package mmm;<br>
> use Dancer2 appname => 'APP';<br>
> Use Dancer2::Plugin::Database<br>
><br>
> .........<br>
> $sth = database->prepare("select xxxx from yyy(?)"); $sth->execute($id);<br>
><br>
> $result = $sth->fetchrow_hashref();<br>
><br>
> return $result;<br>
> ............<br>
><br>
> There is no explicit closing of connections.<br>
><br>
> We use starman to run our app, and it looks like the number of starman<br>
> workers matches exactly the number of open connections to the DB - so it<br>
> seems that the plugin holds one open connection per instance.<br>
><br>
> Does the above all sound the correct use of the plugin?<br>
><br>
> Z<br>
><br>
> > -----Original Message-----<br>
> > From: dancer-users [mailto:<a href="mailto:dancer-users-bounces@dancer.pm">dancer-users-bounces@<wbr>dancer.pm</a>] On Behalf<br>
> > Of Warren Young<br>
> > Sent: 08 December 2016 17:33<br>
> > To: Perl Dancer users mailing list <<a href="mailto:dancer-users@dancer.pm">dancer-users@dancer.pm</a>><br>
> > Subject: Re: [dancer-users] High CPU usage on DB<br>
> ><br>
> > On Dec 8, 2016, at 10:27 AM, Zahir Lalani <ZahirLalani@oliver.agency><br>
> > wrote:<br>
> > ><br>
> > > We use the Dancer database module to create a connection<br>
> ><br>
> > Are you caching those connections or re-opening a fresh one for every<br>
> > request?<br>
> ><br>
> > And if the latter, are you *closing* the connection before returning<br>
> > the queried data to the client?  Are you sure, evidenced by monitoring<br>
> > the OS’s open file handles counter?<br>
> ><br>
> > You don’t say which OS this is, but if it’s Linux:<br>
> ><br>
> >     ls /proc/$(pidof my-dancer-program)/fd | wc -l<br>
> ><br>
> > > so in this case we have 20 connections to the DB<br>
> ><br>
> > So you believe.  Double-check.<br>
> ><br>
> > > a restart of Starman cures the problem<br>
> ><br>
> > That sure sounds like a leaked resource of some kind.  I have you<br>
> > chasing DB file handles.  You say it isn’t leaked memory.  If not<br>
> > either of those, then it could be web sockets or any similar sort of<br>
> > thing.<br>
> ><br>
> > ______________________________<wbr>_________________<br>
> > dancer-users mailing list<br>
> > <a href="mailto:dancer-users@dancer.pm">dancer-users@dancer.pm</a><br>
> > <a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" rel="noreferrer" target="_blank">http://lists.preshweb.co.uk/<wbr>mailman/listinfo/dancer-users</a><br>
> ______________________________<wbr>_________________<br>
> dancer-users mailing list<br>
> <a href="mailto:dancer-users@dancer.pm">dancer-users@dancer.pm</a><br>
> <a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" rel="noreferrer" target="_blank">http://lists.preshweb.co.uk/<wbr>mailman/listinfo/dancer-users</a><br>
><br>
> ______________________________<wbr>_________________<br>
> dancer-users mailing list<br>
> <a href="mailto:dancer-users@dancer.pm">dancer-users@dancer.pm</a><br>
> <a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" rel="noreferrer" target="_blank">http://lists.preshweb.co.uk/<wbr>mailman/listinfo/dancer-users</a><br>
______________________________<wbr>_________________<br>
dancer-users mailing list<br>
<a href="mailto:dancer-users@dancer.pm">dancer-users@dancer.pm</a><br>
<a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" rel="noreferrer" target="_blank">http://lists.preshweb.co.uk/<wbr>mailman/listinfo/dancer-users</a><br>
</div></div></blockquote></div><br></div>