Scalability of a php application
I built my application using cakephp. It works fine. My application still in beta with 3000 beta users(invites based). I am want to expand it for bigger end user base.
Few things about my app.
1) I am using mysql database table has around ~ 25000 records. 2) Multiple models and many multiple hasMany and belongsTo and HABTM relationships
First Question. 1) How I can I improve my site performance. 2) What is result limit from queries on the database(10s). 4) Should I move application to newer technology or framework.
The number of records and relationships are growing.
I started app in cakephp less than three months back with little (MVC) knowledge. It is amazing easy to开发者_如何学运维 build and test applications. I would recommend it to friends anyday.
I appreciate any help.
Thanks.
How I can I improve my site performance?
Hard to say without knowing where the bottleneck is. One approach would be to:
Start by optimising your SQL queries, enable slow query logging and examine them, properly index columns, and change SQL server's configuration if needed.
Profile PHP execution, analyse report and make sure to refactor the code where needed.
Introduce caching, flat files, SQL caching, APC, Memcache etc. (just don't use all of them together :)
Optimize server configuration, including software and hardware.
Move to several servers.
What is result limit from queries on the database(10s)?
You mean execution time? As fast as possible :) But then again, depends on the query itself. If the query is executed once every day, it can be slower than if it is executed with every request. Time depends on first question/answer above.
Should I move application to newer technology or framework?
This one is hard to answer. Again, depends on what the problems are and whether you can identify and fix them. If you can solve them by optimizing queries and database, caching etc., then the problem is not in the framework. I strongly advise to think about it thoroughly before switching to another technology or rewriting the code.
A quick google search resulted in the following sites, all dedicated to speeding CakePHP up considerably. In addition, here are my thoughts on Cake's speed:
- Make sure you're using the latest Cake release. The update from Cake 1.2 to 1.3 yielded about a 20% speed boost for my biggest app.
- Make sure you have caching turned on (for most read-intense applications, this will help massively).
- If you have a LOT of models that are related, but infrequently used, try loading those models lazily.
Remember that Cake isn't really built for speed. The other answers here are good for generic situations, but with CakePHP, the bottleneck is usually with the web layer. So one (fairly simple) way to scale out is to load your pages through a proxy server that passes requests to a backend processing farm.
Also, I highly recommend that you profile your code. This means using an IDE like Zend, where you can insert breakpoints to determine the slow sections of your code. At a minimum, install the Cake debug toolbar, which will show you execution times for major sections of your app (request handler loading, controller execution, view render time, etc.)
Results for google search on "optimizing CakePHP for speed":
Good CakePHP specific tips: http://www.endyourif.com/optimizing-cakephp-websites/
Lazy Load models: http://bakery.cakephp.org/articles/Frank/2010/08/10/optimizing-model-loading-with-lazymodel
- More Cake Tips: http://www.pseudocoder.com/archives/2009/03/17/8-ways-to-speed-up-cakephp-apps/
精彩评论