473,395 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

DB Pool

Hi,

I use MySQLdb lib to access my DB, because I want to opttimize my sql
queries. The application I'm working on has quite a few traffic load,
so I want to minimize the time of creating/destroying cursors:

My typical code is sth like:

cursor=con.cursor()
cursor.execute(sql)
all= cursor.fetchall()
cursor.close()

So, the question is... how can I minimize this cost? I was thinking on
Connection Pools, but I didn't find any good documentation or sample.
Any idea?
Jul 22 '08 #1
2 2073
bcurtu wrote:
Hi,

I use MySQLdb lib to access my DB, because I want to opttimize my sql
queries. The application I'm working on has quite a few traffic load,
so I want to minimize the time of creating/destroying cursors:

My typical code is sth like:

cursor=con.cursor()
cursor.execute(sql)
all= cursor.fetchall()
cursor.close()

So, the question is... how can I minimize this cost? I was thinking on
Connection Pools, but I didn't find any good documentation or sample.
Any idea?
What has the above (getting *cursors* from a given connection) to do with
connection-pooling?

I'm not sure what the actual costs of creating a cursor are (might well be
that these are neglibel) but why don't you stop closing the cursor and just
re-use it?

Connection pooling is of course useful - frameworks such as SQLAlchemy and
SQLObject do that for you, if used proper.
Diez
Jul 22 '08 #2
bcurtu wrote:
Hi,

I use MySQLdb lib to access my DB, because I want to optimize my SQL
queries. The application I'm working on has quite a few traffic load,
so I want to minimize the time of creating/destroying cursors:

My typical code is sth like:

cursor=con.cursor()
cursor.execute(sql)
all= cursor.fetchall()
cursor.close()

So, the question is... how can I minimize this cost? I was thinking on
Connection Pools, but I didn't find any good documentation or sample.
Any idea?
Creating and destroying MySQLdb cursors is cheap, because it
doesn't really do anything. MySQL doesn't actually support
cursors; you can only do one thing at a time per connection, and
thus you can only have one cursor per connection. So cursor creation
is a dummy operation for MySQLdb.

Creating connections to the database is more expensive, and it
helps to reuse those. There was once something called the "pool
module" for doing this ("http://dustman.net/andy/python/Pool")
but it's a dead link now.

This is usually an issue only in multithreaded programs.
Also, it's OK to have multiple connections open to the database
from multiple threads, until you have so many that the database
server starts to run out of resources.

John Nagle
Jul 22 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: david.kao | last post by:
Hi All: I am creating a COM+ Pool object in C#. I set up the following attributes: JIT (true),Pool size; and at the end of each public method I called ContextUtil.DeactivateOnReturn=true to set...
9
by: Abhishek Srivastava | last post by:
Hello All, In IIS 6.0 We have a concept of worker processes and application pools. As I understand it, we can have multiple worker process per appliction pool. Each worker process is dedicated...
5
by: J-T | last post by:
I guess I'm a litte bit confused about app pool and worker process. In IIS 6.0 We have a concept of worker processes and application pools. As I understand it, we can have multiple worker process...
2
by: JoeSep | last post by:
Hi! Is it correct/safe to define a connection pool in the string "sqlConnectionString" of the "sessionState" section of Web.config? - The application is developed using AspNet 1.1 in a Windows...
0
by: roni schuetz | last post by:
since a few day's i'm running around the problem that I stocked with a change i need to do. hopefully somebody here can give me a tipp which will be usefull to solve my problem. I'm using a...
5
by: mackenzie | last post by:
Hello, I am looking for a little bit of help. I am trying to create a dynamically allocated object which contains one or more objects of type boost::pool<>. I get a compiler error when an object...
11
by: Grey Alien | last post by:
Any one know of an open source memory pool library?. I can't seem to find any implemented in C (many available in C++ e.g. Boost). Google is not turning up anything useful ...
11
by: Grey Alien | last post by:
I am looking to write a very simple memory pool library to store only one data type at a time - i.e. to provide a contiguous block of memory to be alloc'd free'd by the calling program. I am I...
5
markrawlingson
by: markrawlingson | last post by:
Hey guys, Having a bit of a complicated issue here so please bare with me while I explain. I'm also not a system admin and don't know a whole lot about IIS, so i apologize in advance. I...
4
by: steven | last post by:
hi i've got an app that runs something like 4000 updates when certain pages are updated. it's taking on average 20 seconds for these pages to execute the update command (15 seconds if all i do...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.