Gregory Piñero wrote: >>> [Tue Nov 20 17:07:23 2007] [error] [client 127.0.0.1] >>> OperationalError: (1040, 'Too many connections') >>> >>> I set my.conf to have 16 max connections so I don't know why it says >>> there are too many since I only gave the pool 10. >> There are two reasons why this can happen. >> >> First, make sure you are setting up POOL only one time, globally. Put a >> print statement after the "POOL = " statement and make sure it prints >> only once. > > So I'm using Apache (MPM=Prefork) with mod_wsgi and web.py. So after > further research it looks like, each Apache child process is going to > have it's own global variables. So perhaps it's not really feasible > for me to have a pool in this setup.
Yes, mod_python and mod_wsgi run in the child processes that Apache is spawning with the Prefork module. So you are actually living in a multi-processing environment here, not a multi-threading environment. DBUtils has originally been written for multi-threading environments such as Webware's ThreadedAppServer (which is not directly coupled to Apache's processes even if you use the Apache mod_webkit module). So I haven't really thought about multi-processing environments yet. But that does not mean that DBUtils is not suited here. Each process will then have its own pool that you must make accordingly smaller (the maximum number of pools will be MaxClients/ThreadsPerChild). Only if ThreadsPerChild is very low or even=1 (as I think it is in the Prefork module), then using DBUtils will be of no use. I'll probably need to add something about multi-processing in the DBUtils documentation, as we are going more into the direction of multi-processing with Python, due to the new multi-core CPUs and the old Python GIL problem. > My error seems to be coming from MySQL though, and not from DBUtils. > It's probably my last point that each apache process is actually > making its own pool. Yes, you're right, this error message is coming from MySQL. I should have looked more carefully, since DBUtils would have raised a different exception. Each of your Apache processes creates its own pool of initially 4 connections, and the 5th process will get into troubles then. Plus, you cannot make use of the pools at all, since the processes are not creating extra threads. > I got: > >>>> MySQLdb.threadsafety > 1 > > So that means it's not thread safe? So no sharing? Yes. No sharing possible then. >> You can also try PersistentDB instead of PooledDB and check whether it >> gives better performance for you. > > So I'm thinking either to go with PersistentDB and then have max mysql > connections = max apache servers - 1. PersistentDB will not be of great use either as long as you are using the Prefork MPM, since there you will have only one Thread per child. One way to go would be to switch over to a different MPM and use small PooledDB pools or PersistentDB. I'll think about other solutions in the multi-process environment. Probably we can also find something in the Internet, I haven't googled yet. If you find something, let me know so I can mention it in the DBUtils documentation. -- Chris ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Webware-devel mailing list Webware-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/webware-devel