By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,957 Members | 2,017 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,957 IT Pros & Developers. It's quick & easy.

mod_python performs several magnitudes slower than PHP?

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.