• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here: Home » Optimize PHP5-FPM Memory Usage

By Abhishek Ghosh November 13, 2015 10:10 am Updated on November 13, 2015

Optimize PHP5-FPM Memory Usage

Advertisement

We Have Described the Way to Calculate the Total RAM Usage by PH5-FPM to Prevent Eating Up Memory to OOM. Optimize PHP5-FPM Memory Usage. It is not always easy to calculate and often, a not properly set and monitored RAM usage can miss any attack including XMLRPC Attack. Eating up memory can drive you crazy and server can reboot out of memory. We never suggest to use swap on cloud server instances, except for emergency need. What the providers supply for cloud servers, it is very difficult to predict. Using very high values of pm.max_children, pm.start_servers etc. is not exactly a great idea. It becomes the culprit for abnormal eating up of memory followed by reboot by the virtualization software. It is very bad & some web host may give warning. Your instances are sucking whole memory & suddenly releasing after reboot. These are towards doing odd suspicious works. Sysadmins understand that is not DDoS, but honestly that reboot is not good for your total system.

 

Optimize PHP5-FPM Memory Usage : Cloud Server & Provider

 

Calculation of real RAM is essentially impossible to physically calculate on cloud server – even without any cheating method applied by the provider. It is on a software defined layer above the real physical RAM. Obviously dedicated is the best choice but not exactly cost effective.

4GB RAM on Cloud Server is a good size for WordPress with MySQL on the same server. Rough calculation is – 1GB for Php, 1GB for MySQL, keep 1GB free and rest 1GB will be sucked by the other softwares including Nginx. Otherwise, it may become difficult to SSH in to instance on high load! 2GB RAM on Cloud Server is a good size for WordPress with MySQL on different server. Basically 3GB server does not exist and more instances you will have, more will be wastage of some memory. Instances basic operating system with some softwares will eat minimum 128MB RAM. Aruba Cloud, VPSdime, OVH – all are giving higher RAM at lower price. With increasing competition, there is no meaning to use the high RAM server on a well renowned provider like Rackspace. Keeping one instance of Rackspace in front as reverse proxy does the work of having great, white listed IP. Linode, DigitalOcean are in between services. There is basically no meaning of having “in-between” quality. With low RAM instance as Nginx reverse proxy on Rackspace or HP Cloud or Amazon, 100% uptime is near obvious.

Advertisement

---

 

Optimize PHP5-FPM Memory Usage : Calculations

 

Run free commands manually few times on random time gap, you should get something like this :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
root@localhost:~# free
             total       used       free     shared    buffers     cached
Mem:       4045132    1066992    2978140      38636      47000     171848
-/+ buffers/cache:     848144    3196988
Swap:       131068          0     131068
root@localhost:~# free
             total       used       free     shared    buffers     cached
Mem:       4045132    1044780    3000352      39112      49224     173696
-/+ buffers/cache:     821860    3223272
Swap:       131068          0     131068
root@localhost:~# free
             total       used       free     shared    buffers     cached
Mem:       4045132    1096056    2949076      42972      59264     193756
-/+ buffers/cache:     843036    3202096
Swap:       131068          0     131068

You can see that middle one had 3000352 MB RAM free. That means, RAM consumption is not increasing with time – that is suspicious! Run top command to check the load average. If RAM consumption is continuously increasing after restarting PHP5-FPM, it is likely a problem of wrong settings of /etc/php5/fpm/pool.d/www.conf file. This command will tell us average process memory :

Vim
1
ps -ylC php5-fpm --sort:rss | awk '!/RSS/ { s+=$8 } END { printf "%s\n", "Dr. Abhishek Ghosh Calculated Total Memory Used by PHP-FPM Child Processes is : "; printf "%dM\n", s/1024 }'

This is derived from :

Vim
1
ps -ylC php-fpm --sort:rss

For your easiness, I have created a script here on Github Gist, which can directly wget from this URL as raw file from server :

Vim
1
2
3
4
cd ~
wget https://gist.githubusercontent.com/AbhishekGhosh/01b935bc71200badd89f/raw/1d21fe369d14865371731b8cef81e18c3bf7a5b9/mem_php5.sh
 
chmod +x mem_php5.sh

whenever you’ll run sh mem_php5.sh from $HOME (~) location, you can easily get this output :

Vim
1
2
3
4
5
6
root@localhost:~# sh mem_php5.sh
 
Dr. Abhishek Ghosh Calculated, Total Memory Used by PHP-FPM Child Processes is :
109M
and One PHP5-FPM Process is Eating :
54M

Without my name, you’ll forget with time, where from this script came! Practical fact.

Optimize PHP5-FPM Memory Usage

 

Optimize PHP5-FPM Memory Usage & Prevent Out of Memory (OOM)

 

If you have a memory leak, then pm.max_requests will kill/restart the PHP-FPM Child Processes after it is handled this many requests. Try setting this to a number to causes each child process to be respawned every 20 minutes or so. So if you get 200 requests a minute, and you have 5 processes, set pm.max_requests to 500 to 800 might work.

PHP-FPM may be creating too many child processes on a traffic spike, it will factually initiate the starting of out of memory. Very bad – Google bot will not crawl.

Without going in to much fuss, this should be safe for 4GB :

Vim
1
2
3
4
5
6
7
pm = ondemand
pm.max_children = 100
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 15
pm.process_idle_timeout = 10s;
pm.max_requests = 1000

If WordPress or whatever web software cache the PHP webpages, with increased traffic load, 4GB will not die. Decrease the pm.max_requests for fine tuning. pm = on demand stops that memory sucking with minimal leak. Run my script on random time, run free to go closer towards a stable value. Now, if free command’s memory and your calculation from the script gives hugeeeee difference, then there is some other issue. Lower down the values to even 1 to check the issue. This is another set of setting with lower value :

Vim
1
2
3
4
5
6
7
pm = ondemand
pm.max_children = 40
pm.start_servers = 15
pm.min_spare_servers = 15
pm.max_spare_servers = 25
pm.process_idle_timeout = 10s;
pm.max_requests = 500

Tagged With https://yandex ru/clck/jsredir?from=yandex ru;search;web;;&text=&etext=1822 NYE6lNgW2wf3bLId1Xb2ImdTIW1xTX2O40vhY_qUkk8Di-u2jhjuqtUB-ICkwMQJ 1d97defd1d8bcd6837411fa96943a9a8b23dc157&uuid=&state=_BLhILn4SxNIvvL0W45KSic66uCIg23qh8iRG98qeIXme , https://yandex ru/clck/jsredir?from=yandex ru;search;web;;&text=&etext=1831 oNeCQHYJXyIfbTM3Abl6m3v_WdKdxeFsz5q4bXNp-Yp8x7HVFmVo5owVYuQuQQKm 66faec2127d4968af63022a6dd8744549b895340&uuid=&state=_BLhILn4SxNIvvL0W45KSic66uCIg23qh8iRG98qeIXme , paperuri:(a7441a8f5f2340ca077b4cc0c32d07ae) , php-fpm process size mem , php-fpm reduce memory usage , php5-fpm memory

This Article Has Been Shared 737 Times!

Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to Optimize PHP5-FPM Memory Usage

  • Cloud Computing Expo – Enterprise IT Event in Nov 2011

    Cloud Computing Expo first started in 2007. As usually, this year the Cloud Computing Expo will focus on the current development and opportunities in the field.

  • Cloud Computing And Faster Ad Serving Technologies

    Cloud Computing has given the opportunity to serve the targeted Ads as fast as possible to the publisher increasing the Ad revenue and conversion rate.

  • Red Hat Open Source Database : A Newer Generation ?

    Red Hat has announced a flexible and extended Service, that companies can use to track and analyze published data on the entire web public.

  • Future of IT Migration to the Cloud

    Cloud computing itself and the topic migration of IT Migration to the Cloud are two more interesting topics. IT Migration can be classified.

  • Future of Private Cloud in Enterprises

    Future of Private Cloud is within four factors those suggest that the private cloud is destined to have a great future, despite the debates.

Additionally, performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • What is Configuration Management February 5, 2023
  • What is ChatGPT? February 3, 2023
  • Zebronics Pixaplay 16 : Entry Level Movie Projector Review February 2, 2023
  • What is Voice User Interface (VUI) January 31, 2023
  • Proxy Server: Design Pattern in Programming January 30, 2023

About This Article

Cite this article as: Abhishek Ghosh, "Optimize PHP5-FPM Memory Usage," in The Customize Windows, November 13, 2015, February 6, 2023, https://thecustomizewindows.com/2015/11/optimize-php5-fpm-memory-usage/.

Source:The Customize Windows, JiMA.in

PC users can consult Corrine Chorney for Security.

Want to know more about us? Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
Do not sell my personal information.
Cookie SettingsAccept
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT