Re: [HACKERS] Re: [NOVICE] Re: re : PHP and persistent connections
Uh, Don? Not all the world's a web page, you know. Thatkind of thinking is _so_ mid 90's ;-) Dedicated apps that talk directly the user seem to be making a comeback, due to a number of factors. They can have much cleaner user interfaces, for example. Which brings us back around to the point of why this is on Hackers: PostgreSQL currently has no clean method for dropping idle connections. Yes, some apps handle this themselves, but not all. A number of people seem to feel there is a need for this feature. How hard would it be to implement? Probably not too hard: we've already got an 'idle' state, suring which we block on the input. Add a timeout to hat, and we're pretty much there. goes and looks at code for a bit Hmm, we're down in the bowels of libpq, doing a recv() on the socket to the frontend, about 4 layers down from backend's blocking call to ReadCommand(). I seem to recall someone working on creating an async version of the libpq API, but Tom not being happy with the approach. So, it's not a simple change. Ross On Mon, Nov 27, 2000 at 07:18:48AM -0800, Don Baccus wrote: At 12:38 AM 11/27/00 -0700, Ron Chmara wrote: Don Baccus wrote: At 12:07 AM 11/26/00 -0500, Alain Toussaint wrote: how about having a middle man between apache (or aolserver or any other clients...) and PosgreSQL ?? that middleman could be configured to have 16 persistant connections,every clients would deal with the middleman instead of going direct to the database,this would be an advantage where multiple PostgreSQL server are used... Well, this is sort of what AOLserver does for you without any need for middlemen. What if you have a server farm of 8 AOL servers, and 12 perl clients, and 3 MS Access connections, leaving things open? Is AOLserver parsing the Perl DBD/DBI, connects, too? So you're using AOLserver as (cough) a middleman? g Note that only the AOL servers here are web client/servers, the rest are dedicated apps. snip Don missing the point -- Open source code is like a natural resource, it's the result of providing food and sunshine to programmers, and then staying out of their way. [...] [It] is not going away because it has utility for both the developers and users independent of economic motivations. Jim Flynn, Sunnyvale, Calif.
Re: [HACKERS] Re: [NOVICE] Re: re : PHP and persistent connections
At 10:46 AM 11/27/00 -0600, Ross J. Reedstrom wrote: Uh, Don? Not all the world's a web page, you know. Thatkind of thinking is _so_ mid 90's ;-) Dedicated apps that talk directly the user seem to be making a comeback, due to a number of factors. They can have much cleaner user interfaces, for example. Of course. But the question's been raised in the context of a web server, and I've answered in context. I've been trying to move the discussion offline to avoid clogging the hackers list with this stuff but some of the messages have escaped my machine with my forgetting to remove pg_hackers from the distribution list. I'll try to be more diligent if the discussion continues. - Don Baccus, Portland OR [EMAIL PROTECTED] Nature photos, on-line guides, Pacific Northwest Rare Bird Alert Service and other goodies at http://donb.photo.net.
Re: [HACKERS] Re: [NOVICE] Re: re : PHP and persistent connections
Don Baccus wrote: At 12:07 AM 11/26/00 -0500, Alain Toussaint wrote: how about having a middle man between apache (or aolserver or any other clients...) and PosgreSQL ?? that middleman could be configured to have 16 persistant connections,every clients would deal with the middleman instead of going direct to the database,this would be an advantage where multiple PostgreSQL server are used... Well, this is sort of what AOLserver does for you without any need for middlemen. What if you have a server farm of 8 AOL servers, and 12 perl clients, and 3 MS Access connections, leaving things open? Is AOLserver parsing the Perl DBD/DBI, connects, too? So you're using AOLserver as (cough) a middleman? g Again, reading stuff like this makes me think "ugh!" This stuff is really pretty easy, it's amazing to me that the Apache/db world talks about such kludges when they're clearly not necessary. How does AOL server time out access clients, ODBC connections, Perl clients? I thought it was mainly web-server stuff. Apache/PHP isn't the only problem. The problem isn't solved by telling others to fix their software, either... is this something that can be done _within_ postmaster? -Bop -- Brought to you from iBop the iMac, a MacOS, Win95, Win98, LinuxPPC machine, which is currently in MacOS land. Your bopping may vary.
[HACKERS] Re: [NOVICE] Re: re : PHP and persistent connections
Note: CC'd to Hackers, as this has wandered into deeper feature issues. Tom Lane wrote: GH [EMAIL PROTECTED] writes: Do the "persistent-connected" Postgres backends ever timeout or die? No. A backend will sit patiently for the client to send it another query or close the connection. This does have an unfortunate denial-of-service implication, where an attack can effectively suck up all available backends, and there's no throttle, no timeout, no way of automatically dropping these However, the more likely possibility is similar to the problem that we see in PHP's persistant connections a normally benign connection is inactive, and yet it isn't dropped. If you have two of these created every day, and you only have 16 backends, after 8 days you have a lockout. On a busy web site or another busy application, you can, of course, exhaust 64 backends in a matter of minutes. Is it possible to set something like a timeout for persistent connctions? (Er, would that be something that someone would want to do? A Bad Thing?) This has been suggested before, but I don't think any of the core developers consider it a good idea. Having the backend arbitrarily disconnect on an active client would be a Bad Thing for sure. Right but I don't think anybody has suggested disconnecting an *active* client, just inactive ones. Hence, any workable timeout would have to be quite large (order of an hour, maybe? not milliseconds anyway). The mySQL disconnect starts at around 24 hours. It prevents a slow accumulation of unused backends, but does nothing for a rapid accumulation. It can be cranked down to a few minutes AFAIK. And that means that it's not an effective solution for the problem. Under load, a webserver that wastes backend connections will run out of available backends long before a safe timeout would start to clean up after it. Depends on how it's set up... you see, this isn't uncharted territory, other web/db solutions have already fought with this issue. Much like the number of backends set up for pgsql must be static, a timeout may wind up being the same way. The critical thing to realize is that you are timing out _inactive_ connections, not connections in general. So provided that a connection provided information about when it was last used, or usage set a counter somewhere, it could easily be checked. To my mind, a client app that wants to use persistent connections has got to implement some form of connection pooling, so that it recycles idle connections back to a "pool" for allocation to task threads that want to make a new query. And the threads have to release connections back to the pool as soon as they're done with a transaction. Actively releasing an idle connection is essential, rather than depending on a timeout. I haven't studied PHP at all, but from this conversation I gather that it's only halfway there... Well.. This is exactly how apache and PHP serve pages. The problem is that apache children aren't threads, they are separate copies of the application itself. So a single apache thread will re-use the same connection, over and over again, and give that conection over to other connections on that apache thread.. so in your above model, it's not really one client application in the first place. It's a dynamic number of client applications, between one and hundreds or so. So to turn the feature request the other way 'round: "I have all sorts of client apps, connecting in different ways, to my server. Some of the clients are leaving their connections open, but unused. How can I prevent running out of backends, and boot the inactive users off?" -Ronabop -- Brought to you from iBop the iMac, a MacOS, Win95, Win98, LinuxPPC machine, which is currently in MacOS land. Your bopping may vary.
Re: [HACKERS] Re: [NOVICE] Re: re : PHP and persistent connections
"I have all sorts of client apps, connecting in different ways, to my server. Some of the clients are leaving their connections open, but unused. How can I prevent running out of backends, and boot the inactive users off?" how about having a middle man between apache (or aolserver or any other clients...) and PosgreSQL ?? that middleman could be configured to have 16 persistant connections,every clients would deal with the middleman instead of going direct to the database,this would be an advantage where multiple PostgreSQL server are used... 240 apache process are running on a box and there's 60 PostgreSQL instance running on the machine or another machine: 240 apache process -- middleman -- 60 PostgreSQL process now if there's multiple Database server: 240 apache process -- middleman -- 12 PostgreSQL for each server (5 servers in this case) in this case,the middleman could be a shared library which the clients link to.. what do you think about that ?? Alain Toussaint
Re: [HACKERS] Re: [NOVICE] Re: re : PHP and persistent connections
At 12:07 AM 11/26/00 -0500, Alain Toussaint wrote: how about having a middle man between apache (or aolserver or any other clients...) and PosgreSQL ?? that middleman could be configured to have 16 persistant connections,every clients would deal with the middleman instead of going direct to the database,this would be an advantage where multiple PostgreSQL server are used... Well, this is sort of what AOLserver does for you without any need for middlemen. Again, reading stuff like this makes me think "ugh!" This stuff is really pretty easy, it's amazing to me that the Apache/db world talks about such kludges when they're clearly not necessary. My first experience running a website (donb.photo.net) was with Apache on Linux on an old P100 system in 1996 when few folks had personal photo sites with 1000 photos on them getting thousands of hits a day. I have fond memories of those days, and Apache served me (or more properly webserved my website) well. This site is largely responsible for my reputation that lets me freelance nature photography to the national media market pretty much at will. Thus my fondness. But ... for database stuff the release of AOLserver as first Free Beer, and now Free Speech software has caused me to abandon Apache and suggestions like the above just make me cringe. It shouldn't be that hard, folks. - Don Baccus, Portland OR [EMAIL PROTECTED] Nature photos, on-line guides, Pacific Northwest Rare Bird Alert Service and other goodies at http://donb.photo.net.
Re: [HACKERS] Re: [NOVICE] Re: re : PHP and persistent connections
At 10:00 PM 11/25/00 -0800, Mitch Vincent wrote: I've tried quite a bit to use persistent connections with PHP (for over a year) and always the scripts that I try to use them with behave crazy... The last time I tried there were problems all over the place with PHP, variables getting overwritten, certain functions just totally breaking (date() to name one) and so on.. I know I'm not being specific but my point is that I think there are some other outstanding PHP issues that play into this problem as the behavior that I've seen isn't directly related to PostgreSQL but only happens when I use persistent connections.. I've heard rumors that PHP isn't thoroughly threadsafe, could this be a source of your problems? - Don Baccus, Portland OR [EMAIL PROTECTED] Nature photos, on-line guides, Pacific Northwest Rare Bird Alert Service and other goodies at http://donb.photo.net.
Re: [HACKERS] Re: [NOVICE] Re: re : PHP and persistent connections
I'm sure that this, if true, could certainly be the source of the problems I've seen... I can't comment on if PHP is completely threadsafe, I know that some of the modules (for lack of a better word) aren't, possible the ClibPDF library I'm using. I'll check into it. Thanks! -Mitch - Original Message - From: "Don Baccus" [EMAIL PROTECTED] To: "Mitch Vincent" [EMAIL PROTECTED]; "PostgreSQL Hackers List" [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Saturday, November 25, 2000 9:18 PM Subject: Re: [HACKERS] Re: [NOVICE] Re: re : PHP and persistent connections At 10:00 PM 11/25/00 -0800, Mitch Vincent wrote: I've tried quite a bit to use persistent connections with PHP (for over a year) and always the scripts that I try to use them with behave crazy... The last time I tried there were problems all over the place with PHP, variables getting overwritten, certain functions just totally breaking (date() to name one) and so on.. I know I'm not being specific but my point is that I think there are some other outstanding PHP issues that play into this problem as the behavior that I've seen isn't directly related to PostgreSQL but only happens when I use persistent connections.. I've heard rumors that PHP isn't thoroughly threadsafe, could this be a source of your problems? - Don Baccus, Portland OR [EMAIL PROTECTED] Nature photos, on-line guides, Pacific Northwest Rare Bird Alert Service and other goodies at http://donb.photo.net.
Re: [HACKERS] Re: [NOVICE] Re: re : PHP and persistent connections
Well, this is sort of what AOLserver does for you without any need for middlemen. i agree that AolServer is good karma,i've been reading various docs on Aolserver since Philip Greenspun talked about it on linuxworld and i'm glad that there's some java support being coded for it (im my opinion,it's the only advantage that Apache had over AolServer for me). Again, reading stuff like this makes me think "ugh!" This stuff is really pretty easy, it's amazing to me that the Apache/db world talks about such kludges when they're clearly not necessary. well...i was using Apache as an example due to it DB model but the stuff i was talking would work quite well in the case of multiple DB server hosting differents table and you want to maintain location independance,here's an example: you have 7 Database server,5 are online and the other 2 are for maintenance and/or development purpose,for simplicity,we'll name the server database1.example.net to database7.example.net,database4.example.net is currently doing a dump and database6.example.net is loading the dump from database4,then,you reconfigure the middleman so it redirect all request from database4 to database6: vim /etc/middleman.conf and then a sighup to the middleman so it reread its config file: killall -HUP middleman this would update the middleman's shared lib with the new configuration info (and BTW,i just extended my idea from a single shared lib to a daemon/shared lib combo). now i'm off to get the dog out for a walk and then,take a nap,see ya !! Alain Toussaint