Initializing
Initialize the mysql database from a previous dump as I did earlier.
1 2 3 4 5 6 7 8 9 10 11 |
/etc/init.d/mysql start mysql -e 'show databases' [root@localhost ~]# mysql -e 'show databases' +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ |
1 2 |
mysql -e 'create database gumibomba_dev' mysql gumibomba_dev < import.sql |
Install PHP and Symfony 1.2
Unlike previous test subjects php doesn’t come with the default linux install. So first of all we need some php package. Because php doesn’t have such tool like Perl’s CPAN or Python’s easy_intall we’re going to install everything with yum. (This is not completely true. PHP has PEAR and Pecl too for installing third party libraries but not for all php modules)
In the default 6.2 CentOS packages we don’t have php-fpm which we will neeed if we want to be objective and use nginx webserver for serving php test sites. One way to do this is we have to find a third party repository where the neccecary packages are maintained. The other way it to compile php from source. I like this way better because php package depends on httpd (apache) package which I really don’t need at all. But feel free to choose whatever options you like.
Compile from source:
1 2 3 |
# ./configure --enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data --with-zlib --enable-mbstring --enable-pdo --with-pdo-mysql --with-curl --disable-debug --disable-rpath --disable-inline-optimization --with-bz2 --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --with-mhash --with-xsl --enable-zip --with-pcre-regex --enable-calendar --enable-ctype --disable-dba --enable-dom --enable-exif --with-gd --enable-mbstring --enable-soap --with-jpeg-dir=/usr/include --with-png-dir=/usr/include --with-mysql --disable-phar --with-libdir=lib64 # make # make install |
First steps
1 2 |
# mkdir /var/www/html/sandbox # cd /var/www/html/sandbox |
1 2 |
# symfony generate:project sandbox # symfony generate:app frontend |
Set up php-fpm and nginx and now we can see our default symfony front page.
Import schema from model
This is very easy to do after we set the config/databases.yml and config/propel.ini correctly. Just put these in command line and symfony will generate all the configs and models you will need.
1 2 3 4 |
# symfony propel:build-schema # symfony propel:build-model # symfony propel:build-form # symfony propel:build-filter |
Start our first application
We need an action ( controller ) and the regarding templates to create the pages for the test.
The action class:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# cat apps/frontend/modules/gumi/actions/actions.class.php <?php /** * gumi actions. * * @package sandbox * @subpackage gumi * @author Your name here * @version SVN: $Id: actions.class.php 12479 2008-10-31 10:54:40Z fabien $ */ class gumiActions extends sfActions { /** * Executes index action * * @param sfRequest $request A request object */ public function executeIndex(sfWebRequest $request) { $c = new Criteria(); $c->setLimit(10); $this->gumis = GumiPeer::doSelect($c); return sfView::SUCCESS; } public function executeShow(sfWebRequest $request) { $this->gumi = GumiPeer::retrieveByPk($request->getParameter('id')); $this->forward404Unless($this->gumi); return sfView::SUCCESS; } } |
Really simple, really easy.
Templates
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# cat apps/frontend/modules/gumi/templates/indexSuccess.php <table> <thead> <tr> <th>Márka</th> <th>Típus</th> </tr> </thead> <?php foreach($gumis as $gumi): ?> <tr> <td><?php echo $gumi->getGMarka() ?></td> <td><?php echo $gumi->getGTipus() ?></td> <td><a href="<?php echo url_for('gumi/show?id='.$gumi->getGId()) ?>">Show</a></td> </tr> <?php endforeach; ?> </table> |
1 2 3 4 5 |
# cat apps/frontend/modules/gumi/templates/showSuccess.php <h1> <?php echo $gumi->getGMarka() ?> <?php echo $gumi->getGMarka() ?> </h1> |
Nginx and FastCGI
I used fastcgi process manager (phpFPM) to do this. This is able to start new processes when it’s needed. Something similar as apache prefork model. The sample configuration for nginx can be downloaded from either nginx’s or symfony’s website.
Results
The results was more then below expected. And the box was overloaded already at 20 concurrent ab threads. The average process consumed 2.2% of memory which means around 13MB. That sounds really good until you find out that php-fpm will spawn a new process for almost every concurrent thread. After about 40 process the memory became full and the box started to swap. Of course I can limit the number of max children in php-fpm.conf but if I did this the number of failing requests increased and the request/sec rate dropped down significantly. At maximum 20 children the load was 13,27 and at maximum 50 children the load went up to 21,59.
Index | Show | |
AB 5 conc | 24,29 | 23,77 |
AB 20 conc | 23,81 | 23,6 |
AB 50 conc | 23,75 | 23,67 |
Memory usage | 2,20% per thread | 2,20% per thread |
CPU usage | 100,00% | 100,00% |
Summary »
Recent comments