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

mod_python performs several magnitudes slower than PHP?

Recently I've had to move my site to a new dedicated server running
FreeBSD 6.1. After installing apache 2.0.59, python 2.4.4 and
mod_python 3.3.1, I decided to bench a script in PHP vs one in Python.
I found out that for some reason, my mod_python was performing
extremely slow - magnitudes slower than it should. I scowered the
internet for hours and asked a few friends and still haven't been able
to find a solution to the problem.

from mod_python import apache

def handler(req):
for i in xrange(1000):
print >req, "Yeah"
return apache.OK

and...

<?
for ($i = 0; $i < 1000; $i++)
echo "Yeah\n" ;
?>

when I ran ab on both using 1000 requests and a concurrency of 10, i
got these results:

python- Requests per second: 21.37 [#/sec] (mean)
php- Requests per second: 1008.37 [#/sec] (mean)

Any ideas would really be appreciated... I'm on my last leg.

May 19 '07 #1
4 1214
That's puzzling, because with mod_python, you're only invoking
the compiler once per Apache restart. With CGI programs, you pay
the loading penalty on every request.

John Nagle

ch************@gmail.com wrote:
Recently I've had to move my site to a new dedicated server running
FreeBSD 6.1. After installing apache 2.0.59, python 2.4.4 and
mod_python 3.3.1, I decided to bench a script in PHP vs one in Python.
I found out that for some reason, my mod_python was performing
extremely slow - magnitudes slower than it should. I scowered the
internet for hours and asked a few friends and still haven't been able
to find a solution to the problem.

from mod_python import apache

def handler(req):
for i in xrange(1000):
print >req, "Yeah"
return apache.OK

and...

<?
for ($i = 0; $i < 1000; $i++)
echo "Yeah\n" ;
?>

when I ran ab on both using 1000 requests and a concurrency of 10, i
got these results:

python- Requests per second: 21.37 [#/sec] (mean)
php- Requests per second: 1008.37 [#/sec] (mean)

Any ideas would really be appreciated... I'm on my last leg.
May 20 '07 #2
On May 20, 10:01 am, John Nagle <n...@animats.comwrote:
That's puzzling, because withmod_python, you're only invoking
the compiler once per Apache restart. With CGI programs, you pay
the loading penalty on every request.

John Nagle

chris.monsa...@gmail.com wrote:
Recently I've had to move my site to a new dedicated server running
FreeBSD 6.1. After installing apache 2.0.59, python 2.4.4 and
mod_python3.3.1, I decided to bench a script in PHP vs one in Python.
I found out that for some reason, mymod_pythonwas performing
extremely slow - magnitudes slower than it should. I scowered the
internet for hours and asked a few friends and still haven't been able
to find a solution to the problem.
frommod_pythonimport apache
def handler(req):
for i in xrange(1000):
print >req, "Yeah"
return apache.OK
and...
<?
for ($i = 0; $i < 1000; $i++)
echo "Yeah\n" ;
?>
when I ran ab on both using 1000 requests and a concurrency of 10, i
got these results:
python- Requests per second: 21.37 [#/sec] (mean)
php- Requests per second: 1008.37 [#/sec] (mean)
Any ideas would really be appreciated... I'm on my last leg.
The original poster also asked the same question on the mod_python
mailing list. As pointed out there, the examples aren't equivalent as
the mod_python example would have resulted in data being flushed to
the client after every call to 'print'.

A more suitable example for comparison would have been:

def handler(req):
for i in xrange(1000):
req.write('Yeah\n, 0)
return apache.OK

The second argument of 0 to req.write() will allow Apache to buffer
data in an appropriate way and avoid lots of socket writes with small
amounts of data, plus avoid triggering of Apache's filter mechanism
every time.

Graham

May 20 '07 #3
On 05/20/2007 Graham Dumpleton wrote:

Hi,
A more suitable example for comparison would have been:
And are there any benchmarks with this new version available? Just
curious...

best wishes,

Winfried
May 21 '07 #4
On May 21, 5:51 pm, Winfried Tilanus <no_s...@tilanus.comwrote:
On 05/20/2007 Graham Dumpleton wrote:

Hi,
A more suitable example for comparison would have been:

And are there any benchmarks with this new version available? Just
curious...
Unless someone else posts that specific example comparing it to PHP on
the same system, then you might instead look at:

http://www.modpython.org/pipermail/m...ay/023654.html

This shows the original posters Python example compared to another way
of doing it, not what I posted, which would be even quicker, ie.,
using Python itself to do the buffering.

Do note that such benchmarks are pretty meaningless as you will never
achieve such throughputs once you actually load on top your Django,
TurboGears, Pylons or other mega web framework application. Such
applications are huge and carry a lot of overhead which dwarfs any
overhead of mod_python itself.

Graham

May 21 '07 #5

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

Similar topics

4
by: Camilo Olarte | last post by:
Hi list, I was wondering : If python cgi scripts can be acceletaded by means of mod_python in apache (loading the python interpreter on apache) , then : ?Is there a way of doing the same...
5
by: Kylotan | last post by:
I thought mod_python would be the answer to my CGI performance issue, but I can't seem to make much sense out of it. All the examples are too trivial to be of much use. Given that I have an...
0
by: Julien Cigar | last post by:
Hello, I'm using mod_python 3.1.3 with Apache 2.0.54 on a Debian box with the publisher handler and the Clearsilver template engine, and from time to time apache returns an 500 error code...
3
by: mneagul | last post by:
Hello! I am writing a small program using mod_python publisher extension. I have created several python files and imported them in a `main' file. How can I stop mod_python to byte compile the...
9
by: cyberco | last post by:
And I thought this would be trivial...getting mod_python to run within apache on windows XP. ============= mod_python 3.2.8 apache 2.0.55 python2.4 winxp =============
4
by: John Salerno | last post by:
I get this internal error message when I try to access a PSP page: "Invalid command 'PythonHandler', perhaps mis-spelled or defined by a module not included in the server configuration" So it...
0
by: Manuzhai | last post by:
Hello there, I have this weird problem with a mod_python application. Recently I installed ElementTree and cElementTree through ez_setup.py, even though they were already installed normally...
2
by: Gregory (Grisha) Trubetskoy | last post by:
The Apache Software Foundation and The Apache HTTP Server Project are pleased to announce the 3.3.0b (Beta) release of mod_python. Version 3.3.0b of mod_python features several new functions and...
1
by: Rajarshi | last post by:
Hi, I have a web application built using mod_python.Currently it behaves like a standard CGI - gets data from a form, performs a query on a backend database and presents a HTML page. However the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.