I question I see a lot on the CakePHP mailing list is “can CakePHP scale?”. Now, other than this being an incredibly general statement it got me to thinking about scalability. In many ways the issue is like security: developers expect security to be “built into the application” when time and time again it has been pointed out that security is the responsibility of the developer, not the language itself. If you don’t make sure to filter your input and escape your output, well, who’s fault is that really? Yes, I know there are cool things like the filter extension for PHP and that many frameworks have helpers that can automagically filter your input. But that’s still code written by someone else that HAS TO BE USED.
So, what does this have to do with scaling? Well, let’s look at it from several different perspectives. At the language level, it has been proven that PHP’s shared-nothing tendencies mean that it is suited to what I call horizontal scaling, where you add more web servers running PHP on them. No need for a central chokepoint means you can scale by simply adding more servers. It’s really that simple.
Now, once you start adding in shared resources (like a database or centralized session storage) the problem ceases to be PHP’s and becomes the problem of the developer. Why? Because now you have to write your application (or components of your application) with these shared resources in mind. You’re now involving resources OTHER than PHP in the equation as well. Say you have a centralized database and multiple application servers. Is the ratio of reads to writes high enough that response time to the database server will be low enough to not impact application performance? If you use replication, is replication lag going to kill you? All these questions are beyond the scope of PHP.
During my talk at php|tek I got asked if I thought that adding a framework to your code meant unnecessary overhead. Unfortunately, the answer is “it depends, but I try not to worry about it”. The reason for this wishy-washy answer is that I find that when you start using a framework, you can stop using custom code for low-level things and instead use whatever the framework is using (like DB access or form creation helpers). You gain in speed because, well, you don’t have to write those things, you just have to learn how to use them. The trade-off is developer speed vs. application speed, but there are things you can to increase application speed: output caching, opcode caching, data partitioning, server tweaking. Again, all those things are not done in PHP-land.
So, looking at the above I think it’s pretty obvious that scaling is not the responsibility of PHP (or a framework in this case) but the responsibility of the developer. When you are building an application, you need to be mindful of the actual design so that when the time comes you will be able to scale horizontally by adding more servers or you can scale vertically (moving functionality around to different levels of your application) with minimal headaches. Having been through this on an adult dating site, I can say without a doubt that trying to scale your application after the fact just doesn’t work. Do your homework, understand the problem, and don’t ask if a framework can scale. Ask yourself if you know how to build a scalable application in the first place.


Every time I see the “Does cake scale?” question come up on the google group mailing list…I die a little inside.
So, I guess the (more) proper question then is, does Cake PHP have any specific features that make it easier (or harder) for the developer to write a scalable application?
(and I’m seriously asking, not just poking a stick at you… cheers
@Brent – Well, CakePHP does have caching for views *and* hooks for caching content (or anything else you can think of) with a variety of engines (like filesystem or memcache or Alternative PHP Cache). But I think the point I’m trying to make is that “does it scale” is too generic a term. Instead you should be figuring out what needs to happen for your application to scale and then seeing what tools exist to make that happen. If Mozilla has seen fit to use CakePHP as the engine behind it’s Addon site, I feel comfortable telling people that if they use the technology available to them that you can build a scalable app (both horizontally and vertically) using CakePHP.
Have nothing to add other than – the new WP theme is cool !
Hi,
I agree with you for the most part. I’m currently using 1.2 and it does have a lot of great performance features.
I would say that the framework can definitely directly affect an app’s performance and scalability. I’ll admit I’m a total ORM newbie. So questions are bound to come up time and time again about how much overhead there is using cake’s ORM layer or whatever else. Why would you even need ORM if you’re using stored procedures? Before using MySQL, my previous DB experience was writing Sybase stored procedures. I plan on using them when we implement MySQL 5.1. Why because I know stored proc’s can improve performance from 10 to one thousand percent! I purposely spelled out the 1000 to emphasize that it’s not a typo. We have approx. 240 tables – so ORM may not make sense.
One thing I’ve noticed when reading responses to performance and scalability question, is how defensive people get. The best way to squash performance questions is to prove it and communicate it via the manual. Get testimonials from companies stating that cake scales – IMHO
When I first started using cake I was wondering if DESCRIBE was always being called even if DEBUG was set to 0. I had to search through the newsgroup for the answer – that it wasn’t.
As a newbie, I don’t know all of the in and outs of the framework – especially when and when not to use / do things such as when to use requestAction. Only the “seasoned” bakers and the cake architects would know all the nuisances / performance tricks. I spend a lot of time reading posts and replies, as well as checking out code in CakeForge for “best practices”.
Every framework it’s pushing its 5 min. tutorial on how to create a “simple” blog. Create a real world example using hardcore validation, sanitization, special character handling etc. Some of the code I’ve seen is just propagating PHP’s rep as being insecure. For example:
function edit($id)
{
$this->User->id = $id; // like WTF!
}
That’s my 2 cents! And I will continue baking until I too can qualify as a Chef. I’m dying for 1.2 to get out of the oven and onto the dining table.
Here’s an example of how the framework affects performance and therefore scaling, “But, it’s getting crazy; 50-100 queries
(unbind isn’t helpful as I need the relevant data) often force me to
handcode the queries.” – http://groups.google.com/group/cake-php/browse_thread/thread/b97c38e4c36fc781
@beth
I think there are few unanswered questions in that email:
1) what debug level is he on, because debug = 2 generates a lot of stuff that is cached by the application itself
2) there is the actual chance that *gasp* his approach is wrong.
Also, a newer version of Cake 1.2.x.x has a patch that got rid of a lot of extra queries. All I’m saying is that you need to be aware of how the framework handles a particular problem before you start crying “framework affects performance”. I have never seen Cake do more than 4 or 5 queries to pull the data I wanted.