Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am experiencing frequent drops in performance of my server (affects both webserver performace and ssh). It may work fine all day and then suddenly pages load 10 times slower. After awhile it comes back to normal performance. Reboot also helps. Please suggest how to investigate this? Prerequisites:

  • Ubuntu 10.10 server, with most recent updates (including kernel)
  • LAMP: Apache/2.2.16, PHP 5.3.3, MySQL 5.1.49
share|improve this question

1 Answer 1

There are multiple possibilities for degrading performance, but the most likely cause is a shortage on RAM, causing the system to swap.

You can use free -m to get the memory usage, an example output:

             total       used       free     shared    buffers     cached
Mem:          3632       2512       1120          0        233       1456
-/+ buffers/cache:        822       2810
Swap:         8192          0       8192

The actual free space that can be allocated is visible on the row with -/+ buffers/cache. If you find that your server is swapping too fast, you might want to lower the vm.swappiness setting. You can find your current swappiness setting by running sysctl vm.swappiness. It ranges from 0 - 100, a lower value will use the swap later, a higher value make the kernel use the swap earlier. If you decide to set this value to 10, you should run the next command to change it at run-time:

sudo sysctl -w sysctl vm.swappiness=10

To make it persistent (i.e. after a reboot), add the line sysctl vm.swappiness=10 to /etc/sysctl.conf.

share|improve this answer
    
What exactly indicates that my server is swapping to fast? –  Dziamid Mar 29 '11 at 15:21
    
my free -m output: total/used/free mem: 117/113/3 -/+ buffers/cache: -/84/32 swap: 139/46/93 Swappiness is 60 –  Dziamid Mar 29 '11 at 15:27
    
@Dziamid: you said your machine would become slow, and after some time or a reboot, everything is normal. 117MB is very low memory, 256MB+ is recommended, you're currently using 46/139MB swap with 84/117MB RAM in use. Try setting your swappiness to 20. –  Lekensteyn Mar 29 '11 at 15:57
    
Setting swappiness to 20 didn't help. I decided to upgrade to a better server with 384MB of memory. What swappiness do you think I should set there? –  Dziamid Mar 30 '11 at 14:37
    
If 20 swappiness did not help, try setting it even more lower, like 5 or 2. Experiment with it, if your system runs out of RAM and has to swap, it can be a higher performance hit to wait until stuff has been moved to the swap compared to a system on which stuff is moved to the swap before it's full. 384MB should be sufficient. Disabling unnecessary services can lower the memory consumption too (e.g. mail server) –  Lekensteyn Mar 30 '11 at 15:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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