Advertisement
shottamo

memory usage

Feb 28th, 2015
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. Ok, first of all the main contributors to your memory consumption seems to be the passenger rack app and java.
  2.  
  3. To limit the phusion passenger RAM consumption, you can limit the memory consumption by limiting the amount of processes spawned in the process pool size.
  4.  
  5. See the documentation for more information.
  6.  
  7. https://www.phusionpassenger.com/documentation/Users%20guide%20Nginx.html#PassengerMaxPoolSize
  8.  
  9. Now for the Java process:
  10.  
  11. Java has a couple of settings that help control how much memory it uses:
  12.  
  13. -Xmx sets the maximum memory heap size
  14. -Xms sets the minimum memory heap size.
  15. Keep -Xms Small
  16. For a server with a 'small' amount of memory, then we recommend that -Xms is kept as small as possible. e.g. -Xms 16m. Some customers set this higher, but that can lead to issues. e.g. the command that restarts tomcat runs a java process. That Java process picks up the same -Xms setting as the actual Tomcat process. So you will effectively be using two times -Xms when doing a restart. If you set -Xms too high, then you may run out of memory.
  17.  
  18. Don't Let -Xmx Be Too Low
  19. When setting the -Xmx setting you should consider a few things... -Xmx has to be enough for you to run your app. If it is set too low then you may get Java OutOfMemory exceptions (even when there is sufficient spare memory on the server).
  20.  
  21. As far as I understand, the -Xmx1g of your process sets the heap memory; however, the process includes additional memory spaces as well.
  22.  
  23. I suggest starting with these values and see how the app performs.
  24.  
  25. -Xms128m -Xmx256m
  26.  
  27. Check the logs of the application for any errors.
  28.  
  29. There are good explanations of the Java process memory allocation at the official Java documentation:
  30.  
  31. http://docs.oracle.com/cd/E13222_01/wls/docs81/perform/JVMTuning.html#1109778
  32.  
  33. And
  34.  
  35. http://stackoverflow.com/questions/6897476/tomcat-7-how-to-set-initial-heap-size-correctly
  36.  
  37. http://blogs.vmware.com/apps/2011/06/taking-a-closer-look-at-sizing-the-java-process.html
  38.  
  39. http://java.dzone.com/articles/java-performance-tuning?page=0,1
  40.  
  41. According to the fourth one, is not unusual for the total memory consumption of the VM to exceed the value of -Xmx.
  42.  
  43. You can try playing with the -XX:MaxPermSize setting or limit the number of threads (-Xss) to see if this will decrease the JVM process memory consumption.
  44.  
  45. Lastly, to track your RAM usage:
  46.  
  47. We have a python script available on our wiki:
  48. http://wiki.webfaction.com/attachment/wiki/MiscellaneousFiles/memory_usage.py
  49.  
  50. You can use the following command to download it:
  51. wget -O ~/bin/memory_usage.py 'http://wiki.webfaction.com/attachment/wiki/MiscellaneousFiles/memory_usage.py?format=raw'
  52.  
  53. Then change the permissions to make it executable.
  54.  
  55. chmod 755 ~/bin/memory_usage.py
  56.  
  57. Then, simply run it: memory_usage.py (or ~/bin/memory_usage.py)
  58.  
  59. It will show you the total memory usage for all of your processes, along with their Process IDs for easy management. :)
  60.  
  61. You can also set up a cronjob that will execute the script at certain periods and store the results in a log file.
  62.  
  63. 0 */1 * * * ~/bin/memory_usage.py >> $HOME/logs/user/cron.log 2>&1
  64.  
  65. That will run the script every hour.
  66.  
  67. I hope this helps.
  68.  
  69. Please let us know if you have any questions.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement