1

Right now I have 1000 concurrent users online. But my site is very slow. I could have 8000 concurrent users, but the server can't handle the traffic, and I'm losing visitors.

My server is a VPS server:

Dedicated CPU 7.2GHz

RAM 4512MB

The memory usage is way below the available resources. (right now 632 MB) What should i do? Should i configure the apache server? If yes, how? What about caching, maybe memcached?

This is a virtual server, built up from nodes, each node representing 600 Mhz cpu and 376MB ram.

I'm running a website on it built with php and mysql.

11
  • 4
    7.2 GHz? 4512 MB RAM? Are you about those numbers?
    – hughes
    Aug 11, 2011 at 18:41
  • What means slow? Does it try to connect for a long time and then load fast or does it connect fast and then load a long time or even both? Aug 11, 2011 at 18:42
  • You're neither describing what (web) applications run on that server, nor what exactly goes wrong. You will need to provide much more data than this to get meaningful answers.
    – Pekka
    Aug 11, 2011 at 18:42
  • 1
    2x3.6 or 4x1.8 is possible, I guess. And on a VPS, you can allocate ram in oddball sized chunks if you want. Memory won't be the only bottle neck on a machine. Check cpu usage, check disk bandwidth, check the database, etc... There's no ONE magical bullet that can solve this issue, except "throw more money at the server and get a bigger/faster/better one".
    – Marc B
    Aug 11, 2011 at 18:43
  • CPU usage and bandwidth sounds like it could be the issue, since the memory looks like it's sufficient. Could you describe your application in more detail?
    – EdoDodo
    Aug 11, 2011 at 19:01

2 Answers 2

3

Benchmark, benchmark, benchmark. That's the only solution. There are a million things that can make a website slow. Here's what I would do:

  • Load up Firefox with Firebug. Check the net panel for the loading times of your main request. If it gives a long time for "connecting", you may have network or bandwidth issues, or Apache cannot handle that many requests at the same time. If there's a long "waiting" or "transferring" time, then your PHP scripts could be the culprit. They take too long to render the page.
  • When dealing with PHP, the first suspect is usually your (My)SQL server. If you use a central SQL library, it should not be too hard to benchmark your queries. Just track how many queries your page needs, and how long those queries take. Compare that with the total page rendering time. If you have an old app that uses plain mysql(i)_ functions all over the place, then jump down two bullits.
  • If the issue is with MySQL then the first suspect is usually proper indexes. Run an EXPLAIN on all your queries and see if indexes are used. Define proper indexes. Re-benchmark. I/O is also a common cause of MySQL slowdown (use a bigger query cache, issue less queries (application cache), tweak your MySQL settings or just split the webserver and SQL server.
  • If the issue is PHP itself, load up xdebug and run your page through the profiler (make sure only for your request or you could easily kill your server). Load up the dump in KCacheGrind and figure out where your application spends all it's time. Refactor.

This is just what I would do. Every step depends very much on the results you got in the previous step. There is no generic advice that we can give you. Just benchmark, benchmark, benchmark and refactor your code and server setup accordingly.

1

My site was starting to get to the point where performance was suffering a little bit. I put memcached on some of my more "complicated" pages and it worked better than I could imagine. I had some pages that took .5 seconds to parse and one that took 3 seconds to parse (shame on me, i know). I spent less than an hour putting memcached in a couple of these key places and everything now parses in less than .01 seconds. Also, I've noticed my load average is down a bunch too as there aren't as many mysql queries to handle. I couldn't recommend memcached more :)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .