Hi, I'm a bit new to MySQL; here's a philisophical question.
I'm working on getting my head round apache2+mod_pyt hon+mysql for web applications. It all seems pretty straight-forward, and I'm making great progress so far.
However, I'd like to know your opinions on whether it is better to open a database connection once, globally, at the beginning of each module, and keep it open "forever" or to do a "drive by query"; i.e. open/query/close every time.
The way mod_python works, is that a python process is started for each apache server thread, and this is run "forever" - until the server is shut down/restarted. If I choose to open the connection once only at the head of each module, the connections could become broken (due to timeout/loss of network connection/whatever) and cause a crash. On the other hand, if I go the "drive by" route, and the site becomes very busy (theoretically, of course) this could result in a large number of connection opens and closes, which could be computationally expensive.
I suppose a mid-ground, "managed persistent connection" may solve this but the code complexity is probably worse.
Thanks for any input!
regards,
-cybervegan
I'm working on getting my head round apache2+mod_pyt hon+mysql for web applications. It all seems pretty straight-forward, and I'm making great progress so far.
However, I'd like to know your opinions on whether it is better to open a database connection once, globally, at the beginning of each module, and keep it open "forever" or to do a "drive by query"; i.e. open/query/close every time.
The way mod_python works, is that a python process is started for each apache server thread, and this is run "forever" - until the server is shut down/restarted. If I choose to open the connection once only at the head of each module, the connections could become broken (due to timeout/loss of network connection/whatever) and cause a crash. On the other hand, if I go the "drive by" route, and the site becomes very busy (theoretically, of course) this could result in a large number of connection opens and closes, which could be computationally expensive.
I suppose a mid-ground, "managed persistent connection" may solve this but the code complexity is probably worse.
Thanks for any input!
regards,
-cybervegan
Comment