Thread: Coding for high traffic
Im about to get hold a project, its looking as though it will be a very high traffic site.
Im just wondering if any of you guys have any advice, for server load, and/or
programmingfor high traffic applications?
Any tutes or articles, you can direct me to?
I want to make sure I have most bases covered before taking the job on.
As always, thanks in advance.
"High traffic" is relative, but when I think high traffic, I'm thinking load balancing. If the traffic is truly high, you'll need it. You'll also need the high availability load balancing gives you since lots of traffic usually means an important application. It's hard to code around not having the right hardware for the job. Your
machines will need a lot of CPU speed and a lot of RAM. Squid caching servers are great for offloading static stuff like images. Nothing's faster than Squid for that kind of stuff.
The more static content and caching you can do, the better. The less code you have to execute, the better. You should look at using the Zend optimizer for your
Database design could be what makes or breaks you though. Assuming you are using MySQL, make sure you're using query caching. Make sure you use indexes. <>Don't write stupid queries.> Work closely with the DBA.
Again, hardware is going to make a difference here. You need fast 15KRPM SCSI drives with a good RAID controller that's got a lot of cache on it, Fast CPUs and lots of RAM.
I didn't really give you much coding advice, but you don't just code for this kind of thing. You have to think about the entire architecture. At the end of the day, if you don't have all of the above covered, it really doesn't matter what you code.
I kind of came to that conclusion myself. Load balancing will definately needed, it'll be similar to a job listing or rather a heavily promoted product promotion site, so i can see a lot of db called and images as well.
Seems Ive a little bit of research to do.
Can I ask what database you will be using?
I dont think it will be huge traffic to begin with since its local (australia) but they are looking at huge promotion and have budgeted for commercials etc.. in prime time. So I suppose it will spike a little.
So at tops Im guessing perhaps 400,000+ hits a day, I know that they will be looking at global eventually, but obviously that will be something I'll deal with when it arises.
Capacity planning is really pretty difficult when dealing with a huge unknown like an unwritten application.
You're definitely going to have to do a lot of testing, simulating a lot of concurrent users. A big company might use something like Mercury Load Runner, but that's really expensive.
You can download "iOpus
Macros" browser plugin for free on a bunch of PCs and "play back" browser sessions in a loop. That should give you <>some >idea of how you will perform under load from real users. ab (
apachebenchmark) will give you a measurement of total throughput from a single URL. This is pretty good to use for a singe page you know is going to be kind of heavy. It can help you see if your tweaking is really making an improvement, and by how much.
Keep track of how much bandwidth you are using too. You web servers will melt down if it fills the pipe. What happens is it can't complete the requests fast enough, and the number of connections to
Apachestart climbing. You start running out of memory and cpu, and it's a downward spiral from there. I've seen this happen all too often under huge traffic spikes we weren't ready for. Fortunately, modern load balancers have connection limiting features. You might not serve everybody, but at least you'll serve who you were prepared for. They also have connection "concentrating" where the load balancer opens up say 5 connections to the webserver, but is sending 50 real connections over it. <>This is huge>. It really reduces the memory
Apachehas to consume and lets the
machine work more efficiently. Compression from the load balancer helps with the bandwidth too without consuming your web servers' cpu for mod_deflate. Unfortunately, a high end load balancer can be pretty expensive too.
Anyway, this is from Sys Admin's (sometimes coder) perspective after years of dealing with high volume traffic. I've pretty much seen it all, lol. I've been out of that for about 1 1/2 years now. These days I mainly work on giant DB2 databases and little Weblogic applications.
Glad you're around slap, this shit makes my head spin.
Awesome info by the way.
I think it being a local project, i will have at least some time to analyse and do some testing, when it launches.
Im thinking along the lines of seperating the mysql database and
phproutines onto different servers and see how I go from there. After doing some research today, there seem to be a few dedicated hosts that are willing to give 24/7 monitoring and in an emergency do what is needed in order to keep things running. And looking at the bigger picture, this one doesn't look like it will be the nightmare that I think it will be, or that I have read about others having.
At this stage, money doesn't seem to be a problem for these guys, so I have at least a little room to move.
I have a couple of local servers here that I'll setup as temps to test as Im building. Thanks for the tips on iOpus
Macros, most likely I'll run this a little on the login and index pages. Perhaps Im going overboard, with worry, but I suppose being aware of the potential of such a project is the first step in being prepared for the worst.
As above, Im seriously looking at 2 dedicated servers first up. One dedicated to Mysql due to what I forsee as a lot of calls to the product database and especially those just browsing around pulling info and running searches, the other to standard
phproutines, images and as a mail server. Then I'll be running some tests to see if load bearing solutions are called for. Obviously because it will be a login, contribution system, DNS routing wont cut it, I'll have to keep sessions alive once users have made a call to script.
Having never dealt with such traffic before, its a
curve for me. If I could Id love to call on you for some advice somewhere along the line once things get going.
|Best of The Cache Home|
|Search The Cache|
- Apache & mod_rewrite
- BlackHat SEO & Web Stuff
- C/++/#, Pascal etc.
- Database Stuff
- General & Non-Technical Discussion
- General programming, learning to code
- Linux Related
- Mac, iPhone & OS-X Stuff
- MS Windows Related
- PERL & Python Related
- PHP: Questions & Discussion
- PHP: Techniques, Classes & Examples
- Regular Expressions
- Uncategorized Threads