1

(I'm using Google Translate).

Currently developing a system of vehicles (30,000 vehicles, 10 000 users), and during this period only ran tests on the local environment.

Here then came the problem: when I sent to Cloud Server, mysql now consume 100 ~ 140% of the processing, making it the site falling around 5 ~ 30 minutes.

I do not know how to solve this problem, in order that I could not identify him because until then everything was on localhost.

And my question is just this: how can a system overload to the point using a CakePHP application?

Some basic information about the tables:

Customers -> contract -> Plans -> ads

ads -> (vehicles, parts, services)

vehicles -> (brand, model, version, category, color, fuel)

banners -> banners channels -> local banners

Information regarding the application:

debug: 0 caching enabled (10-1 hour per page *)

hakre
  • 193,403
  • 52
  • 435
  • 836
Patrick Maciel
  • 4,874
  • 8
  • 40
  • 80

3 Answers3

5

In my own experience running heavy apps with CakePHP and MySQL (more than 250 tables) the bottleneck reside in a bad use of the CakePHP ORM.

Sometimes, you will fetch a lot more datas than you need.

find('all') function associated to high recursive value looks cool and speed up the development time.

But in fact, this can be really awful, especially when your app and database is growing. The number of associated models will grow too, fetching recursively more and more datas.

A good practice is to always specify the fields you need. Also, for spectific queries, you should unbind associated models you don't need.

For complex queries, don't hesitate to write optimized queries by hand, using the query() function.

In developpment, you should enable CakePHP debug mode for profiling SQL queries in your Config/core.php file : Configure::write('debug', 2); This will help you to find the slowest.

Optimizing your queries is the first step. If this doesn't solve your issue, your database is maybe not well designed.

In addition, you should use an opcode cache in production, such as APC or XCache.

Adrien Schuler
  • 2,395
  • 1
  • 21
  • 32
  • 3
    Check out `ContainableBehavior` which helps handle the recursive and model bindings for you. – jeremyharris Apr 06 '12 at 06:17
  • 2
    +1 You should start with `var $recursive = -1;` in every model. – Henri Apr 06 '12 at 06:26
  • This is one of the main reason why I never used cake. – Shiplu Mokaddim Apr 06 '12 at 19:00
  • 1
    One of the main reasons you don't use cake is because you have to optimize your use of the db / orm? -- How is that different from any other framework? I have bogged down almost every framework there is - please tell me what *you* use instead that doesn't require the exact same level of consideration towards performance. – Abba Bryant Apr 06 '12 at 20:54
  • debug, recursive, cache ... All these attributes are setados correctly. Checked that at least 10 times. Actually I could not solve, and to make matters worse, a 'freelancer' is now taking over the project and said the solution is to use Zend + Doctrine + Smarty, and if it will work because I do not know. – Patrick Maciel Apr 08 '12 at 18:23
  • @jeremyharris , I checked ContainableBehavior, but somehow this does not help me much because I have no knowledge as an expert in CakePHP about to make a change or just a routine change to give rise to any positive results. Anyway, thanks for help. – Patrick Maciel Apr 08 '12 at 18:27
  • @Henri, in most controllers / models, I used the recursive -1 to avoid further problems, but this did not solve. Some queries are spending 16-80 seconds to run. And this because the site's homepage, there are "only" 13 queries that are executed every 1am due to caching. However, during search, or view a vehicle or another, the server processing takes around 140% – Patrick Maciel Apr 08 '12 at 18:32
  • @shiplu.mokadd.im , right, but what problems you had, what solutions you found, and in what cases? Only you tell me this, since it helps me to have a base, and the principal: how long works or has worked with CakePHP? (And which version). – Patrick Maciel Apr 08 '12 at 18:34
2

If you really want to know why its too slow, do this,

  1. Equip Apache JMeter to generate the load
  2. Enable profiling your web app by xdebug
  3. Profile your web server too.

If you want to make it fast read on Tactics for using PHP in a high-load site

Community
  • 1
  • 1
Shiplu Mokaddim
  • 56,364
  • 17
  • 141
  • 187
2

This book by Matt Curry might be helpful:

http://www.pseudocoder.com/Super_Awesome_Advanced_CakePHP_Tips.pdf

@ Page 54 -> "Make Your Cake App Fast"

Henri
  • 740
  • 10
  • 22
  • thanks my friend, I'll read them and test, but now, someone else is responsible for the project, and this will use Doctrine + Smarty + Zend, and will redo the entire application. – Patrick Maciel Apr 08 '12 at 18:49