Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


MySQL and PHP optimization
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

MySQL and PHP optimization

bboranbboran Member
edited November 2011 in Help

hello i am running a 512mb vps. i am only using it for 1 site which is a wordpress driven content sharing site which is also running on nginx web server. can you help me to optimize mysql and php? for example a typical my.cnf settings for a 512mb vps should be good. by the way right now with a clean install of nginx, php5-fpm , mysql and wordpress my memory usage is this

Mem:           497 (total)        343(used)        153(free)

is this normal? thanks.

Comments

  • Is OpenVZ? FIRST tip, try disabling Inno-DB

    Otherwise... http://www.linuxatemyram.com/

  • it is xen (linode) also forgot to paste the buffers/cache output from free -m here it is;

    -/+ buffers/cache: 119(used) 377(free)

  • cleonardcleonard Member
    edited November 2011

    I think that yomero must be on the right track. Using Debian packages I got the nginx, two php-fpm children, and innodb off mysql stack going in a bit over 100 mb of OpenVZ space. Compiling from nginx/php from sources and only including what I needed I got the same with three php children in under 80mb.

    With a 512 I might even run with innodb turned on.

  • 119 MB used, I don't see any problem with your setup

  • ok but can i optimize the mysql and php ? cause i didnt touch any cnf file yet.

  • divyadivya Member
    edited November 2011

    The default config for mysql won't have any issues with even 256mb vps on a xen box. You should start worrying if your -/+ buffers/cache starts showing more than 80% used and if you are expecting considerable traffic increase(which is sometimes predictable).

    Standard install of php-fpm will have lot many child processes running, but you should leave them untouched for your config.

    Instead of trying to free up more memory, you should rather use more of the available memory for better performance. And since it is a wordpress driven site, you can actually look at increasing mysql buffer sizes.

    suggestion(not an expert but this is what I would use if they are less than that)

    key_buffer = 64M

    query_cache_size=32M

    To improve the overall experience of your wordpress site, consider some form of caching(preferably caching plugins for wp)

    http://codex.wordpress.org/WordPress_Optimization/Caching

    Do some stress testing.

    Easy one for starters is http://loadimpact.com

    And finally, do some googling on the topic and understand your setup. It is much better then simply(read blindly) implementing what some unknown divya or familiar yomero or the friendly cleonard says :)

    Edit:
    While stress testing, it is a good idea to watch the server behavior.
    Just ssh into the box and run 'top'. Watch 'top' screen while the test runs.

    While 'top' is running, press > on your keyboard to see the results sorted by memory usage. It is more comfortable and useful that way while doing a memory related test.

  • Thank you very much for your usefull informations mates. I'll try them.

  • If it's wordpress, first thing i would do is install a caching plugin and make sure it's working.

    Someone else is going to have to make suggestions here. Lost 4+ days dealing with the OS change over and I'm very behind. Plus I don't know what's current any more.

  • Do you have a PHP opcode cache installed (APC, xcache, eaccelerator, etc)? If not, install one.

  • Yes i have installed APC and thinking of using it with w3 total cache for page caching but a friend told me "My experience in setting Page Caching to use APC from W3TC on 512MB was not good. Memory use shot through the roof as the APC cache filled up instantly. You’ll need 2GB of RAM min. I think before thinking about switching Page Caching to use APC. For smaller VPS’s and shared hosts you’ll get much better results using enhanced Page Caching."

    so what do you think mates? thanks.

  • You specify the amount of RAM used by APC, and for default is 128MB. I am almost sure that your friend was using Apache, and it creates and destroy lots of php instances. You just run the amount that you want.

  • bboranbboran Member
    edited November 2011

    No he is using nginx too =) 128 is enough for start?

  • SimplyfastSimplyfast Member
    edited November 2011

    @bboran said: Memory use shot through the roof as the APC cache filled up instantly. You’ll need 2GB of RAM min

    Yomero is right,

    First of all, APC and W3TC are different, APC only caches PHP scripts, while W3TC caches everything, APC is some kind of backend for W3TC, as I see it.

    I'm using Apache with APC on 512MB XEN, no W3TC (no static pages), I use NGiNX in front of Apache to deliver static files. I allowed APC to use 60MB. It's a small community with heavy site, but with 200 uniques per day. RAM usage never grows more than 230MB with full set of LAMP + NGINX + ISPmanager (the time saver) + APC.

    I assume you need to install APC, set maximum allowed ram to, let's say 90. Check if it fills up, if not, reduce the ammount and so on.

    Then install W3TC and check RAM usage. You can always disable it.


    To reduce the RAM usage just play with Apache and MySQL configs. There is enough tutorials about this.

  • are there some good tutorials about nginx + apc? thanks.

  • What tutorial you need? You just need to compile/install and enable the plugin, nothing to do with Nginx.

  • I installed and enabled APC. Is that all =)

  • Restart php-fpm and check phpinfo to see if it's loaded.

  • bboranbboran Member
    edited November 2011

    Yeah its loaded. By the way the default apc.shm_size is not 128 it is 96.

  • @bboran said: By the way the default apc.shm_size is not 128 it is 96.

    It was 64mb by default every time I installed it.

  • @bboran said: Yeah its loaded. By the way the default apc.shm_size is not 128 it is 96.

    Better :P

  • Thank you mates.

Sign In or Register to comment.