Re: [Modeling-users] Database Connections
Status: Abandoned
Brought to you by:
sbigaret
From: <so...@la...> - 2004-08-10 00:48:12
|
On Friday 06 August 2004 21:44, Sebastien Bigaret wrote: [snip] =46irst .. i'm very busy w/ computer off, right now so .. Anyways > I'm not sure this is exact --I've read your post there, and I do not=20 > agree w/ your analysis: I can be wrong of course since my experience w/ > mod_python is really thin, but to my understanding there is a global > namespace available w/ mod-python, the global namespace that exists > within the subinterpreter dedicated to an application. =46irst, i won't talk about apache1 but take care that apache2 isn't really= =20 stable. I use it in production right now but i disabled the thread support. I get to much trouble w/ it. They is 3 kind of process handling in apache2 fork / thread / mixed (i don't recall it but i hope it's true ..:)=20 I won't go deeper in explain but cut/paste the answer i got about MPServlet (which use mod_python + apache2) from Daniel Popowich: """=20 Your questions are related to each other and are frequently asked on the mod_python discussion list. The problem with maintaining global data with mod_python (and servlets doesn't solve this issue) is tightly related to how apache maintains processes and threads. If you are on linux or other unix-like OS, then apache uses the prefork MPM by default. This is a multi-process MPM where each request is handled by a separate process, so you end up with N python interpreters, where N is the number of processes apache has forked. In such an environment, the only way to have global data is through some external storage: sessions, db, shared memory, etc. =46or unix, there is the worker MPM which is a hybrid multi-process/multi-threaded server. With worker you can control apache such that you have ONE process with multiple threads. I know one person who is using servlets in such a manner. (This is the default on windows with the winnt MPM.) In such an environment you can have global data shared across requests, but of course, you'll have to wrap your data in mutexes of some sort to avoid threads stepping on each other. If the data you want shared across requests is tied to a particular user, then sessions are an excellent solution. Light-weight and pretty fast. Servlets has builtin support for sessions; see the api doc or the tutorial. """ In short, using if you're using the fork behaviour, you can't share data. So in modeling =3D> time consuming import .. and multiple (with no way to reduce without restart ).. interpreter .. not talking about the trouble you can get if you have some multiple virtual host=20 etc etc .. If you want to share data, you need to use the multi-thread, but=20 you have to play w/ python thread/mutexes. And everybody around=20 know I don't want to play w/ thread. In modeling, i don't know if=20 you can do something like this. I mean, share a 'global' editing=20 context, and garantues that it's thread safe. (without of course ending w/ a lock/unlock around each http request). I use SQObject=20 for a couple of things right now, and I get exactly this kind of=20 troubles. For example SQLite or MySQL DB Api aren't thread safe.=20 (I get weird issues about lost connection in MySQL) ..=20 So that's the dilemma (the post in my blog, is about all kind=20 of web frameworks, but here is example) If you don't want to=20 share objects, ok but you will loose time because you can use=20 some cache behaviours ..=20 I you want to share, it's ok, but you need to play w/ generator (=E0la Twisted) or to play w/ the mutexes. And i didn't find a way to do it the nice way, because most of python modules doesn't scale very well in threaded env.=20 In my point of view, quixote offer a good way to handle this.=20 Because it use the same prefork / reuse process that apache does. So you don't have to deal w/ threadObuggy modules, and=20 you can really handle multiples connections without any other artifact, and without loosing time in big lock/unlock.=20 (I know Zope can handle multiple cnx without too much pain by threading. But Zope's threads aren't really used to do=20 multiple task at the same time. It's just a way to accept http request without locking ..)=20 > > Look at http://www.larsen-b.com/Article/130.html for little deeper > > explain of the problem. > > > > I haven't do this kind of stuff for a while.. but i think Modeling need > > something like Durus do .. a server process.. :) > > Interesting indeed, I'll have a look at that. Do you have experience > with this? How do they serialize objects that are transmitted between > the server and its client? I played w/ it in a recent project, it's more simple than ZODB + ZEO ..=20 but i don't know how it works.=20 While finishing this mail, i remember that's a modeling mailing list, and=20 need to apologize to other that don't want to hear about http handling=20 Hope this helps. / I know i need to go to english course sooooonnnn :) |