1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Optimal settings for VPS with 512MB ram (memory issue)

Discussion in 'Server Configuration and Hosting' started by Arkshine, Apr 1, 2013.

  1. Arkshine

    Arkshine Active Member


    Recently I've noticed my forum starting to slow-down and it would be seem server eats too much memory that it uses almost all the available swap most of time.
    I guess it's time to configure properly all the softwares since I got more hits than at the start.

    Just as note, I don't know much and the current configuration is from different tutorials here and there, but I am willing to do any manipulations. I want to have a fast forum !

    Here the relevant informations :

    • VPS with 512MB RAM + 362 MB for swap
    • Contains only one XenForo forum and don't plan to add more
    • Small community, don't have much visits for now since forum is fairly new
    • OS : Debian 6 32 bits (2.6.32-xenU-7428-i386)
    • PHP-FPM 5.3.23-1~dotdeb.0
    • MariaDB 5.5.30
    • varnish 3.0.3 as frontend
    • nginx 1.2.7 as backend
    • memcached 1.4.15 (with Libmemcached 1.0.10)
    • APC 3.1.13
    The relevant settings which are uncommented :
    • About PHP-FPM

      pid = /var/run/php5-fpm.pid
      error_log = /var/log/php5-fpm.log
      log_level = notice
      emergency_restart_threshold = 10
      emergency_restart_interval = 1m
      process_control_timeout = 5s
      user = www-data
      group = www-data
      listen = /var/run/php5-fpm.sock
      listen.owner = www-data
      listen.group = www-data
      listen.mode = 0666
      pm = dynamic
      pm.max_children = 10
      pm.start_servers = 1
      pm.min_spare_servers = 1
      pm.max_spare_servers = 3
      pm.process_idle_timeout = 10s;
      pm.max_requests = 1000
      slowlog = /var/log/php5-fpm/$pool.log.slow
      request_slowlog_timeout = 5s
      request_terminate_timeout = 120s
    • About MariaDB

      Probably this one eating too much memory.

      port= 3306
      socket= /var/run/mysqld/mysqld.sock
      socket= /var/run/mysqld/mysqld.sock
      nice= 0
      # * Basic Settings
      user= mysql
      pid-file= /var/run/mysqld/mysqld.pid
      socket= /var/run/mysqld/mysqld.sock
      port= 3306
      basedir= /usr
      datadir= /srv/d_cs-amx/mysql
      tmpdir= /tmp
      lc_messages_dir= /usr/share/mysql
      lc_messages= en_US
      # * Fine Tuning
      max_connections= 20
      connect_timeout= 5
      wait_timeout= 28800
      max_allowed_packet= 32M
      thread_cache_size    = 50
      sort_buffer_size= 4M
      bulk_insert_buffer_size= 16M
      tmp_table_size= 32M
      max_heap_table_size= 32M
      join_buffer_size= 256K
      # * MyISAM
      # This replaces the startup script and checks MyISAM tables if needed
      # the first time they are touched. On error, make copy and try a repair.
      myisam_recover          = BACKUP
      key_buffer_size= 128M
      open-files-limit= 5000
      table_open_cache= 2000
      myisam_sort_buffer_size= 128M
      concurrent_insert= 2
      read_buffer_size= 2M
      read_rnd_buffer_size= 1M
      # * Query Cache Configuration
      query_cache_type= OFF
      # * Logging and Replication
      log_warnings= 2
      slow_query_log= 1
      slow_query_log_file= /srv/d_cs-amx/mysql/log/mariadb-slow.log
      long_query_time= 5
      log_slow_verbosity= query_plan
      log_bin= /srv/d_cs-amx/mysql/log/mariadb-bin
      log_bin_index= /srv/d_cs-amx/mysql/log/mariadb-bin.index
      sync_binlog= 1
      expire_logs_days= 3
      max_binlog_size        = 100M
      # * InnoDB
      default_storage_engine= InnoDB
      innodb_buffer_pool_size= 128M
      innodb_log_buffer_size= 8M
      innodb_file_per_table= 1
      innodb_open_files= 1024
      innodb_io_capacity= 1024
      innodb_flush_method= O_DIRECT
      innodb_thread_concurrency= 0
      innodb_stats_on_metadata= off
      innodb_old_blocks_time= 1000
      max_allowed_packet= 16M
      #no-auto-rehash# faster start of mysql but no tab completition
      key_buffer= 16M
    • About Varnish


      http://pastebin.com/uZNceAnj (takes too much caracters :p)

      # Should we start varnishd at boot?  Set to "no" to disable.
      # Maximum number of open files (for ulimit -n)
      # Maximum locked memory size (for ulimit -l)
      # Used for locking the shared memory log in memory.  If you increase log size,
      # you need to increase this number as well
      ## Alternative 2, Configuration with VCL
      # Listen on port 6081, administration on localhost:6082, and forward to
      # one content server selected by the vcl file, based on the request.  Use a 1GB
      # fixed-size cache file.
      DAEMON_OPTS="-a :80 \
                  -T localhost:6082 \
                  -f /etc/varnish/default.vcl \
                  -S /etc/varnish/secret \
                  -s malloc,256m"
    • About nginx


      userwww-data www-data;
      # As a thumb rule: One per CPU. If you are serving a large amount
      # of static files, which requires blocking disk reads, you may want
      # to increase this from the number of cpu_cores available on your
      # system.
      # The maximum number of connections for Nginx is calculated by:
      # max_clients = worker_processes * worker_connections
      # Change these paths to somewhere that suits you!
      error_log  /var/log/nginx/error.log;
      # Maximum file descriptors that can be opened per process
      # This should be > worker_connections
          # When you need > 8000 * cpu_cores connections, you start optimizing
          # your OS, and this is probably the point at where you hire people
          # who are smarter than you, this is *a lot* of requests.
          log_format            main '$remote_addr - $remote_user [$time_local] $request '
                                  '"$status" $body_bytes_sent "$http_referer" '
                                  '"$http_user_agent" "$http_x_forwarded_for" "$gzip_ratio"';
          # Click tracking!
          #access_log/var/log/nginx/access.log main;
          gzip_disable"MSIE [1-6]\.(?!.*SV1)";
          gzip_buffers32 8k;
          client_body_buffer_size 10m;
          client_body_temp_path  /var/spool/nginx/client_temp 1 2;
          port_in_redirect off;
          include /etc/nginx/sites-enabled/*;

      http://pastebin.com/u0cd58LS (takes too much caracters :p)
    • About memcached

      With session/igbinary/json support enabled.
      Used with XF :

      $config['cache']['enabled'] = true;
      $config['cache']['cacheSessions'] = true;
      $config['cache']['frontend'] = 'Core';
      $config['cache']['frontendOptions'] = array(
          'caching'=> true,
          'cache_id_prefix'=> 'xf_',
          'automatic_serialization'=> true,
          'lifetime'=> 0
      $config['cache']['backend'] = 'Libmemcached';
      $config['cache']['backendOptions'] = array(
          'servers' => array(
              'host'=> '',
              'port'=> 11211,
              'weight'=> 1
      DAEMON_OPTS="-u nobody \
                -m 16"
      extension = memcached.so
      session.save_handler = "memcached"
      session.save_path = ""
      memcached.sess_locking = On
      memcached.sess_lock_wait = 150000
      memcached.sess_prefix = "memc.sess.key."
      memcached.sess_binary = Off
      memcached.compression_type = "fastlz"
      memcached.compression_factor = "1.3"
      memcached.compression_threshold = 2000
      memcached.serializer = "igbinary"
      memcache.hash_strategy = "consistent"
    • About APC

      apc.cache_by_default= 1
      apc.canonicalize= 1
      apc.coredump_unmap= 0
      apc.enable_cli= 0
      apc.enabled= 1
      apc.file_md5= 0
      apc.file_update_protection= 0
      apc.gc_ttl= 1200
      apc.include_once_override= 0
      apc.lazy_classes= 0
      apc.lazy_functions= 0
      apc.max_file_size= 10M
      apc.mmap_file_mask= /tmp/apc-mmap.XXXXXX
      apc.num_files_hint= 1000
      apc.report_autofilter= 0
      apc.rfc1867= 1
      apc.rfc1867_freq= 512k
      apc.rfc1867_name= APC_UPLOAD_PROGRESS
      apc.rfc1867_prefix= upload_
      apc.rfc1867_ttl= 1200
      apc.serializer= igbinary 
      apc.shm_segments= 1
      apc.shm_size= 64M
      apc.shm_strings_buffer= 4M
      apc.slam_defense= 0
      apc.stat= 1
      apc.stat_ctime= 1
      apc.ttl= 0
      apc.use_request_time= 1
      apc.user_entries_hint= 4096
      apc.user_ttl= 0
      apc.write_lock= 1
    I think that's all.

    You will agree with a VPS/512MB and one forum, it should be fine fairly up to medium community. So, it's a real problem it uses alread all the swap with only few connections.

    As note, I'm willing to hire someone to configure/optimize this configuration. So, for people who know well this stuff, it would be some easy money, if interested send me a PC.

    Anyway, many thanks in advance for people who will advive/suggest/help me. :)
  2. Sheratan

    Sheratan Well-Known Member

    Well, I'm surely I wasn't the expert about this. But I just want to ask some questions:

    1. Why use 32-bit Debian? Not 64-bit?
    2. You use APC + Memcached. I think that's enough. Why you use Varnish too?
  3. Arkshine

    Arkshine Active Member

    1. Don't remember exactly but considering the memory (only 512), and because I wanted to avoid any problem related x32/x64, I've prefered x32.
    2. Not sure why. I've read it was really fast to use Libmemcached as cache for $config['cache']['backend'] but honestly I'm not sure what does XF with this "cache". When I look the usage, it doesn't use much, that's why, I've allocated only 16MB for that. But I've noticed a small diffrence with and without, and would seem better with.
  4. Jeremy P

    Jeremy P Well-Known Member

    Stick with 32bit unless you have 4+ GB of memory. 32bit apps will use slightly less memory so I'd stick with it for a 512.
  5. Slavik

    Slavik XenForo Moderator Staff Member

    1) You should use x64, you won't have any problems with it. I guess from your x86 choice your new to managing your own server?

    2) If your a new startup board your setup is overkill and probably misconfigured to serve up a small XenForo site.

    I would reload with a 64 bit OS. Load up apache, with APC and percona, and see where that takes you for the time being.
  6. Jeremy P

    Jeremy P Well-Known Member

    I don't believe there are any benefits of x64 on a system with only 512mb memory. 64-bit OS come with some memory overhead, and 32 bit works just as well.
  7. Arkshine

    Arkshine Active Member

    Apache ? Is nginx that bad ? I've heard it was running better than Apache, at least is lighter.

    As it is the forum runs fairly fine, mainly because there are not much visits, even when the swap is used and sometimes you feel some unexpected waiting, but I'm afraid if a lot more, things won't follow.

    If possible, before reinstall all from scratch, I would like to try and expect more some advice to adjust configuration settings for the current softwares and for 512MB, especially for mysql, as after many read here and there, varnish + nginx + mariaDB + php-fpm were the very good & fast config to use ; or it's actually bad ? :p

    Thanks for the answers.
  8. Sheratan

    Sheratan Well-Known Member

    I think this is not an issue in server enviroment. But this can be an issue in dekstop.

    ps: I run a small VPS (Debian 6 64-bit, 512MB) to serve a WP and had no problem so far

    And yes, I think your setup is over kill. APC + Memcached + Varnish? I would prefer use APC only first.

    NGINX is good. (y)
  9. Slavik

    Slavik XenForo Moderator Staff Member

    I just think your trying to overkill a setup which doesn't need overkilling.

    If I was going to start out a new VPS for a brand new forum, I would load it with

    CentOs 6.4 x64, Apache/Free Litespeed + PHP, Percona with XtraDB, and thats about it in reality.

    Just my preference at least.
  10. Arkshine

    Arkshine Active Member

    Sheratan, I've tried APC only, it was so slow. :p Once you put varnish, page loads in a blink eye, it's significant faster. I guess I could remove Memcached but since allocated to 16MB only, I'm not sure it's an issue too, but It's true it sounds like something I could remove.

    @Slavik, I don't mind to start config from scratch, but is it really worth ? At least for a XF forum, it would way faster and eating way less memory ?
    After all I've read, people praising varnish/php-fm/nginx/MariaDB, you advice something totally different, I'm not sure what to do now. :p
  11. Sheratan

    Sheratan Well-Known Member

    I don't and never use APC (xCache FTW). But maybe you have some misconfiguration in xF cache setup or APC.
  12. Slavik

    Slavik XenForo Moderator Staff Member

    Apples and oranges, all people have their own preferences. My preference on a new startup site is keep it simple.
  13. SneakyDave

    SneakyDave Well-Known Member

    I've had problems with memory with 512M RAM and 64bit OS. In my opinion, I'd stick with 32bit. I've had good luck with just 512M RAM, nginx, APC, and MySQL (or MariaDB), and ignoring memcache and varnish until more memory is available for it.

    I eventually had a lot of fragmentation in APC with this 512M RAM setup, but that was because I was trying to serve a number of different sites with it. If you just have one, I suspect you wouldn't have many problems. If you do, I might suggest to restart php-FPM as needed, weekly or monthly when fragmentation gets out of control..

    This is what I use for 512M RAM VPS's in my.cnf. Not sure what the equivalent is for MariaDB, assuming it uses the same db configuration.

    max_allowed_packet = 5M
    thread_stack = 64K
    maszd and Jeremy P like this.
  14. Jeremy P

    Jeremy P Well-Known Member

    Nginx is loads better than Apache, I wouldn't get rid of it. Even without optimal settings it performs better than Apache.

    What's most likely to be consuming resources is mysql/mariadb. That is what I would work on tuning. I wish I could offer more help but tuning mysql has never been easy for me.

    I'd also dump varnish and memcached if your site is not that big. Use APC for cache instead since you already have it installed.
  15. Arkshine

    Arkshine Active Member

    @Slavik : I like when It's simple too but I'm worried about performance. Will take a look to Litespeed. Btw, MariaDB uses XtraDB too, and I've read benchmark MariaDB was the best for mixed InnoDB and MyISAM usage environments. Any thoughts on it ?

    @SneakyDave : Thanks ! What do you use then in the backend cache in XF config ? I might try to reduce varnish memory or removing, not sure yet.

    Random question, about mysql, I can turn off safely the replication thing (not sure what is about), because it ates spaces a lot ?


    @Jeremy, thanks for your advises. I guess I will give a try without varnish again, it will free 256 MB, I guess it will help for sure. About Mysql, I would like someone proposes good default values for 512 MB. :p
  16. Jeremy P

    Jeremy P Well-Known Member

    MariaDB vs Percona is more of a preference thing imo. I personally prefer MariaDB. Wouldn't waste time switching to Percona as it's not likely to solve the problem at hand.

    I also would stick with nginx over litespeed, if for no other reason than it's already installed and running and performs very well itself.

    Use APC for the backend cache in XF config. I would remove Varnish and focus on optimizing your site without it first.
  17. SneakyDave

    SneakyDave Well-Known Member

    You can use a File cache backend. It's not as glamorous, but it gets the job done.

    In config.php
    $config['cache']['backend'] = 'File';
    $config['cache']['backendOptions']['cache_dir'] = '/some/place/to/store/this/file/that/should/be/writable/by/the/webserver/xf_backend_cache';
  18. WSWD

    WSWD Well-Known Member

    Something is very, very wrong here. We have clients run cPanel with dozens of websites on 512mb VPSs, and still have plenty of power left. It's not recommended, but I've seen it done. There is no way a brand new forum with nothing else installed should be having an issue on that VPS.

    You sure you're actually running out of RAM? http://www.linuxatemyram.com/
    karll likes this.
  19. Arkshine

    Arkshine Active Member

    It's just starting to be an issue ; when you see the forum is not reactive as before, sometimes with obvious slowdown, and when you check memory, all is used including most of the swap, for me it's clear it's out of RAM at this point, right ?
    For now it's minor issue, but I would like to prevent any further problems when I will have more hits and would like to fix configuration while I'm around.

    I think I will take another VPS just for one month to test suggestions done above.
    @Slavik, just seen Litespeed is not free, at least the full version, is the standard version running well ? because I've read some comment it was not really good.

    Meanwhile, I would like to have some concrete settings with 512 MB for at least mysql/nginx, because still not sure how to configure them properly for my use (one XF forum) and it's probably one the reason after some times swap is used. Will try SneakyDave's suggestion about msysql but more suggestions/explanations to have a good base configuration for this amount of memory would be very welcomed. Is there some expert around ? :p
  20. WSWD

    WSWD Well-Known Member

    Did you check out the link from my previous post? It explains RAM usage in linux. Your RAM might show itself as being used, when it's actually being used for disk caching or such.

    A lot of people simply don't understand how memory usage works in linux, and as a result, you get all sorts of wacky advice. If your forum is the one in your profile (currently with 2 users online), there is no possible way that should be using all 512mb of RAM, assuming that's all you have running on your VPS. I would be absolutely shocked if it actually was using all that RAM.
    SneakyDave likes this.

Share This Page