Whoever left the anonymous comment yesterday, SHOW YOURSELF! Actually, they made a good point.

"How can the scripting be better if it's CPU intensive?"

Good question. Here's the answer.

In general, Tabulas was a hodgepodge of different scripting styles with various "global" variables being used. This meant that things were not consistent when you looked at code; your userid variable should be stored as one variable throughout the site; it was stored as two previously.

Now, specifically regarding the entry display engine, I had to rewrite it because it was a mess. There was one massive function that specifically handled displaying entries. It was over 600 lines long. This made troubleshooting that function almost impossible.

Now, I split up the function (as described) into two logical functions: the first one determined which entryids to pull based on your privacy settings, while the second one took an array of entryids and displayed them.

Now, although this is a cleaner and more logical method of doing things, there is an extra layer of abstraction; before the entryids and display were on one layer. However, now the database is (essentially) hit twice; once to determine the IDs and once to grab those entry based on their entryid.

However, both of these queries are extremely fast; I've tried to minimize the amount of work the database has to do.

You see, when you develop database-driven sites, there are two primary methods of handling the workload:

1.) Make the PHP do most of the work while mySQL just serves up data
2.) Make the mySQL database do most of the work while the PHP does simple outputting

The problem with the old method is that it placed a lot of work on my database; and I'm trying to move away from that.

PHP is much easier to do load-balancing than mySQL servers; you just buy more servers, send up a round-robin DNS system, and let things loose. mySQL servers are harder to set up across multiple servers; so you want to minimize the amount of work mySQL has to do while mazimixing the amount PHP does.

So the more CPU intensive basically means PHP is doing more work to output the same data, but there's less work being done on the mySQL end of things.
Posted by roy on January 3, 2004 at 11:40 AM in Web Development | 5 Comments

Related Entries

Want to comment with Tabulas?. Please login.

Comment posted on January 3rd, 2004 at 08:45 PM
blah blah blah blah
Comment posted on January 3rd, 2004 at 04:58 PM
wtf does mySQL use to output stuff(CPU?)

....so its less CPU intensive?
Comment posted on January 3rd, 2004 at 05:16 PM
Database systems tend to be more memory intensive than CPU intensive.

And in any case, the main point is that with the database and PHP on separate servers, I'm moving more of the load onto the PHP servers rather than the mySQL servers ;D

MacDaddyTatsu (guest)

Comment posted on January 3rd, 2004 at 04:14 PM
Do you find that PHP handles your system of field display better than mySQL or is it that mySQL is just so fucking finiky cross transfering from server to server and THAT was slowing the display pipeline. Im a hair confused.
Comment posted on January 3rd, 2004 at 05:18 PM
It's not anything you notice right now; I could of gotten away with not doing anything. The reason why these changes were made were to accomodate future growth; with more people using the site, eventually there wil reach a point where I will have to spread Tabulas across several servers (although it's already spread over two).

It's much easier with the changes I've made to spread Tabulas across several servers now (since PHP is easier to load balance than mySQL).