Click to See Complete Forum and Search --> : Caching Some Thoughts


Buddha443556
03-28-2004, 01:53 PM
Have you noticed caching has becoming more and more prominent lately? I've been thinking about caching a lot lately and here are some of my thoughts on the subject.

What are the bottlenecks? Where is a PHP script slowed down?

Hardware:

Network
Hard Drive
Memory/Bus
CPU


Software:

Script
MySQL
PHP
Apache
OS

How does caching help eliminate these bottlenecks?

First by consolidating hard drive operations. Every included file is a hard drive operation. Consolidating included files means PHP is only compiling one file instead of two or even more.

Second by eliminating database queries. Every database query is a network/harddrive/Memory/CPU operation. Eliminating multiple database queries will eliminate the associate bottlenecks.

Third, by eliminating script processing. Static HTML is fast even going through the PHP engine.

Last, but the least obvious, by optimizing your code on a per page basis. Hmm... so if we can figure out how to do the first two or three ourselves maybe caching wouldn't be neccessary?

So why do we see caching turning up all over the place?

I think there is a trend happening, we started out programming every page as an individual entity. But somehow we are no longer programming pages but applications. The problem with this is PHP is still doing the something it always has - rendering a single page at a time. I'm I wrong?

PHP is still a scripting language, correct?

Read script
compile script to bytecode
execute bytecode/get another script/output some of the page

However, we are no longer treating it as a interpreted language but a compiled language. Which would definitely be wrong, yes? PHP only sees a page at a time everything else is just dead weight.

So what are your thoughts?

[ Moderators - I put this topic here because I have no idea where to put it? ]

laserlight
03-28-2004, 10:22 PM
Well, what's your definition of a scripting language?

Weedpacket
03-29-2004, 03:33 AM
"Aerodynamics is for people who can't design good engines."
Enzo Ferrari.

I'm also reminded of the wheel of reincarnation (http://www.catb.org/~esr/jargon/html/W/wheel-of-reincarnation.html), and research developments into such things as "processing-in-memory" and "processing-in-wire", where memory chips (and latterly, wires) also contain processing elements.

Buddha443556
03-29-2004, 07:28 AM
Originally posted by laserlight
Well, what's your definition of a scripting language? Here I mean we are dealing with a language (PHP) in which the source code is interpreted at run time and no application code is produced.

Buddha443556
03-29-2004, 07:34 AM
Originally posted by Weedpacket
"Aerodynamics is for people who can't design good engines."
Enzo Ferrari.Guess I've been looking at too many bad engine designs.

Shrike
03-29-2004, 08:00 AM
Also reminds me of the reason the Gang of Four wrote their design patterns book (have yet to read it though)

www.phppatterns.com

I'm not sure that PHP's interpreter can really be considered a bottleneck as in the other things. Interpreted languages are faster to develop with, compiled languages need no interpretation, it's a simple trade off.

I would only ever consider caching when creating images or generating a long page of database records.

One of the biggest slowdowns I've come across is when heavily using the PHP regexp engine. I think that can be solved with careful regexp creation though (which I don't do :p )

Buddha443556
03-29-2004, 09:13 AM
Originally posted by Shrike
Also reminds me of the reason the Gang of Four wrote their design patterns book (have yet to read it though)

www.phppatterns.comHaven't read it either but I've been to the site more than once.

Originally posted by Shrike I'm not sure that PHP's interpreter can really be considered a bottleneck as in the other things. Interpreted languages are faster to develop with, compiled languages need no interpretation, it's a simple trade off.That was an ordered list, starting with the worse and getting better. PHP is very fast. I don't think it's the problem. I think many problem are created by skipping the design stage in rush to code. Coding is the fun part I guess? I always thought programming was 99% thought and 1% effort? As always, I could be wrong.

Originally posted by Shrike I would only ever consider caching when creating images or generating a long page of database records.

One of the biggest slowdowns I've come across is when heavily using the PHP regexp engine. I think that can be solved with careful regexp creation though (which I don't do :p ) If those regexp are in a database query it's even worse.

Biggest slowdown for me is over thinking the problem. :D

Shrike
03-29-2004, 09:16 AM
Agreed. Even just 15 minutes with a notepad and pencil (and eraser!) is a great way to start even a short piece of code.

Weedpacket
03-30-2004, 04:12 AM
Originally posted by Buddha443556
Guess I've been looking at too many bad engine designs. Cf: any modern Ferrari.