5

I set up a site on amazon ec2 free tier, which comes with 613MB memory with no swap. I see server uses almost 100% of memory all the time. My site is running wordpress with wp super disk cache turned on. and the site is not busy, about 300ip per day. Can anyone tell this is normal, or something goes wrong? Thanks!

free -m
             total       used       free     shared    buffers     cached
Mem:           596        589          7          0          0         14
-/+ buffers/cache:        574         22
Swap:            0          0          0

ps aux | grep "apache"
apache   10120  0.2  5.1 287908 31732 ?        S    10:41   0:19 /usr/sbin/httpd
apache   10122  0.2  4.9 288448 30504 ?        S    10:41   0:22 /usr/sbin/httpd
apache   10123  0.2  4.8 288380 29676 ?        S    10:41   0:20 /usr/sbin/httpd
apache   10124  0.2  5.1 287616 31708 ?        S    10:41   0:21 /usr/sbin/httpd
apache   10125  0.2  4.6 287428 28704 ?        S    10:41   0:20 /usr/sbin/httpd
apache   10126  0.2  5.2 288376 32372 ?        S    10:41   0:22 /usr/sbin/httpd
apache   10127  0.2  4.6 284028 28164 ?        S    10:41   0:21 /usr/sbin/httpd
apache   10207  0.2  5.3 288452 32396 ?        S    10:49   0:19 /usr/sbin/httpd
apache   10224  0.2  4.3 284520 26496 ?        S    10:50   0:19 /usr/sbin/httpd
apache   10226  0.2  5.1 287872 31640 ?        S    10:50   0:20 /usr/sbin/httpd
apache   10376  0.2  5.0 288340 30856 ?        S    11:03   0:16 /usr/sbin/httpd
apache   10453  0.2  5.2 288416 32384 ?        S    11:10   0:16 /usr/sbin/httpd
apache   10455  0.1  5.2 288124 32252 ?        S    11:10   0:15 /usr/sbin/httpd
apache   10457  0.2  4.8 288380 29676 ?        S    11:10   0:15 /usr/sbin/httpd
apache   10459  0.1  5.2 288636 32224 ?        S    11:10   0:14 /usr/sbin/httpd
apache   12106  0.2  4.8 288384 29536 ?        S    13:07   0:01 /usr/sbin/httpd
apache   12107  0.2  4.8 288380 29480 ?        S    13:07   0:02 /usr/sbin/httpd
apache   12110  0.2  4.8 288380 29496 ?        S    13:07   0:01 /usr/sbin/httpd
Adam C.
  • 193
  • 1
  • 9

2 Answers2

2

It probably wouldn't hurt to create a file system swap.

#!/bin/bash -e

# Set default variable values
: ${SWAP_SIZE_MEGABYTES:=1024}
: ${SWAP_FILE_LOCATION:=/var/swap.space}

if (( $SWAP_SIZE_MEGABYTES <= 0 )); then
    echo 'No swap size provided, exiting.'
    exit 1
elif [ -e "$SWAP_FILE_LOCATION" ]; then
    echo "$SWAP_FILE_LOCATION" already exists,  skipping.  
fi

if ! swapon -s | grep -qF "$SWAP_FILE_LOCATION"; then
    echo Creating "$SWAP_FILE_LOCATION", "$SWAP_SIZE_MEGABYTES"MB.
    dd if=/dev/zero of="$SWAP_FILE_LOCATION" bs=1024 count=$(($SWAP_SIZE_MEGABYTES*1024))
    mkswap "$SWAP_FILE_LOCATION"    
    swapon "$SWAP_FILE_LOCATION"
    echo 'Swap status:'
    swapon -s
else
    echo Swap "$SWAP_FILE_LOCATION" file already on.
fi

echo 'Done.' 

Source

Holocryptic
  • 5,665
  • 2
  • 29
  • 37
  • I ran that script, and got error, – Adam C. May 13 '11 at 18:12
  • Thank you! I ran that script, and got error, `[: -eq: unary operator expected`, looks like $SWAP_SIZE_MEGABYTES is not available in the server. Also, my instance is micro, and not Large or Extra-Large as the source mentioned. BTW, my question was if my current memory usage is normal or not. – Adam C. May 13 '11 at 18:22
  • I think the first link was just a snippet of code. I went to the source and pulled that and updated my answer. As to whether or not it's normal, I can't say. But I do know that *usually* not having swap is detrimental to performance. – Holocryptic May 13 '11 at 18:30
  • Thanks! I did that, and now I have 1G swap memory. Do you know how it decide to use swap or physical ram (or how it to keep balance)? BTW, there is a typo on line 7, `SWAP_SIZE_MEGABYTES` should be `$SWAP_SIZE_MEGABYTES` – Adam C. May 13 '11 at 19:19
  • The OS manages swap. You don't really decide how it's being used. – Holocryptic May 13 '11 at 19:21
  • I am going through my serverfault questions, and accepting the correctly questions. Some questions were very old almost 3 years. :-(. Actually I have not used Apache for my personal project, and highly recommend Nginx, which is much much efficient even with much less resources. Anyway, I accepted this one as correct answer. – Adam C. Feb 18 '14 at 16:18
2

Edit your /etc/apache/apache.conf file and set your MaxClients to 30. Keep an eye on your apache error log to see if you run out of clients and if so increase your MaxClients by 5. After you no longer receive errors add another 5 just to provide a little headroom.

You could also check your /etc/php5/apache/php.ini for the memory_limit setting. For just WordPress you could probably get away with 64MB for that setting. If you are running any graphics manipulation (e.g. thumbnail generators, etc) then you will need to bump that up to possibly 96MB.

If you are also running MySQL on that server you should check to see if you could reduce some of your key index sizes or other memory eating settings.

daemonofchaos
  • 1,211
  • 1
  • 8
  • 10
  • Thanks! By adding swap, the server seems to be OK now. I will try your suggestion some other day. And I will also try move mysql to another instance if I have enough instance hour. – Adam C. May 14 '11 at 02:27