Why is my website using so much of RAM on my Bluehost VPS plan?

Discussion in 'Web Hosting' started by D S Aman, Feb 20, 2015.

  1. #1
    I have a Bluehost VPS plan with 2 GB RAM for my website.

    The link of my website is: riseforindia.com

    Yesterday, when my site had only 5-10 visitors at once, the RAM maxed out, and my site started giving out 502 Gateway timeout error. I contacted Bluehost support, and they told me to add more RAM. But my traffic was so low, how can 2GB RAM max out for so low traffic?

    I have been keeping an eye on my Memory usage since, and I have noticed that at anytime, my site is using 30-50% RAM. How can I decrease RAM usage? Can anybody please help me out?
     
    D S Aman, Feb 20, 2015 IP
  2. Profitup

    Profitup Greenhorn

    Messages:
    50
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    13
    #2
    It seems some of your WP plugin (or a few) takes many of memory... Try to find it and change/delete/optimize it. It should help -> http://www.stumiller.me/how-to-monitor-and-reduce-wordpress-memory-usage-by-plugins/
     
    Profitup, Feb 20, 2015 IP
  3. sysdev0

    sysdev0 Member

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    Digital Goods:
    1
    #3
    Since anyone can create addons for WordPress they are rarely optimized.
     
    sysdev0, Feb 20, 2015 IP
  4. billzo

    billzo Well-Known Member

    Messages:
    961
    Likes Received:
    278
    Best Answers:
    15
    Trophy Points:
    113
    #4
    Log in via SSH and run this command via command line:

    free -m

    Report back the results. Then try running the htop command (if that is not available, then run the top command). Take a screenshot and save it for your own future use. What programs are consuming large amounts of RAM?

    What web server are you running? Apache? Are you running Wordpress? With plugins? Are you running PHP as a DSO or CGI?

    There is a lot of ways you can configure a web server. With 2 GB of RAM, you should have more than enough to operate a web sever, certainly enough to handle 5 - 10 concurrent visitors. But it is impossible to say right now what the problem is. At this point I think you would get more mileage out of configuration changes than you would upgrading to a bigger package.

    The default VPS configuration rarely is optimal for your needs. The proper configuration is going to depend on a lot of factors, including concurrent users, amount of database queries, number of file requests per page, etc.
     
    billzo, Feb 20, 2015 IP
  5. D S Aman

    D S Aman Greenhorn

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #5
    I am running Apache, and yes Wordpress with plugins. But I tried deactivating all the plugins to see if there is a difference, but there was just around 1-2% difference in the memory usage as indicated in my WHM panel. I haven't worked with SSH before, because I am new to VPS and was on shared hosting earlier. So, I don't think I will be able to carry on those instructions that you have mentioned. Isn't there any other way?
     
    D S Aman, Feb 20, 2015 IP
  6. D S Aman

    D S Aman Greenhorn

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #6
    I tried deactivating all the plugins, and then checked memory usage in WHM panel. But there wasn't much difference. I am not sure if the WHM panel was showing correctly or not, but thats what it showed. I haven't worked with SSH before, so I didn't check via that. But I will try the points mentioned in the link that you have sent and I will get back to you.
     
    D S Aman, Feb 20, 2015 IP
  7. billzo

    billzo Well-Known Member

    Messages:
    961
    Likes Received:
    278
    Best Answers:
    15
    Trophy Points:
    113
    #7
    No, there really is no other way. It is quite simple, really.

    Download puTTY. Run puTTY and try accessing your VPS by its IP address (main IP address). You will need to enter your username and password, which is the same for accessing WHM. I imagine the user will be "root" (it could be different, but only you would know that). You know what your password is.


    Linux generally uses as much memory as possible. So it will almost always show near max consumption. That does not mean that memory is not available to programs. That is why you have to log in using SSH and run the free -m command. And your plugins only use memory on a page view. So you would have to check in the middle of a page view, so that is not feasible.

    Download puTTY and go from there.

    I re-read your original post. A 502 is not usually a memory error. There are a number of possibilities, including hitting your max number of child servers. What is your total traffic per day? Per hour? Page views and visitors.

    Also go into WHM and look for the Apache configuration. Find the max spare servers, child servers, KeepAlive, and other settings and then post them back here.
     
    billzo, Feb 20, 2015 IP
  8. D S Aman

    D S Aman Greenhorn

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #8
    I am really thankful for your help. I have attached a screenshot of memory usage on my server from SSH when only one visitor was present on my site. What else should I look for in SSH specifically?

    I am sure it is a memory error because I contacted Bluehost support and they told me specifically that my RAM had maxed out during my downtime, and I should add more RAM to my account to avoid it in future.

    My total traffic daily varies from between 1000-10000 daily. My traffic comes mostly from Facebook, so it varies a lot depending upon which articles are working on Social media. But on average, I get around 3-5000 people on my website on a daily basis. Page views is not much more than visitors. Almost 1.25 times the visitors.

    Here are the details that I found in Apache Configuration:

    Start servers: 5
    Min spare servers: 5
    Max spare servers: 10
    Server limit: 256
    Max clients: 150
    Max requests per child: 10000
    Keep-Alive: off
    Keep-Alive Timeout: 5
    Max Keep-Alive Requests: 100
    Timeout: 300

    & here, maybe this is of some significance.. My Apache RLimits is disabled under Memory Usage Restrictions. Should I enable that and set a memory restriction? The recommended setting mentioned there is 383 MB.
     

    Attached Files:

    D S Aman, Feb 20, 2015 IP
  9. billzo

    billzo Well-Known Member

    Messages:
    961
    Likes Received:
    278
    Best Answers:
    15
    Trophy Points:
    113
    #9
    Then you can click the "Like" link at the bottom right of my posts. :)

    Log into SSH and run the htop command. We want to see how many Apache and database processes you have running and how much memory they are consuming. Take screenshots of the entire output. Then hit the F5 key so the output will be displayed in tree view where the processes will be grouped together. Also take screenshots of the tree view.

    http://www.thegeekstuff.com/2011/09/linux-htop-examples/

    If you do not have htop available on your system, run the top command instead.

    If you are getting a crush of visitors at the same time, then you could certainly be hitting a memory or number of servers problem. Even a dedicated server can slow to a crawl or crash if it gets thousands of visitors in a short period of time. If your traffic is distributed through the day, then you should not be having any problem because you have plenty of memory available. In your memory screenshot you posted, look in the -/+ buffers/cache line under the free column. That shows 1,438 MB of RAM free for programs to run. So with very little visitors you have more than enough RAM.

    Do you get a large amount of visitors all at the same time? If so, you could try CloudFlare or upgrade to a higher VPS package. Or you could try using a caching plugin in W3 Super Cache. so your site will serve static HTML and reduce resource consumption, especially database queries. That will be cheaper than a hosting upgrade.

    I ran a test of your site on tools.pingdom.com. It loaded pretty fast considering it has 115 requests for the home page on first load. It looks like you are off-loading some images to i1.wp.com instead of serving them from your server, is that correct?

    With that many file requests, I would probably enable KeepAlive and set the Timeout to a low value like 2 seconds. But it is going to depend on how much traffic you have all at one time. There are pros and cons to KeepAlive. You can read more about KeepAlive here:

    http://abdussamad.com/archives/169-Apache-optimization:-KeepAlive-On-or-Off.html

    http://httpd.apache.org/docs/2.2/mod/prefork.html

    No, I see no point in doing that now. You do not have a memory problem during normal operation. If you get a lot of visitors all at once, then you probably will have a problem with your memory limit. A Wordpress caching plugin will help with that. You could also try CloudFlare.
     
    billzo, Feb 21, 2015 IP
  10. D S Aman

    D S Aman Greenhorn

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #10
    I would love to, but I can't find like button at bottom right. All I can see is a Quote button and a Reply button. I am new to Digital Point, sorry for being such a fool! :p

    I have attached the screenshots as you have asked. But its just a screenshot after the top command (htop wasn't working). F5 button yielded no result.

    I am more concerned with that 438 MB of RAM being used currently with just 1 or 2 concurrent users. Because I want to fix the issue before a traffic spike comes in.

    Generally, I don't get large amount of visitors at a time. Under average conditions, it is about 100-150 visitors at prime time on website during high traffic days. And am already using W3 Total Cache and Cloudfare too.

    Okay, I will dig into more of this to find out about Keep-Alive. Thanks for the links to get me started. Is it okay, if I switch on Keep Alive directly from WHM panel instead of using SSH?


    Basically, what I am more curious about is that what is using that 438 MB of RAM on my server when all that I am having at that point of time is 1 or 2 concurrent users on my website?

    And also, can you tell me that how much traffic per day (and also at a time) will my current VPS be able to handle under proper optimization conditions?
     

    Attached Files:

    • top3.png
      top3.png
      File size:
      22.1 KB
      Views:
      310
    D S Aman, Feb 21, 2015 IP
  11. billzo

    billzo Well-Known Member

    Messages:
    961
    Likes Received:
    278
    Best Answers:
    15
    Trophy Points:
    113
    #11
    That's okay. Your VPS does not have htop installed. It is a nice program to have. You could install it if you want through command line, or not. It is very helpful in situations like this. Much more helpful than the basic top command.

    That RAM is being used by the OS and programs. Even if you have no visitors, Apache and MySQL sit waiting for connections.

    That is a lot of visitors at one time. For the main page, there are 26 or so file requests from the server with the other stuff coming from other servers. That is a bit much, but not a whole lot. It is difficult to say without knowing how many file requests you are getting per second at peak.

    Also, I see in your HTML that you are using the Jetpack plugin. There are a lot of complaints about that plugin's memory consumption. You deactivated plugins as you mentioned earlier, but as I mentioned Linux tends to show consumption of most of the memory even when it is available. That memory figure you were looking at early is not very important for this purpose of finding the reason the 502 errors and memory gets used up. Even though you deactivated the plugin, the memory figure did not change much--as it would not because Linux shows it being used when it is available to programs.

    https://wordpress.org/support/topic/jetpack-and-its-insane-memory-consumption
    https://wordpress.org/support/topic/plugin-jetpack-by-wordpresscom-jetpack-is-extremely-heavy-plugin
    https://wordpress.org/support/topic/jetpack-maxing-out-memory-alocated

    Try disabling your Jetpack plugin before peak times then watch your site and see how it performs. Are you still getting 502 errors? If you install the htop program, you could take a screenshot during peak time and that will show you exactly what is consuming memory (and CPU). Looking at it during off-peak time does not provide very much information.

    If the Jetpack plugin sucks up as much memory as people complain it does, it could be the cause of your problems. You can only know for sure by disabling it before peak traffic.

    Don't worry about KeepAlive now. Focus on the Jetpack plugin. KeepAlive would only be enabled in WHM, not via command line (when using WHM/cPanel).

    If you are using a caching plugin, you should be able to serve many thousands of visitors per day provided they do not all come at the same time. CloudFlare will help even more. The number of visitors per day is not as important as whether or not they all come at the same time.

    Try disabling Jetpack before peak and see if that makes any difference. If you want more information, install the htop program via command line and observe your server's performance during peak times.
     
    billzo, Feb 21, 2015 IP
  12. D S Aman

    D S Aman Greenhorn

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #12
    Thanks for the suggestion. I will definitely look into it.

    The traffic is generally not on main page. Its basically on a single article page, referred through facebook. And people don't tend to generally view more than one page. Bounce off is pretty high, at around 80%. My Bluehost shared hosting even handled 150 visitors at a time, but it started giving out downtime, basically database error at high peaks of traffic due to which I switched to VPS. But it has been a little bumpy ride since then to get a knack of all these stuffs.

    I use Jetpack just because I like their Site stats interface, and because its easily accessible from the dashboard. I can surely get rid of it. And if not for that, jetpack may be a reason for another issue that I have been facing for past few days. Uploading of images has been failing continuously and I have had to increase memory limit for wordpress from wpconfig 2 times since last month. Maybe deactivating Jetpack will help.

    Also regarding memory consumption on server, I have read on different forums about configuring the Apache properly so that it works for your website. As mentioned on those forums, VPS is not of much use if not configured properly to increase site performance. Is that true? If yes, then what type of configurations does that refer to?
     
    D S Aman, Feb 21, 2015 IP
  13. billzo

    billzo Well-Known Member

    Messages:
    961
    Likes Received:
    278
    Best Answers:
    15
    Trophy Points:
    113
    #13
    That is somewhat true. The ideal configuration for a server will depend on the traffic, the type of content served, and more. Fact of the matter is there are hundreds of things you can do to optimize a server, most of which will not have much more than a little effect. For example, disabling .htaccess is a good way to optimize a server as using .htaccess is very inefficient.

    http://httpd.apache.org/docs/2.2/howto/htaccess.html

    Server optimization is limited when you are using WHM/cPanel as that is designed for ease of use and not high performance configurations. It's like building a race car. You can spend $100,000 developing an engine that is tiny bit faster than somebody else's engine. Question is whether or not you need to. You can spend many hours tweaking settings and experimenting to see what the idea configuration is or you can spend an extra $15 - $20 a month and upgrade your VPS.

    As far as what you should be concerned about, the things you already looked at like KeepAlive, number of servers, and stuff, are the a good place to start.

    As far as not having problems on shared, some web hosts are notorious for allowing customers to consume large amounts of server resources without regard to it affecting performance for other customers. A VPS has a limited amount of resources available to you. A shared server will have more memory and CPU cores available on the server as a whole and it is possible you may be using those greater resources for a small fraction of a second when your script runs. Many people think that a VPS will be faster than shared hosting and that is not always true. A VPS is for customization and being able to use its resources without worrying about being suspended for interfering with server performance. You can use your VPS for as much as you can get out of it.

    I think the first thing you should do is disable Jetpack then watch your server during peak times to see if the 502 error problem goes away.
     
    billzo, Feb 21, 2015 IP
  14. King-Servers

    King-Servers Greenhorn

    Messages:
    269
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    23
    #14
    It could be any script or database causing load on the server. Did you check the processes when the server load increases? It would be better if you post server logs to figure out what is causing load on the server.
     
    King-Servers, Feb 21, 2015 IP
  15. [ET]Alexander

    [ET]Alexander Well-Known Member

    Messages:
    66
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    100
    #15
    It is recommended when utilizing a platform such as cPanel/WHM that you have a recommended minimum configuration of 4GB memory. If you were to build the LAMP stack yourself and properly optimize it to allow for traffic, then a 2GB VPS might be capable of running your project. Keep in mind that without proper optimization, Apache and MySQL will use a great deal more memory than they should. Additionally, new cPanel installations come with MariaDB which is a much faster and reliable build of MySQL. The only issue, is that it does use a lot more memory in an idle state.
     
    [ET]Alexander, Feb 23, 2015 IP