My most popular website, the Fake Name Generator, recently ran into two major problems:
- It was using too many server resources.
- It wasn’t as fast as I wanted it.
To solve these issues, I turned to SimpleCDN and their awesome “mirror buckets”. Basically you setup a bucket, point it at your base URL (in my case, http://www.fakenamegenerator.com), then update a few links on your website. Instead of linking to something like http://www.fakenamegenerator.com/images/logo.png, I link to http://fake.name.generator.lg1x8.simplecdn.net/images/logo.png. When the visitor pulls up the new SimpleCDN URL, SimpleCDN will see if they have a cached copy of my image. If they don’t, they download it from my server then serve it to the visitor.
How does this help?
First, the website is faster for the visitor. The images are served up from a server that is geographically near them and that is guaranteed to handle all the headers related to caching properly.
Second, my server doesn’t have to handle images or CSS for that site anymore. For the Fake Name Generator, that is 260,000 requests per day that Apache doesn’t have to handle. This makes my server capable of doing more without having to buy more memory or get a faster CPU.
So the big question: how much does it cost? $0.039 per GB. For me, that means for the low low price $7.31 per year, they’ll handle 94,900,000 requests totaling 187 GB.
The best part? They give you a free $15 account credit when you sign up, so I won’t pay a penny until 2012.
Check it out at SimpleCDN.






PHP: mysql or mysqli?
As you may know, I’ve been spending a lot of time trying to make the Fake Name Generator as fast as possible. I’ve started using a CDN, I’ve made minor code tweaks (like doing ++$i instead of $i++), added APC caching, and a bunch of other stuff, but still feel that the core of the FNG is a bit slow.
Currently the code uses PHP’s mysql extension. I’ve read in several places that mysqli is better, faster, more attractive, gets more girls, etc, but have been unable to find any remotely recent benchmarks to prove it. I don’t care if the OO approach is cleaner looking, I just want it to be faster.
So I put together a bit of a benchmark (very unscientific) to see if it is faster or not for my very specific needs: I want to generate 50,000 names as fast as possible. Each name requires 4 SQL queries, so I end up making 200,000 queries (yikes!).
For my first attempt, I simply replaced all of my procedural mysql stuff with the OO mysqli equivalent. In other words, I connected to the database, ran each query, then got the result out of the result set. This had absolutely no improvement over my current method of getting data; sometimes mysql was a second or two faster, sometimes mysqli was a second or two faster.
For my second attempt, I used the mysqli::multi_query method to combine the 4 SQL queries per name down to a single trip to the database per name, dropping my total number of trips to the database from 200,000 to 50,000. This yielded a drastic 66% speed improvement. There are several methods in my name generation class that generate multiple queries, so using this technique will make the name generator significantly faster.
Conclusion: As a drop-in replacement for the standard mysql extension, mysqli does not appear to be any faster, even for lots of queries. However, the mysqli::multi_query method makes it possible to shave large percentages of time off of your script’s execution time.
Update (2−4−2010): I just ran an order for 10,000,000 names (with addresses, occupations, etc). This process used to take about 25 hours to run on my server. With the new code it ran in only 15 hours. That is a 40% speed improvement for about 45 minutes of effort! So my conclusion is yes, mysqli can be much faster in certain situations.