Is it worth running memcache on my server? - php

This may seem like a newbie-ish question but I couldn't find an answer for this on google.
I have a server with 128mb of ram. I was wondering if installing memcache will help reduce serverload, say I sacrifice 5-10mb of ram to memcache. Is this even worth it? And if it is, how would I limit memcache to 5-10mb of ram?

I think you should replace apache with nginx first. This will allow you to reduce memory usage, probably even below 64MB, and also server load.
Then, you can allocate up to 60MB remaining memory to memcached, and it should help to reduce load even further.

Related

How can I prevent memory exhaustion using a CakePHP application?

I am on a VPS server (Quad core with 768MB of RAM. I am running Apache and using APC as my default caching engine) . I get around 2000 visitors per day with a maximum of 100 concurrent visitors.
According to CakePHP DebugKit, my most memory intensive pages use around 16MB and the other pages average at around 10MB.
Is this memory usage normal?
Is it normal for my memory to bottleneck at 2000 visitors per page?
Should I consider upgrading my plan to 2GB RAM?
I also noticed that the View rendering is taking up most of the memory, around 70% on most pages.
I am monitoring my resource usage, when I have around 50 or more concurrent users, I am getting 0 free MB left.
Thank you
You should also check your other processes. From my experience, MySQL takes up more memory than anything else on any stack that I run. You should also implement better page caching so that PHP doesn't need to be touched when it isn't absolutely necessary. But Apache is also a memory hog that needs to be fine tuned. If you want to stick with Apache, then run Varnish in front of it.
Also, keep APC, but also add Memcached. It's much faster.
If your site has a spike-load that brings it to zero memory, then, if you can, consider launching extra instances of the server and doing a sort of round-robin (if the VPS is cloud-hosted and this is possible). If the load is constant, then definitely upgrade.
#burzum is completely right, however, that you should just switch to nginx. It's far, far better than Apache at this point. But, just to put you on the right track, quite a few people run nginx as a reverse proxy in front of Apache, and while that does speed up the server, it's entirely unnecessary because nginx can do pretty much anything you need it to do without Apache. Don't bother using Varnish in front of nginx either because nginx can act as its own reverse proxy.
Your best bet is to implement nginx with apcu (upgrade php to 5.5 if possible for better performance) and use memcached, and implement nginx's native microcaching abilities. If your site is heavy on read and light on write, then you might notice that everything is taken care of by nginx just retrieving a cached copy from memcache. While this helps with memory, it also helps with processing. My servers' CPUs usually have a 3-5% usage during peaks.
Is this memory usage normal?
Yes, it doesn't seem to be high for a normal CakePHP application.
Is it normal for my memory to bottleneck at 2000 visitors per page?
I guess yes, I'm not a "server guy".
Should I consider upgrading my plan to 2GB RAM?
I would try switching to Nginx first. Apache is a memory eating monster compared to Nginx, just search for a few banchmarks, a random one I've picked by a quick search is from this page.
Overall Nginx should provide you a much better performance. At some stage I would consider updating the memory but try Nginx first.

PHP Memory Limit depends upon System's Hard Disk or RAM?

I want to know if PHP's memory limit depends upon the system's hard disk or RAM?
I tried searching on google for this, but didn't get satisfactory answer to this
It depends on how much ram you allow.. This setting is located at php.ini as memory_limit
The system is the one who manages how it gets the necessary ram. If there is RAM available or if it needs to access pagefile (swap), etc..
There are some physical limitations (OS Virtual Memory Size) but you are probably only reaching your allocated memory.
I would recommend to use ini_set('memory_limit', 'XXXXM'); in your code

How to reduce VPS memory usage

i have some problem with my VPS.
We are using a VPS to run our CMS and our websites, for now we have 300MB memory limit, and now we are close to reach the limit.
To maintain low cost(i know, increase memory is not to much expensive), but if i find a solution to optimize what we have, will be better.
What can i do?
Thanks!
I would suggest to increase memory - more memory, faster website :-)
But if speed is not important, reduce all cache sizes, set php memory_limit to 8M, disable opcode caching (APC, eAccelerator)
or try Raspberry Pi as server, now comes with 512MB :-)
I have a small 256MB vps which uses
apache + php + mariadb (mysqld)
I found memory was being gobbled by apache at every request 20MB at time for a simple wordpress page. It would settle but over time gobble into swap space and slow everything to a crawl. I suspect there are ways to fine tune mpm_event and mpm_worker to stop entering swap but I didn't figure out how.
When working in such tight environments it is important to know what is using what memory and reduce everything, so that swapping is minimized.
A summary of what I did follows, I managed to get 100MB physical headroom for tweaking, this is not a heavily loaded server but needs to be accessible (and cheap):
Using slackware (the os and default services seem to use less memory than debian, perhaps there is less loaded by default on my providers image)
Switch mysqld innodb tables off and use myisam
configure mysqld to reduce cache sizes if relevant
install cms fresh so they are definitely using myisam or alter all the tables
in apache choose to use the mod_mpm_prefork rather than mpm_event and mpm_worker ("apachectl -V" will tell you which is being used)
set sensible values for maxserver(start from low values for number of servers and requests and work up)
test the server under load whilst doing 'watch free' or 'top' through ssh
you should be able to see memory & the processes being created and destroyed as the load increases
adjust your httpd server settings and retest until happy
I like to see the memory max out at no more than 90% and reduce back down when the load is gone before I am convinced it will stay up without grinding to a halt (start using swap).
check your php.ini memory settings as stated in another answer.
I have also set a cron job to send me an email when swap starts to get used significantly, so I can restart something or even restart the whole server if I can't find what has used the memory, this should happen less and less the more you fine tune.
As stated this is not an environment that will perform well under heavy load but the cost may be more important to you.
Just my two pence worth...
I would look at Nginx like concerto49 recommended, if you have just one website on it also consider Litespeed (www.litespeedtech.com) they have a free version which may be sufficient to power your site.
If its PHP based, then strip out everything you're not using. Use APC/XCache to processing every request. Nginx also has a caching module, that could help so you can avoid hitting PHP for every request if its still fresh.
What type of VPS is it? OpenVZ? Xen? KVM? If it is OpenVZ does it have VSwap or Burst memory?
What type of CMS / Website are you running? Is it PHP based? Are you using Apache? If so have you tried nginx? I would look at optimizing the web server component and removing unused processes/applications to reduce memory and increase performance.

memcached resource requirements

I'm a newbie to memcache. My host(hostgator) says they recommend on memcahce on VPS 5 & up. I'm on VPS 4 (Centos, 2 Ghz, 1.3 GB ram 60 GB HDD) & VPS 5 is Centos, 2.7Ghz, 1.8GB ram, 80GB hdd.
Does memcache require so much resources ? I thought that VPS4 should do but my host thinks other wise. Can anyone suggest why memcahced resource needs are so high ?
thanks
Anita
That depends on how much data you want to store using memcache. All data will be kept in RAM, so if you are going to keep there a lot of data you will also need a lot of RAM. Well.. if your VPS4 RAM is completely used by sites/apps you already have there - it is reasonable to use VPS 5 (or even a system with large amount of RAM). Of course, it will use some additional CPU resources, but it needs should not be very high. But if you have on your VPS something simple enough - than it looks like they just want to sell VPS 5.
Determine how much data you are going to need to cache? You just need to have an idea for what size the data objects are going to be and how many of them you think there will be.
You really just need to look at the memcached stats... probably shoot for a hit rate of 90%+ (depending on application needs), an eviction rate of 0, and and perhaps around 50% memory usage when the cache is fully populated to provide for any growth needs, spikes, etc.
Once you know how much that memory allocation is, you can size your server's memory properly.

APC is showing 100% fragmentation

APC is showing 100% fragmentation. Is this bad?
Does it mean that it's not helping at all? What paths do I go down to improve situation?
Thanks in advance.
In my experience, yes. I had a system where APC was showing 100% fragmentation, and performance was bad. I increased APC's memory limit (to 200 MB in my case -- but we had a lot of code) enough to give it some slack room. Fragmentation dropped to zero, and IIRC, CPU usage on the server dropped by 50%.
Also, make sure you're using the apc.php script that comes with APC to monitor fragmentation/utilization. We've even written a nagios check to watch APC, 'cause we have enough traffic that apache locks up entirely when APC fills up.
Moral of the story: give APC enough memory, and monitor utilization.
Fragmentation means that apc often throws out items from it's cache and adds new ones and has trouble finding large enough continous blocks.
There are two main ways to improve performance then
Give more memory to APC. Ideally APC can store your complete scripts in memory.
use apc.filter in php.ini to filter out files which aren't requested often or change often.
Also using apc_store() with a short time to live is bad, as is overwriting using apc_store() often.
[...] Fragmentation is what hurts performance, not the size of memory per se. But it also seems that fragmentation happens when memory is low [...]
Note also that there seems to be a bug with apc.php's graph: http://pecl.php.net/bugs/bug.php?id=13146

Categories