• Industry Solutions
    • Managed Service Providers
    • Enterprise Solutions
    • Developers & Startups
    • Healthcare
    • Trading and Financial
      • Chicago Managed Trading Servers
      • Trading and Financial Colocation: Chicago & New Jersey
    • IBM AS/400 and iSeries Users
  • Support
    • Register
    • View Tickets
    • Submit a Ticket
    • Knowledgebase
    • News
  • Steadfast Blog
  • Steadfast Podcasts
  • Contact Us
Home
  • Call Us
  • Call | 888.281.9449
  • Login
  • Search

This form logs you into your management portal account. To access your help desk account, click here and use the form to the right of the news.

  • Cloud Hosting
    • Cloud Hosting
    • Private Cloud
    • Hybrid Cloud
    • Public Cloud
    • Cloud Storage
      • Secure File Share
      • Wasabi Cloud Storage
    • Virtual Data Center Platform
  • Managed Hosting
    • Bare Metal Dedicated Servers
      • Deep Learning GPU Dedicated Servers
      • Linux Dedicated Servers
      • Windows Dedicated Servers
    • Virtual Private Servers
    • Data Center Colocation
      • Managed Colocation
      • Chicago: 350 E Cermak
      • Chicago: 725 S Wells
      • Edison, New Jersey
    • Security & Compliance
      • Managed Firewall
      • SSL VPN
      • DDoS Protection
      • Email Security
  • Backup & Disaster Recovery
    • Backup
    • Disaster Recovery
    • Veeam Backup & Replication
    • Veeam Cloud Connect
    • Wasabi Cloud Storage
  • Why Steadfast
    • Why Steadfast?
    • About Steadfast
      • Our History
      • News and Press
    • Data Centers & Network
      • Our Data Centers
      • Our Network
      • Network Test
      • Peering Policy
    • Customer Stories
    • Service Level Agreement
  • Industry Solutions
    • Managed Service Providers
    • Enterprise Solutions
    • Developers & Startups
    • Healthcare
    • Trading and Financial
      • Chicago Managed Trading Servers
      • Trading and Financial Colocation: Chicago & New Jersey
    • IBM AS/400 and iSeries Users
  • Support
    • Register
    • View Tickets
    • Submit a Ticket
    • Knowledgebase
    • News
  • Steadfast Blog
  • Steadfast Podcasts
  • Contact Us
Close
  • Support Home
  • Register
  • Submit a Ticket
  • Knowledgebase
  • News
 Login Subscribe

Log into the help desk to manage support tickets.


Lost password

Subscribe to general maintenance announcements and advisories.



 
 Knowledgebase
39Steadfast Cloud Platform 3Full Management 38Dedicated Servers & Colocation 4Control Panels 19Other
Search
Knowledgebase: Steadfast Cloud Platform
Reducing Memory Usage
Posted by Karl Zimmerman, Last modified by Kevin Stange on 06 May 2013 02:16 PM

If your server or VM is frequently running out of memory this article should be of great assistance to you and will guide you through diagnosing what the issue is as well as listing some possible fixes.

First of all, to see how much memory you are currently using, run free -m. It will give you output such as:

             total       used       free     shared    buffers     cached
Mem:           363        354          9          0         46        137
-/+ buffers/cache:        170        193
Swap:         1023         53        970

The "used" value (354) will almost always be close to the total memory (363) in the system. This is because Linux uses spare memory to cache data in order to reduce the reliance on the hard drive. Here 137MB are being used for cache. You can read more about this in the "Why is so much memory in use on my server when nothing is running?" article.

The main thing you're going to want to look at is the "-/+ buffers/cache:" used value (170). That is the actual amount of memory your applications are currently using. For best performance, this number should be less than your total (363) memory and in order to prevent out of memory errors, it needs to be less than the total memory (363) and swap space (1023).

ps

In order to see where all your memory is going, just run ps aux. That will show the percentage of memory each process is using (in the %MEM column) and you can use it to identify the top memory users (usually Apache or MySQL). Remember to add together all instances of the service to calculate how much memory the service is using as a whole.

Resolving: High Apache Memory Usage

Apache is often one of the biggest memory users. Apache is run as a number of 'servers' and incoming requests are shared among them. The memory used by each server grows, especially when the web page being returned by that server includes PHP or Perl that needs to load in new libraries, and it is no uncommon for each server process to use as much as 10% of a server's memory.

In order to reduce the memory usage you can reduce the number of servers by editing your httpd.conf file. There are three settings you are going to want to look at: StartServers, MinSpareServers, and MaxSpareServers. Each can be reduced to a value of 1 or 2 and your server should still respond promptly. After changing the settings in the httpd.conf file be sure to restart Apache by running "service httpd restart" to assure the new settings are in effect.

Resolving: High MySQL Memory Usage

MySQL is relatively memory efficient on install as most memory intensive features are not enabled by default, but you can add the following lines to the /etc/my.cnf file, under the mysqld section, to free up some additional memory:

innodb_buffer_pool_size = 16k
key_buffer_size = 16k
myisam_sort_buffer_size = 16k
query_cache_size = 1M

Again, make sure you restart the service for those settings to take affect. This can be done by running "service mysql restart"

Resolving: High SpamAssassin Memory Usage

SpamAssassin can also be a major memory user as it can create multiple threads/processes and each of those threads can use a good amount of memory, but SpamAssassin normally works very well with just one thread. You can reduce the 'children' setting and reclaim some memory on your server for other apps to run with.

To do this change the SPAMDOPTIONS line in the /etc/init.d/spamassassin file to:

SPAMDOPTIONS="-d -c -m1 -H"

Final Solution: Add Memory

A simple solution to resolving most out of memory problems is to add more memory. If you'd like to increase the memory on your VM, just modify your VM directly from your control panel at https://vm.steadfast.net/ and if you have a dedicated server simply email us at sales@steadfast.net in order to get an upgrade.

(279 vote(s))
Helpful
Not helpful

Comments (2)
Josh Leuze
27 April 2008 08:46 PM
If you are running Debian, the Apache config file is a little different than the instructions. You want to edit apache2.conf, located in /etc/apache2, rather than httpd.conf.

More info here: http://www.control-escape.com/web/configuring-apache2-debian.html
Josh Lacey
18 September 2009 08:49 PM
Good article helped me out.

I consent to allow Steadfast to process my data and agree to the Acceptable Use and Privacy Policies

  • 312.602.2689
  • ColoHouse Sales
  • Facebook
  • Twitter
  • YouTube
  • LinkedIn

Services

  • Cloud Hosting
  • Managed Hosting
  • Backup & Disaster Recovery

Solutions By Industry

  • Enterprise Solutions
  • Trading & Financial
  • Healthcare
  • Developers & Startups
© 2023 Steadfast
  • Log In
  • Site Map
  • Legal Info & Privacy Policy