Virtualmin on Low Memory Systems

This legacy document is here only to insure incoming links continue to work. You likely want to start with the new documentation index or search for what you want to know about. This document is unmaintained!

Virtualmin on Low Memory Systems

A default installation of Virtualmin is configured to maximize performance, rather than minimize memory usage. Thus, on a system with less than 256MB of RAM, problems can arise if steps aren't taken to reduce usage. These steps will not hurt performance on a low memory system, as running out of memory is a far greater performance problem than having to load a few libraries on each pageview in Virtualmin. Note also that Virtualmin, even at 100MB, is not the largest process on a full-featured webserver. Apache will be about 150-250MB once all of the modules are loaded, depending on which modules you use and whether everything runs under mod_fcgid or you use the individual mod_php, mod_perl, mod_ruby, etc. BIND can also grow to 100MB or much more, depending on the number of zones you're hosting and whether it is providing recursive DNS service. Postfix always stays pretty small, but the spam and anti-virus tools are unavoidably quite memory and CPU intensive.

To disable preloading of Webmin libraries, follow these steps :

  1. Login to Virtualmin as root.
  2. Open the System Settings category on the left menu, then click on Module Config.
  3. Change Preload Virtualmin libraries at startup? to No
  4. Click Save. You will then be prompted to re-check the Virtualmin configuration.
  5. Click the Re-Check button. Once this process is complete, the Webmin server process will reduce RAM use to about 10M.

Alternately, you can do the same thing from the command line by editing /etc/webmin/miniserv.conf

Find this line:

preload=virtual-server=virtual-server/virtual-server-lib-funcs.pl virtual-server=virtual-server/feature-dir.pl virtual-server=virtual-server/feature-unix.pl... 
 

This line is much longer than this on most systems. Insert a # mark at the beginning of the line (before "preload"), to comment it out, and then restart Webmin with the following command:

# /etc/webmin/restart

Then edit /etc/webmin/virtual-server/config, and change the preload_mode line to :

preload_mode=0

This will reduce Virtualmin memory usage from ~90MB to ~10MB. This option determines which Webmin libraries are preloaded on Webmin startup. It makes it faster, if there's plenty of memory, but on low memory systems avoiding swapping is far more important to performance of all components.

Reduce Apache memory usage

  • Browse to the Webmin Apache Webserver module
  • Click on "Processes and Limits"
  • Change the following to the values shown:
    • Maximum spare server processes 3
    • Minimum spare server processes 2
    • Initial server processes 3

Optionally, remove any modules you aren't using. This actually will reduce memory usage more than anything else--but it's hard to guess what modules you'll want/need to do your job. mod_perl is needed for the new Analytics module in Virtualmin, but otherwise everything can be run under cgi or fcgid...and if memory is a real problem, you may have to give up on Analytics (or set it up manually without our mod_perl filter). So, disabling mod_php4 or mod_php5 is cool (but if you've been using it for PHP scripts, you'll need to make the switch to fcgid first, and reset permissions and ownership up your PHP scripts in domain homes) and will shave quite a bit off the process size. Other possibilities for disabling: auth_dbm, disk_cache, proxy (but this removes quite a bit of functionality), include (removes Server Side Include functionality), status.

Because Apache is probably the biggest process on any hosting system...if you're dealing with a VERY small memory system (under 256M), then you'll have to cut it down a lot. This isn't really optional in that case.

Reduce mail processing memory usage

The actual mail services are tiny. The spam and anti-virus filtering services are not. You may want to consider simply forwarding mail on to a free Gmail account or something that has good spam/AV filtering. This is limiting...but it means your mail service can be provided in a few MB. In such a case, you'd turn off dovecot, and would never have to spawn SpamAssassin or clamav. If you do have to deliver mail locally, don't use clamd or spamc, as those have processes that always run...unless you get enough mail to keep them respawning every minute or more (because the memory is effectively made unavailable anyway--might as well get the mail processed faster and give away a little memory).

Reduce unnecessary services

Shut down postgresql or mysql or both. If you're not using databases, don't run them.

Shut down proftpd, if you can convince yourself and/or your users to use the Webmin Upload/Download and File Manager modules or ssh/scp for file transfers.

Don't even think about running X. You probably don't want to run X on any server, but this is particularly true for low-memory systems.

Enable swap

Make sure you have a swap file or swap partition configured. Swapping out infrequently used processes and data leaves more memory for active processes.

Community-Provided Sample Config Settings (CentOS 5.2)

I use these configs on my 256MB CentOs 5.2 VPS Server. It works good for me, but mileage may vary for you. This is in no way a replacement to a larger server.

Optimize LDAP for low memory Server

Note: Don't use LDAP on a low-memory system. Flat-files are dramatically less resource intensive and much faster than LDAP under pretty much all circumstances and especially in low-memory systems. But, if you must use LDAP, this may be helpful in reducing some of the resources required.

/etc/openldap/DB_CONFIG

    set_cachesize 0 26843545 1
    cachesize 1000
    set_lg_regionmax 26214
    set_lg_bsize 209715
Optimize Apache for Low memory Server

/etc/httpd/conf/httpd.conf

    KeepAlive On
    KeepAliveTimeout 3
    <IfModule prefork.c>

    StartServers       2
    MinSpareServers    2
    MaxSpareServers    5
    ServerLimit      100
    MaxClients       100
    MaxRequestsPerChild  500
    </IfModule>
    <IfModule worker.c>
    StartServers         2
    MaxClients         150
    MinSpareThreads     15
    MaxSpareThreads     50
    ThreadsPerChild     15
    MaxRequestsPerChild  0
    </IfModule>
Optimize MySQL for Low Memory Server

/etc/my.cnf

    [mysqld]
    port               = 3306
    socket             = /var/lib/mysql/mysql.sock
    skip-locking
    key_buffer         = 16K
    max_allowed_packet = 1M
    table_cache        = 4
    sort_buffer_size   = 64K
    read_buffer_size   = 256K
    read_rnd_buffer_size = 256K
    net_buffer_length  = 2K
    thread_stack       = 64K

Comments

I run 2 VPS,s and each one running virtualmin / webmin. They are on seperate serversfrom 2 different companies, but I do have them linked though in a cluster etc.
One VPS has 1 GB real memory and 1 CPU core, the other has 2 GB real memory and 2 cores.
I noticed the smaller VPS has allocated 1.92 GB as virtual memory, while the other VPS has allocated 97 MB.
The smaller VPS runs around 60% real memory usage and about 50 percent virtual. The larger VPS runs 45% real memory usage and 100% virtual memory.
Both generally only run 2 to 10% CPU.
The larger VPS doesn't run as many sites at this stage to the smaller, while the smaller one runs about 10 active sites.
Is there a way of increase virtual memory as I feel that running that at 100% can only be slowing things up, and I am about to setup a couple of larger (eventually) linked sites.
I was always under the impression with small ram setups such as 1 and 2 GB, that the Virtual Memory should be roughly double....

Just a quick update: I added a 2 GB swap file to the system and that seems to have done the trick.
My virtual min now shows 2GB swap with 4% usage, so it will be interesting to see how it goes once I tranfer the sites.
I would prefer to have resized the virtual drive but could find on info on doing that without losing data.