Sign up

This page looks plain and unstyled because you're using a non-standard compliant browser. To see it in its best form, please upgrade to a browser that supports web standards. It's free and painless.

FreeBSD 7, Apache 2, PHP 5, Mysql 5 optimize

About configuration

This post was redacted with at least this configuration in mind:

Of course, it may be usable for other configurations, or give elements to think about.

MySQL performances

Under FreeBSD and not under GNU/Linux, performances drop down where there are too many simultaneous connections. With my 1.8 GHz Celeron and 1.2 MB RAM, I can't go over 30 simultaneous connections without blocking the computer.

This issue seems to be fixed with FreeBSD 7.0, but it may be possible to attenuate it with previous versions.

Here are some ideas:

MPM and PHP

Since version 2, Apache support many distinct MPM. The most often used are the following ones:

If you read the previous list, you will want to use worker MPM: less slower, better memory usage, why hesitate ? the problem is that PHP only support prefork MPM, and nothing is guaranteed with worker MPM. It's may work, but it may not. In my case, it perfectly worked with PHP 5.0.x, but didn't worked with PHP 5.1.x. Related symptoms were session lost or blank pages.

Then if you don't want to prematurely loose your hairs, only use prefork MPM. So you may want to stay with Apache 1.3, and you're right. But remember, one day, this version will be obsolete and not supported anymore, and sooner than version 2.0.

PHP and MySQL

You have to ways to connect to a MySQL database: persistent connections, and non persistent connections. A persistent connection is a connection which will stay open until it's explicitly closed (with the related function or when the script ends). If may be useful if you don't want to lose time waiting to open connection again when you need it, but if you have too many simultaneous connexions the MyQSL service may be overloaded.
A non persistent connection is a connection which is open and close each time a query is sent to MySQL. Connection open and close functions are only here to create the variable used to manage the connexion. Unlike persistent connection, you have a slight overhead due to connection opening and closing, but it may be unnoticeable (unless your scripts need to often execute queries). In non persistent connection case, the server will be less often overloaded while getting many simultaneous connections.
In order to disable persistent connections with PHP, you have to set the parameter "mysql.allow_persistent" to "Off" into "/usr/local/etc/php.ini" file.

PHP and memory usage

It may be evident to you, but PHP is memory hungry. After a few quick tries, an Apache process use 7 MB without PHP, and 20 MB with PHP. And don't forget: more you have connections, more you have open Apache processes. With 20 MB per processes, memory usage will grow quickly.

In order to avoid important memory usage, only install PHP modules you need. And if you have problems with a module, you will loose less time to find which one is guilty with few modules than with many. When I write about problems with a module, I mean this: I open a page with use no function from this module, but Apache crashes with an error code 11. If you want to find the guilty module, disable all modules one by one, then restart Apache and reload the page until Apache doesn't crash anymore.

PHP and performances.

PHP is an interpreted language. This means each time a PHP script is opened and executed, PHP engine will need to check the syntax, compile it to a semi-native language ( called "bytecode"), then execute it. For only one PHP script, this syntax check then compilation dedicated time is invisible to the user. But when the web server has to treat hundreds of PHP script within a second, this overhead may be too important.

If you want to accelerate things, there are tools called "PHP accelerators" which optimize PHP scripts loading. When a PHP script is open for the first time, the syntax is checked, it's compiled to bytecode in an optimized may, and this bytecode is saved then executed. Then, each time this script is asked for, PHP engine will use the previously generated bytecode. This time gain may be appreciable.

There are many PHP accelerator. The most known are:

I first tried eAccelerator, but had some issues with: cache was not updated, some session loose, etc. With ZendOptimizer, I still have these issues, but less often. Then I don't use any of them.

If you want to use a PHP accelerator, you can accelerate ZendOptimizer if you don't use files protected by ZendGuard. You just have to add into "/usr/local/etc/php.ini" file, within ZendOptimizer section, the following lines:

zend_optimizer.enable_loader=0
zend_optimizer.disable_licensing=0

Apache and AcceptFilter

AcceptFilter is a feature based on kernel options used to optimize HTTP connections (see "accf_http" kernel module for FreeBSD). Said like that, it looks good. But I'm really not convinced: processes memory usage grow (45 MB memory usage per process), processes are opened but never closed (which does not help with memory usage). The only good thing is, when system was not overloaded, that connections seemed to answer quicker. Then disable AcceptFilter. With FreeBSD, it's easy: just add a line

apache22_http_accept_enable="NO"

into "/etc/rc.conf" ("apache22" may change depending the version you use).

Apache and connections limitation.

I just come back to memory use with some trick to avoid server overload:

Conclusion

I hope these tricks will be useful to you. There are not perfect one because they come from empiric experience


Nguồn: http://goddess-gate.com/dc2/index.php/post/255

Viết bởi freebsd, 03 October 2008 09:46 | Optimize | Góp ý (0) | Đường dẫn cố định | Trackbacks (0) | Bản inBản in

Thêm góp ý
Thêm góp ý
(http://tenban.vnweblogs.com)
 authimage (Hãy nhập dãy số này vào ô bên cạnh)
Powered by vnWeblogs
Valid XHTML 1.0 Strict - Valid CSS