Building a private virtual server

People often look for the 'magic tune-up' that will make their system perform four times as fast by tweaking just one little setting. The truth is, present-day UNIX derivatives are pretty well adjusted straight out of the box and there is not a lot that needs to be done to make them perform optimally. However, there are a few things that an administrator can do to improve performance.

Backported PostgreSQL in Debian
http://pgapt.debian.net/

Integrating APC (Alternative PHP Cache) Into PHP5 (Debian Etch & Apache2)
http://www.howtoforge.com/apc-php5-apache2-debian-etch

Increasing the size of the Linux shared memory segment
http://www.msi.umn.edu/~cpsosa/ChemApps/QuaChem/gaussian_tech/support/download/Linux_shared_mem_seg.html

Checkpoints and the Background Writer
http://www.westnet.com/~gsmith/content/postgresql/chkp-bgw-83.htm

Tuning Your PostgreSQL Server
http://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server 

HTTPD - Performance Optimization: Scaling Up
http://wiki.apache.org/httpd/PerformanceScalingUp

Postgresql configuration

Ensure you have configured the database system iteself before tuning other processes.

User pgtuner as follows to determine settings for 120 max_connections

./pgtune -D -c 120 -i postgresql.conf -o postgresql.conf.tuned

Then modify the /etc/sysctl.conf and update the kernel shared memory limits

kernel.shmmax=891289600<br /> kernel.shmall=891289600

pgbouncer

apt-get install pgbouncer
vim /etc/pgbouncer/pgbouncer.ini

;; database name = connect string<br />[databases]<br />* = host=127.0.0.1 port=5432<br /><br />;; Configuation section<br />[pgbouncer]<br /><br />logfile = /var/log/postgresql/pgbouncer.log<br />pidfile = /var/run/postgresql/pgbouncer.pid<br />listen_addr = 127.0.0.1<br />listen_port = 6543<br />unix_socket_dir = /tmp<br />auth_type = trust<br />auth_file = /etc/pgbouncer/userlist.txt<br />admin_users = postgres<br />stats_users = postgres<br /><br />; When server connection is released back to pool:<br />;&nbsp;&nbsp; session&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - after client disconnects<br />;&nbsp;&nbsp; transaction&nbsp; - after transaction finishes<br />;&nbsp;&nbsp; statement&nbsp;&nbsp;&nbsp; - after statement finishes<br />pool_mode = session<br />server_reset_query = DISCARD ALL;<br />server_check_query = select 1<br />server_check_delay = 10<br /><br />max_client_conn = 100<br />default_pool_size = 100<br />log_connections = 1<br />log_disconnections = 1<br />log_pooler_errors = 1<br /><br />ignore_startup_parameters = application_name,extra_float_digits

Add the postgresql database users you wish to use with pgbouncer in "username"|"password" format.

vim /etc/pgbouncer/userlist.ini

Ensure postgres owns pgbouncer

chown -R postgres:postgres /usr/sbin/pgbouncer

Start pgbouncer

/usr/sbin/pgbouncer -d /etc/pgbouncer/pgbouncer.ini

Use netstat to see it listening on our specified port:

netstat -tlnp

Tail the log to see it working (you will need to configure an app to use the correct port and user as per configuration).

tail -f -n 20 /var/log/postgresql/pgbouncer.log

Optimizing Apache Server using static asset vhost

http://omniti.com/seeds/yslow-to-yfast-in-45-minutes
http://lethargy.org/~jesus/misc/webperformancebootcamp.pdf

Extending Privilege Separation
http://wiki.apache.org/httpd/ExtendingPrivilegeSeparation

Recommended reading

Design by Jon