Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
How do you do Load Testing and Capacity Planning for Web Sites

I hope this is the proper place to ask this. I put it up in webapps and it was closed without a recommendation on where to put it. Hopefully folks will be kinder here.

I have an app that I am gathering usage metrics on. The metrics are sent to a MySQL DB via PHP scripts. This is all running on an AWS EC2 micro instance.

My question is, I have about 10 metrics I want to gather. Would I be better served breaking up the PHP scripts into 10 separate units that each write one metric to the DB or writing one monolithic PHP script to handle them all?

I don't care about the complexity or inherent difficulty maintaining 10 scripts, what I am concerned with is the scalability for a TON of users. Is it generally better to have more scripts to serve many people, or one script to serve many people? Basically if 10 people use our app, each hitting a different metric, one method would serve the same page 10 times, and the other would serve a single page once to each user.

Which performs better??

Thanks for any input!


share|improve this question

marked as duplicate by Michael Hampton, John Gardeniers, HopelessN00b, Brent Pabst, mdpc Nov 12 '12 at 17:42

This question was marked as an exact duplicate of an existing question.

Hi Michael, I don't think so... really what I am looking for is someone with more in-depth web-server experience than I have (which is not asking much...) to chime in with, "Apache will handle serving a single file to millions of users just fine," or "Break it up into pieces and it will do much better..." Something to that effect. :) – Raconteur Aug 14 '12 at 20:19
I don't think it's possible for any of us to say how well your application will perform with one design as opposed to the other. The best advice I can give you is to try it both ways and see. – Michael Hampton Aug 14 '12 at 20:24
So there is really no "rule of thumb" that says that a server will handle serving separate files to multiple users better than serving a single file to multiple users (or vice-versa)? Seems like it would be one of those server-admin secrets. :) – Raconteur Aug 14 '12 at 21:10
It would be helpful if you could define exactly what you mean by "metric." Since you have this tagged as Amazon Web Services, have you looked at using custom CloudWatch metrics? Or possibly SimpleDB? Also: You shouldn't be running anything other than a test environment on a single EC2 instance. A production environment should always be composed of at least two EC2 instances. – jamieb Aug 15 '12 at 0:27

First of all, I believe this site (ServerFault) is the proper place to ask your question, as long as you're concerned about how to configure and deploy your web server (SF is a system admin place). If it turns out you have more of a coding question (how do I do this properly in php) then you might post that to StackOverflow, which is intended more for programming issues.

But to your main question, the answer is unfortunately, It Depends(tm). One significant distinction between your original question and your discussion in comments, using PHP to post updates to a database is significantly different than serving one file or multiple files out of a webserver. The reason for this is that a well-configured php application will run inside of the webserver process (ie mod_php in Apache) and so will soak up CPU time from the webserver, and the PHP binary's libraries will get loaded up into memory as well.

However, those are the "buy in" costs of running your web application. They are not going to change significantly whether you have a single PHP script with dispatch logic, or a bunch of different single-purpose scripts.

To make a really broad generalization, the slowest and most resource-hungry part of many web applications is the step where they connect to the database. This is the reason there are so many application frameworks, tightly integrated with web or app servers: to take advantage of resource pooling for those expensive setup tasks. Again, assuming you run your application in Apache with mod_php, this is likely to be handled for you automagically or at least made quite simple.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.