Apache

Thoughts on VPS Memory Management

0

Recently, I have been spending a significant amount of time working on an application which manages the amount of memory assigned to a DreamHost Web VPS. During the time I’ve spent developing this several choices had to be made in what the real goal of the application had to be. When it comes to memory management on a server there are really two goals which don’t always play well together.

Goal One: Save Money

Many people seem to have a belief that just because the site/s are on a VPS, even with memory set as low as possible (300MB of RAM assigned to a machine in the case of a DreamHost VPS), they will have perfect or near perfect uptime. Sadly, this is not the case and often times this misunderstanding/confusion can lead to serious downtime and frustration. Ideally, for people who are trying to have the lowest amount of memory usage possible, a memory management application would realize that there is a need for more memory, calculate an estimated amount of memory needed to handle the increased usage, resize the VPS as closely as possible to that need, then downsize as soon as the memory is no longer needed.

There is one major issue with this scenario:

Creating estimates regarding the amount of memory needed in an environment where usage is constantly changing, is a massive challenge. To be more specific; since the ability to resize a VPS tends to take some time (anywhere from 1-5 minutes), it is possible for memory requirements to have increased during the time that the need was detected and the memory estimate was created. This could create a resize on a VPS with too little memory, causing problems for the website/s on the VPS, as the machine is given too little memory to handle the increased need.

Goal Two: Keep Services Running

If you are on a VPS, chances are you’ve outgrown shared hosting or are looking for more stability and control over the environment your applications run on. If you’ve got a decent understanding of servers, applications, and websites, you may also understand that you need to have enough memory to run all the processes and handle the requests to your sites. Often times simply setting your service to the lowest amount of memory possible is going to be asking for failed script executions and the dreaded 500 error being displayed on your site.

So with this understanding, some people go to the extreme and max out their VPS resources. At DreamHost that means $200 a month for services (4GB worth of RAM) which may not be fully utilized (and most likely are not). So the question here becomes how to balance cost and the need for memory, in order to keep services running without paying the maximum amount at all times.

A Hybrid Memory Manager Focused on Uptime

With these two potential goals in mind, I had decided to mainly focus my attentions on goal two. While I do understand the need to keep price as low as possible, it is my personal belief, gleaned from experience, that a downed website is more damaging to the bottom line than a slightly larger payment for hosting services. So with this in mind, the memory manager was created to focus on uptime, while still saving time and money for those who manually resize throughout the day, and potentially over-allocate memory for their site/s.

All this being said, I am quite excited to be releasing this software soon. The status of this release is currently closed beta. However, if you are interested in testing this on your DreamHost VPS, please contact me. I am looking to increase the pool of Beta testers before the official release.

Protected: JJ’s VPS Memory Manager, Closed Beta

0

This post is password protected. To view it please enter your password below:


A DreamHost VPS Memory Manager – Coming Soon

0

I’ve been working on this for awhile now and it’s almost ready! I’m just working out a better set of rules for figuring out what amount to resize to and I’ll be releasing the first beta!

GimmeSoda.com Server Move: XCache, W3-Total-Cache and Nginx = Awesome

2

I’ve moved this site (gimmesoda.com) over to a test server (Private Server) I’ve got running on DreamHost. This server is running Nginx instead of Apache, both machines (the PS it was running on before, and the PS it is now running on) are set to 2GB of memory and the software setup of WordPress is exactly the same.

Why:

Apache can be a memory hog.

As more and more traffic comes into a website the Apache process continues to spawn memory hogging worker processes and during my basic testing I saw over 90 apache worker processes spawned at one time. Each of those processes were taking about 23MB worth of memory when spawned (23 x 90 = 2070MB) which maxed out the $100/month PS machine and returned several hundred errors at 100 concurrent connections.

Nginx handles concurrency much better and requires far less memory.

When the site was moved over to Nginx I ran the same test (1000 requests with 100 concurrency) and memory usage was under 800MB, it also returned 0 errors compared to the 664 from the use of Apache. Also, you should take note of the speed between the two in the results below, Nginx returned all requests in under 1s.

WordPress Cache Settings:

I’ve switched off the use of WP-SuperCache, which uses disk based caching and provides no further options such as opcode caching (APC/XCache/eAccelerator) which W3-Total-Cache does provide! Not only does it provide a static page cache as well as opcode options but it incorporates minify options, database, and object caching among other features.

All cache options have been set to XCache rather then disk, after all reading from memory is faster then reading from disk.

The Setup:

  • WordPress v3.0.1
    • Theme
      • I am using the Mystique theme, which thankfully does NOT use the timthumb.php script (I am NOT a fan of it).
      • Plugins
        • Akismet
        • All in One SEO Pack
        • Categories to Tags Converter Importer
        • Clean-Contact
        • Dragon Design Sitemap Generator
        • DreamHost WordPress Backup
        • FeedBurner FeedSmith
        • Google XML Sitemaps
        • Paypal Donate Plugin for WordPress Widget Support
        • Permalinks Moved Permanently
        • Piwiks Analytics
        • Twitter for WordPress
        • W3-Total-Cache
        • WordPress.com Stats
        • WordPress Importer
        • WP-FLV
        • WP-PayPalDonate

AB (ApacheBench) Results:

Apache Results Nginx Results
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking www.gimmesoda.com (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests

Server Software:        Apache
Server Hostname:        www.gimmesoda.com
Server Port:            80

Document Path:          /
Document Length:        30876 bytes

Concurrency Level:      100
Time taken for tests:   6.912 seconds
Complete requests:      1000
Failed requests:        664
   (Connect: 0, Receive: 0, Length: 664, Exceptions: 0)
Write errors:           0
Non-2xx responses:      664
Total transferred:      10878952 bytes
HTML transferred:       10588808 bytes
Requests per second:    144.67 [#/sec] (mean)
Time per request:       691.234 [ms] (mean)
Time per request:       6.912 [ms] (mean, across all concurrent requests)
Transfer rate:          1536.96 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        1   15 164.4      7    3013
Processing:    24  511 782.2    190    4087
Waiting:       17  503 778.0    188    4074
Total:         46  526 792.6    196    4091

Percentage of the requests served within a certain time (ms)
  50%    196
  66%    266
  75%    499
  80%    744
  90%   2018
  95%   2703
  98%   2983
  99%   3060
 100%   4091 (longest request)
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking www.gimmesoda.com (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Finished 1000 requests

Server Software:        nginx/0.7.65
Server Hostname:        www.gimmesoda.com
Server Port:            80

Document Path:          /
Document Length:        30874 bytes

Concurrency Level:      100
Time taken for tests:   3.158373 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      31348328 bytes
HTML transferred:       30961170 bytes
Requests per second:    316.62 [#/sec] (mean)
Time per request:       315.837 [ms] (mean)
Time per request:       3.158 [ms] (mean, across all concurrent requests)
Transfer rate:          9692.65 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        1   22  11.8     20      63
Processing:    36  184 108.6    144     874
Waiting:        8   34  24.6     26     279
Total:         37  206 111.5    166     913

Percentage of the requests served within a certain time (ms)
  50%    166
  66%    209
  75%    251
  80%    273
  90%    347
  95%    405
  98%    569
  99%    641
 100%    913 (longest request)

More Information

Nginx: A web server written to address the C10K problem. http://wiki.nginx.org/Main

XCache: A fast opcode cacher, it’s a PHP extension. http://xcache.lighttpd.net/

W3-Total-Cache: A brilliant (and free) wordpress caching plugin that goes the extra mile. http://wordpress.org/extend/plugins/w3-total-cache/

Forcing MP3 Downloads on Apache

0

I keep seeing this more and more often. Apparently the proper mime-types keep getting set for mp3 files and browsers are properly responding – so rather then downloading (depending on your setup) the file might just end up playing from your browser! The horror! (People, just save the target file!)

Anyhow, if your application is meant to send the file as a download you really should be forcing it rather then relying on your visitor’s settings. Put the following into your .htaccess file to force the download:

AddType application/octet-stream .mp3

You can also add more extensions to that line in order to force the download of more file types such as:

AddType application/octet-stream .mp3 .flv .mov .wav

You get the idea! Any questions? Enjoy!

Go to Top