Accelerate your LAMP


When your LAMP application is slow, you might choose to upgrade the processor and adding more RAM. It is call scale up.

There are other solutions to accelerate fulfill different bottleneck. I am also learning this topic and will update when I found more related useful information.

Repeating Generating the Same Page

If your web page doesn’t change, a cache may save your time by reducing CPU generate the same page over and over again. Some LAMP applications, eg. WordPress, have cache plugin. Others may use an external solution like Varnish Cache.

But if your content is always changing or needs the latest information, eg ZurmoCRM, cache doesn’t help much.

Here are some useful posts about this topic:

  1. Four Nines: Improving page speed: CDN vs Squid/Varnish/nginx/mod_proxy
  2. OpenLogic: Varnish improves web performance and security
  3. Varnish Cache
  4. WordPress.org: Codex: WordPress Optimization/Caching

Geographic Latency

If you need to serve customers in different geographic locations, Content delivery network aka CDN may help. Cached content will be deliver from local CDN provider which not only reduce network latency but also save your bandwidth. Wiki explains what can be cache:

CDNs serve a large fraction of the Internet content today, including web objects (text, graphics and scripts), downloadable objects (media files, software, documents), applications (e-commerce, portals), live streaming media, on-demand streaming media, and social networks.

Unlike cache, if you need real-time data or your content is always changing, eg ZurmoCRM, it may still help reduce network latency on cached content.

BTW, CDN service is not available everywhere. Check before you choose.

Here are some useful posts about this topic:

  1. Amazon CloudFront
  2. Four Nines: Improving page speed: CDN vs Squid/Varnish/nginx/mod_proxy
  3. 运维之道:web网站加速之CDN(Content Delivery Network)技术原理
  4. 軟體玩家:免費的雲端加速網站代理服務—CloudFlare,讓你的網站變得又快又安全!

PHP High CPU Usage

If you are using PHP as an Apache module, you may try to use FastCGI which has better resource usage. Another reason to adopt FastCGI is security especially when you run more than one LAMP applications with the same Apache. They will be execute as the file owner of the application folder in FastCGI which helps preventing file and folder access violation and easier to debug.

More detail about security can be found in [resolved] php support: fastcgi or apache module:

Often enough you have to tweak file permissions because WordPress runs as the Apache user instead of the user who owns the files on your install. So a quick 777 will fix it – but that’s no good for security.

The other option is to have files and folders owned by Apache, but that makes finding an exploit more difficult because 1000 sites could be owned (and compromised) by the same user i.e. Apache. In fact, if WordPress needs a new folder it will be created as owned by Apache, if you run PHP as Apache Module.

So if you run PHP as FastCGI then it’ll be created as the “your user” rather than Apache. It also means WordPress has write permissions to all files because it’s executed as “you user” rather than Apache. All that together means FastCGI – on paper – sounds like the dream solution.

Here are some useful posts about this topic:

  1. StackOverflow: Is FastCgi thread-safe?
  2. StackOverflow: mod_php vs cgi vs fast-cgi
  3. The WP Guru: FIXED: The Problem with running PHP as FastCGI Application (WordPress and Plesk)
  4. WordPress.org: Forums: [resolved] php support: fastcgi or apache module?

Slow Database

If you have only one MySQL and found it slow to respond, try to upgrade to MySQL Cluster CGE or MySQL NDB Cluster. The later is explained very clearly in O’reilly Answers: What Is MySQL Cluster?

MySQL Cluster is a database system that uses the MySQL server as the frontend to support standard SQL queries. A storage engine named NDBcluster is the interface that links the MySQL server with the cluster technology. This relationship is often confused. You cannot use the NDBcluster storage engine without the NDB Cluster components. However, is it is possible to use the NDB Cluster technologies without the MySQL server, but this requires lower-level programming with the NDB API.

Here are some useful posts about this topic:

  1. everything about machines: Howto setup mysql-cluster (beginners tutorial)
  2. Hello World: MySQL Cluster 安裝筆記
  3. iThome: 痞客邦導入MySQL 檢索1億張照片也沒問題
  4. Neo’s Blog: MySQL Cluster 叢集安裝環境介紹
  5. O’reilly Answers: What Is MySQL Cluster?
  6. 大熊先生:Mysql在大型网站的应用架构演变

You might also want to try MySQL query cache technique. Increase MySQL performance with query cache query_cache on Go2Linux is worth reading. There are even more tweaking may be found on following post and slides:

  1. ZONE Forums: MySQL Server Tweaking Basics
  2. SlideShare: Linux performance tuning & stabilization tips (mysqlconf2010) by Yoshinori Matsunobu

Load Balance

If the server is heavy load, you may setup other servers pointing to the same database server and use load balancing to share loading. There are physical load balancer and software, eg. Varnish.

Here are some useful posts about this topic:

  1. OpenLogic: Varnish improves web performance and security
  2. Varnish Cache

Reference

  1. Amazon Web Services: Amazon CloudFront
  2. Apache
  3. everything about machines: Howto setup mysql-cluster (beginners tutorial)
  4. FastCGI
  5. Four Nines: Improving page speed: CDN vs Squid/Varnish/nginx/mod_proxy
  6. Go2Linux: Increase MySQL performance with query cache query_cache
  7. Hello World: MySQL Cluster 安裝筆記
  8. iThome: 痞客邦導入MySQL 檢索1億張照片也沒問題
  9. MySQL
  10. MySQL: MySQL Cluster CGE
  11. Neo’s Blog: MySQL Cluster 叢集安裝環境介紹
  12. O’reilly Answers: What Is MySQL Cluster?
  13. OpenLogic: Varnish improves web performance and security
  14. PHP.net
  15. SlideShare: Linux performance tuning & stabilization tips (mysqlconf2010) by Yoshinori Matsunobu
  16. StackOverflow: Is FastCgi thread-safe?
  17. StackOverflow: mod_php vs cgi vs fast-cgi
  18. The WP Guru: FIXED: The Problem with running PHP as FastCGI Application (WordPress and Plesk)
  19. Varnish Cache
  20. Wiki: Content delivery network
  21. Wiki: LAMP (software bundle)
  22. Wiki: Load balancing (computing)
  23. Wiki: NJDB Cluster: 2 MySQL Cluster (Ndb Cluster + MySQL Server(s))
  24. Wiki: Scalability: 3 Horizontal and vertical scaling
  25. WordPress.org
  26. WordPress.org: Codex: WordPress Optimization/Caching
  27. WordPress.org: Forums: [resolved] php support: fastcgi or apache module?
  28. ZONE Forums: MySQL Server Tweaking Basics
  29. Zurmo.org
  30. 运维之道:web网站加速之CDN(Content Delivery Network)技术原理
  31. 大熊先生:Mysql在大型网站的应用架构演变
  32. 軟體玩家:免費的雲端加速網站代理服務—CloudFlare,讓你的網站變得又快又安全!

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.