Views

DreamHost says "ow, your ignorance."

From Telkoth.net

well, not really, but I feel like my ignorance is hurting their servers sometimes...

I've been mailing them recently about a problem they perceive with my account... apparently I'm using too many system resources... unfortunately, the two hosting companies I've been with have both been pretty bad about defining what "too many system resources" really means, but they do report that my web page is hogging their CPU, basically, and that they'd like it to stop... they just can't seem to tell me what about my site is doing all the hogging, making it difficult for me to fix.

anyway, I've been asking them what they think the problem could be, and they've said "well make sure you're not getting 500,000 page requests in a day from 100 users" (it'd be odd for the average user to make 5000 hits in a day - a good sign of someone purposely trying to cause the servers grief), and "maybe people are going nuts with FTP access"... neither of those seem to be it, though, so I pried more, and they went "check out the disk usage" for no good reason, so I did, and I'm way below any of their limits...

while I was looking at the disk usage, though, I noticed that MySQL usage is also recorded (MySQL is just a kind of database... imagine a spreadsheet, but better :)). Still, the numbers there don't look odd to me, but they did give me a lot of information I didn't understand, so I took a look in to what some of those numbers might mean, and in taking a look I realized that I may have been doing something the dumb way, 'cause I didn't know another way even existed that could be better.

I will explain!

It has to do with the way the computer talks. I'm gonna need a picture... [goes to draw one up]

Alright! So!

There's You, and You're like "check me out - it's PsyPets"... and I dunno, You just logged in, and are at the Plaza, but You want to go to "My House" and check up on Your pets, so you click "My House".

Your computer sends a request along A - the Internet, I suppose - and goes "Yo! Give me My House. I'm You, at this IP address, bla-bla." So your house goes "Oh, you're You, eh? Well I need to look that up in the Database, so I'm going to send a message along B and ask for a connection. Hey, Database! Can we talk? This Guy You from IP address wants some information..." and the Database goes "Sure, ah, I need to assign a number or something first for future reference... um, lemme see which one is free... there are so many to look through... um... just a minute... ah! here, number 123 is free." and so your house says "Great. So I'm 123 - tell me about the account that this person has," and the database goes "Ah, 123, fantastic. Yes, I will tell you about it." And then maybe your house says "Um, I'm 123... tell me about all the pets, too" and the Database says "123 you say? Sure, here's all that info about pets." and your house probably asks about inventories, and lots of other stuff, too, and passes it along back to You through A. After the whole ordeal, your house finally says "Alright, cool, I - 123 - am done," and the Database says "123 is done? Great, I can use this number for someone else now. I'll just take that back... thanks." and that's it.

Now suppose You notice that your pets are hungry, but You don't have money, so You want to go to the bank to withdraw money. So You click on "Bank", which sends a request saying "Hey bank! You of IP address speaking. Talk to me," and the Bank says "Ah, You, eh? I'll talk to the Database... Hey Database, I want to talk about this guy," and the database says "well first let me find a number here... ah, hm... I think 998 is -- oh, wait, no, not 998. Um... hmmm... ah! 999 maybe? yeah, 999 is free. you can be 999 when you talk to me from now on." and all that nonsense goes on again, and the bank page tells You, in some form, what the Database tells it, and then at the end the bank says "999 reporting - I'm done." and the Database goes "really? done? sweet - I could use that 999 for this other request. [yoink]"

Here's the problem. The actual requests for information are relatively quick, however assigning the number with which to talk about the requests takes a very long time. Apparently a good ratio is 25 requests per 1 "dialog", if you will. If you were only making one request per converstion, you'd spend most of your time with the database trying to find a good number, but by making something like 25 or more requests, you make that waiting time negligable.

So here's an improvement... what if, instead of giving the number back after every conversation, you hold on to it for the future? There are some technical trickinesses due to how computers talk about web pages, but it's otherwise, as you might imagine, a superior method.

So now what happens is when You visit the bank, the bank says "Hey, I need to know about this guy of IP address." and the Database replies "IP address? why, you must be 999" and the bank goes "yeah, I'm 999. so tell me what you know."

and they talk, and the Database doesn't have to go and find a free number, and establish the connection, etc, etc, etc.

it's quicker and, I hope, so much less distracting to my hosting company's servers that they'll like me again :P

but I'm sad I didn't know how to do this before, because it really requires no extra work for me... like, to make the computer do all that talking, I can just go:

mysql_connect("database", "username", "password");

and the connection is made using the "we'll forget about each other later" method

mysql_query("SELECT * bla-bla-bla");

and a query is made. OR, even better, I say:

mysql_pconnect("database", "username", "password");

and the connection is made using the "remember me" method; queries done the same way.

what? the commands look the same to you? there's an extra "p" in there before the word "connect" which means "persistent."

that's all I had to do!?!

anyway, I'm sure there are other side-effects, and other things to consider... we'll see how it works out. but grr! I really need to just pick up a PHP/MySQL book and read it front to back... so I'd know these things...