Forking consumes a large amount of CPU when you have
many simultaneous connections and adds up to the
latency. Particularly MySQL users may think
PostgreSQL's connection time is much slower because
these users tend to perform relatively simple queries.
In my case, connection pooling and persistent
connection is useless for a large server farm
consisting of hundreds of partitioned and replicated
servers doing only simple queries.
Below is a benchmark of MySQL 3.2 and PostgreSQL 7.4
doing multiple connects/disconnects within the same
server (AMD 1.2GHz, 512MB, Linux 2.4). If forking is
the issue then pre-forking will give a big boost
especially for simple queries:
MySQL time
----------
0.012786865234375
0.011546850204468
0.01167106628418
<?php
$time_start = getmicrotime();
for ($i = 0; $i < 20; $i++) { $DBH = mysql_connect('127.0.0.1'); mysql_select_db('test1');
mysql_close($DBH);
}
$Time = getmicrotime() - $time_start;
?>
MySQL time (with simple query)
------------------------------
0.015650987625122
0.01443886756897
0.014433860778809
<?php
$time_start = getmicrotime();
for ($i = 0; $i < 20; $i++) { $DBH = mysql_connect('127.0.0.1'); mysql_select_db('test1');$Res =
mysql_query('SELECT* FROM table1 WHERE id =
1', $DBH); mysql_close($DBH);
}
$Time = getmicrotime() - $time_start;
?>
PostgreSQL time
---------------
0.15319013595581
0.14930582046509
0.14920592308044
<?php
$time_start = getmicrotime();
for ($i = 0; $i < 20; $i++) { $DBH = pg_connect('dbname=test1
host=127.0.0.1'); pg_close($DBH);
}
$Time = getmicrotime() - $time_start;
?>
PostgreSQL time (with simple query)
------------------------------------
0.19016313552856
0.18785095214844
0.18786096572876
<?php
$time_start = getmicrotime();
for ($i = 0; $i < 20; $i++) { $DBH = pg_connect('dbname=test1
host=127.0.0.1');$Res = pg_query($DBH, 'SELECT * FROM table1 WHERE id
= 1'); pg_close($DBH);
}
$Time = getmicrotime() - $time_start;
?>
__________________________________
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs
http://hotjobs.sweepstakes.yahoo.com/careermakeover