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 :
- Login to Virtualmin as
root. - Open the System Settings category on the left menu, then click on Module Config.
- Change Preload Virtualmin libraries at startup? to No
- Click Save. You will then be prompted to re-check the Virtualmin configuration.
- 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 PHP sub-processes
In it’s default configuration, Virtualmin runs PHP scripts with the permissions of each domain’s owner using fast CGI. For each domain that has PHP scripts, four php-cgi processes will be launched and will remain running so that PHP pages can be quickly executed. However, each consumes about 30M of RAM.
The best way to reduce this is to lower the number of php-cgi processes that are kept running. You can do this for a single domain as follows :
- Login to Virtualmin, and select the domain from the left menu.
- Open the Server Configuration category, and click on Website Options.
- Change the PHP FCGId sub-processes to something lower, like 2.
- Click Save.
Alternately, you can make this change for all domains. This is best done from the command line as follows :
- SSH into the system as
root. cdto the Virtualmin directory, which will typically be either/usr/libexec/webmin/virtual-serveror/usr/share/webmin/virtual-server.- Run the command :
./modify-web.pl --all-domains --php-children 2
Be aware that reducing the number of processes will slow down PHP requests if more than the specified number of PHP pages need to be served at the same time.
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.