473,382 Members | 1,390 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,382 software developers and data experts.

Performance Issues of MySQL with Python

Hi All,

I am a newbie to MySQL and Python. At the first place, I would like to
know what are the general performance issues (if any) of using MySQL
with Python.

By performance, I wanted to know how will the speed be, what is the
memory overhead involved, etc during database specific operations
(retrieval, update, insert, etc) when MySQL is used with Python.

Any solutions to overcome these issues (again, if any)?

Thanks and Regards,
Sandeep

Jul 18 '05 #1
5 4662
Wow, you give us too much credit out here. From your
post we can't determine anything about what you plan
to do (how is your data structured, how much data do
you have, can it be indexed to speed up searching...).

Python and MySQL work together beautifully. ANY SQL
database's performance is more about properly defining
the tables and indexes where appropriate than about
language uses to it. You can write compiled C (or any
other language for that matter) that calls a poorly
designed database that gets terrible performance. A
well thought out database structure with good choices
for indexes can give you outstanding performance when
called from any language. Ultimately it comes down
to building a SQL query and passing it to the SQL
database and getting back results. Front end language
isn't all that important (unless you must post-process
the data in the program a lot). It is not uncommon
to get 100x or 1000x speed increases due to adding
proper indexes to tables or refactoring master-detail
table relationships in any SQL database. You can't
get that by changing languages or even purchasing
faster hardware.

MySQL is particularly good when your read operations
outnumber your writes. US Census Bureau uses MySQL
because they have static data that gets read over and
over (even though my understanding is that they have
an Oracle site license). Databases that are transaction
oriented (e.g. accounting, etc.) can sometimes benefit
from the highly transactional nature of an Oracle or
DB2 or Postgres. Later versions of MySQL have added
transactions, but the support is IMHO a step behind
the big guys in this area. Also, if you want to be
highly scalable so as to provide for clustering, of
database servers, etc. MySQL doesn't do that well
in this area, YET.

I hope my random thoughts are helpful.

Larry Bates
sandy wrote:
Hi All,

I am a newbie to MySQL and Python. At the first place, I would like to
know what are the general performance issues (if any) of using MySQL
with Python.

By performance, I wanted to know how will the speed be, what is the
memory overhead involved, etc during database specific operations
(retrieval, update, insert, etc) when MySQL is used with Python.

Any solutions to overcome these issues (again, if any)?

Thanks and Regards,
Sandeep

Jul 18 '05 #2
"sandy" <sa***********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Hi All,

I am a newbie to MySQL and Python. At the first place, I would like to
know what are the general performance issues (if any) of using MySQL
with Python.

By performance, I wanted to know how will the speed be, what is the
memory overhead involved, etc during database specific operations
(retrieval, update, insert, etc) when MySQL is used with Python.

Any solutions to overcome these issues (again, if any)?


There are no "general performance issues" with respect to "using MySQL with
Python".

The use of Python as a programming front end does not impact the performance
of whatever database server you might select. The choice of MySQL as your
database server does not impact the effectiveness of whatever front end
programming language you select. The 2 functions, database server and
programming language, do not interact in ways that raise unique performance
issues.

You can choose each one without worrying about the other. They two quite
separate design choices.

Thomas Bartkus
Jul 18 '05 #3
There aren't any "issues", but there are a few things to keep in mind.

First of all, prior to 4.1, MySQL does no parameter binding, which
means that the parameters must be inserted into your SQL statements as
literals. MySQLdb will do this for you automatically, but keep in mind
that you will be creating a string that is big as your original SQL
statement plus the size of all the parameters. If you are doing a large
INSERT (via executemany()), this could be pretty big. However, this is
no worse a problem with Python than it is with anything else.

MySQL-4.1 *does* support parameter binding, but MySQLdb does not yet.
The next major release will, but that is months off.

The other factor to account for is your result set. By default, MySQLdb
uses the mysql_store_result() C API function, which fetches the entire
result set into the client. The bigger this is, the longer it will take
for your your query to run. You can also use a different cursor type
which uses mysql_use_result(), which fetches the result set row by row.
The drawback to this are that you must fetch the entire result set
before you can issue another query. But again, this is not an issue
with Python.

Make sure you read PEP-249 and then the User's Guide.

Jul 18 '05 #4
There are no performance overhead except when you are dragging a huge
chunk of information out of the database, in that case, python is
converting the data to its tuple data type which adds one more
processing.

I found this when I didn't have the priviledge to do "mysql> SELECT *
FROM TBL INTO OUTFILE;", I used python MySQLdb first, which I later
found sufficiently slower enough than using >>>system("echo 'USE db;
SELECT * FROM TBL;' |mysql >outfile")

But this is the minor case.

Jul 18 '05 #5
Well, it does more than that. It converts each column from a string
(because MySQL returns all columns as strings) into the appropriate
Python type. Then you were converting all the Python types back into
strings. So it's no mystery that using the command line client is
faster, since it would take the string results and write them out
directly. (I assume it does this; there's no rational reason for it to
do otherwise.)

Jul 18 '05 #6

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

Similar topics

3
by: Andrea A | last post by:
Hi, i'm setting up a website with a forecast traffic of 70.000 sessions and 1.000.000 pageviews a day. I'm in trouble about the short budget I have (about 10K $) and the big traffic and so the...
13
by: jamie howard | last post by:
Hello there - we have a fairly busy server and we just started to have problems with PHP sessions failing. We've never had this problem before and to be honist, out server traffic is lower than it...
25
by: Brian Patterson | last post by:
I have noticed in the book of words that hasattr works by calling getattr and raising an exception if no such attribute exists. If I need the value in any case, am I better off using getattr...
0
by: Andrew Braithwaite | last post by:
Hi, Can anyone help? I'm running a server with a Pentium 133 w/32meg ram, 512 pipeline burst, with a wd 512MB HD and I want to store George Bush in our MySQL database. As far as table...
8
by: Jean-Christian Imbeault | last post by:
I'm trying to convince another open-source project (phpOpenTracker) to modify their current INSERT sql queries. Currently they just do an INSERT into a table without first checking if their might...
0
by: keith | last post by:
Hi, I am trying to use the Python MySQL APIs and have been attempting to install the above software. I am using MySQL 5.0.18-standard with Python 2.4.1 I get errors on the build. Some...
1
by: marcfischman | last post by:
Please help. I have a website running on a linux/apache/mysql/php server. I receive about 8,000-10,000 visitors a day with about 200,000 to 300,000 page views. The server is a RedHat Linux...
7
by: Martien van Wanrooij | last post by:
I have been faced a couple of times with the situation that I wanted to write a script and was worried about a too frequent opening and closing mysql connections. To give some examples: 1)I...
3
by: Nagu | last post by:
Hi, I made a small recommendation engine for our company using python, django, and mySQL. My supervisor and the senior management are worried about the copyright and licensing issues. They want...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.