Results 1 to 23 of 23
  1. #1

    Is It Okay to Issue this Command "sysctl -w vm.drop_caches=3"

    Every other day, my server's memory reaches up to 90%. When this happens, I issue this command
    Code:
    /sbin/sysctl -w vm.drop_caches=3
    to free up inactive memory and the memory turns back to 30% used.

    My question is if it is safe to issue this command. I need to do this so that my server will not run out of memory.

  2. #2
    Join Date
    May 2013
    Location
    India
    Posts
    748
    Quote Originally Posted by jaypabs View Post
    Every other day, my server's memory reaches up to 90%. When this happens,
    What command do you use to find the memory usage?

  3. #3
    Quote Originally Posted by nixtree View Post
    What command do you use to find the memory usage?
    I'm actually doing it automatically using PHP script. So the command to know memory usage is:

    Code:
    $mem_usage = get_server_memory_usage();

  4. #4
    Join Date
    May 2013
    Location
    India
    Posts
    748
    Can you paste the result of "free -m" command as well when you experience the issue?

  5. #5
    Quote Originally Posted by nixtree View Post
    Can you paste the result of "free -m" command as well when you experience the issue?
    My question is if it is safe to issue this command.

  6. #6
    Join Date
    May 2013
    Location
    India
    Posts
    748
    Yes, it is fine to run that command + you may run "sync" first! But dropping cache manually is rarely needed as Linux kernel does it automatically.
    Last edited by nixtree; 01-12-2014 at 08:05 AM.

  7. #7
    Quote Originally Posted by nixtree View Post
    Yes, it is fine to run that command + you may run "sync" first! But dropping cache manually is rarely needed as Linux kernel does it automatically.
    Thank you for your reply. But as what I have said, I need to fire it so I can recover the inactive memory. If not, the memory used reaches 100%.

    Another thing that I am doing is reloading php5-fpm when there is an error in php5-fpm.log that says:

    Code:
    WARNING: [pool web8] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 31 idle, and 62 total children
    But somebody replied to me in another forum site that it is not good to reload php-fpm most often.

    I don't know about your idea on this.

  8. #8
    Join Date
    May 2013
    Location
    India
    Posts
    748
    Quote Originally Posted by jaypabs View Post
    Thank you for your reply. But as what I have said, I need to fire it so I can recover the inactive memory. If not, the memory used reaches 100%.

    Another thing that I am doing is reloading php5-fpm when there is an error in php5-fpm.log that says:

    Code:
    WARNING: [pool web8] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 31 idle, and 62 total children
    But somebody replied to me in another forum site that it is not good to reload php-fpm most often.

    I don't know about your idea on this.

    Of course reloading any process often is not recommended. And that warning, rather than often reloading you need to adjust your settings for PHP-FPM. Also the 100% usage - I don't know how the mentioned PHP function calculates memory usage. I think "free -m" can report exact memory usage more accurately. Normally you don't want to drop caches quite often as I said, Linux does it automatically. If you need often, there is something wrong with the storage or settings!

  9. #9
    Quote Originally Posted by nixtree View Post
    Of course reloading any process often is not recommended. And that warning, rather than often reloading you need to adjust your settings for PHP-FPM. Also the 100% usage - I don't know how the mentioned PHP function calculates memory usage. I think "free -m" can report exact memory usage more accurately. Normally you don't want to drop caches quite often as I said, Linux does it automatically. If you need often, there is something wrong with the storage or settings!
    I just don't know what is the best setting for my php-fpm. I have tried everything from lowest to highest value of start_server, min_server/max_server but still the memory is rising so fast.

    For you info here's my settings:

    Code:
    pm.max_children = 256
    pm.start_servers = 50
    pm.min_spare_servers = 40
    pm.max_spare_servers = 192
    pm.max_requests = 500
    I'm running 8 core cpu w/ 32gb ram.

  10. #10
    Join Date
    Dec 2011
    Location
    Netherlands
    Posts
    831
    Quote Originally Posted by jaypabs View Post
    My question is if it is safe to issue this command.
    I would like to see "free -m" as well, since there's nothing wrong with a server using 90% memory, if the memory is just cache.

    IMO it's stupid not to use all the memory, not using memory means wasting money.

    E.g:

    total used free shared buffers cached
    Mem: 32139 30052 2086 0 1061 20766
    -/+ buffers/cache: 8225 23914

    Shows I have 32 gigs mem, 30 is used, 2 gb free.
    But my actual free memory is 23.9 gigs, because of the cache.

    So give us your "free -m" command output and we can tell if you even need to run the sysctl command.

  11. #11
    Quote Originally Posted by Hosting4Real View Post
    I would like to see "free -m" as well, since there's nothing wrong with a server using 90% memory, if the memory is just cache.

    IMO it's stupid not to use all the memory, not using memory means wasting money.

    E.g:

    total used free shared buffers cached
    Mem: 32139 30052 2086 0 1061 20766
    -/+ buffers/cache: 8225 23914

    Shows I have 32 gigs mem, 30 is used, 2 gb free.
    But my actual free memory is 23.9 gigs, because of the cache.

    So give us your "free -m" command output and we can tell if you even need to run the sysctl command.
    Here's my memory usage:

    Code:
                 total       used       free     shared    buffers     cached
    Mem:         32149      26454       5695          0       1071      10168
    -/+ buffers/cache:      15213      16936
    Swap:        32737        563      32174

  12. #12
    Join Date
    May 2013
    Location
    India
    Posts
    748
    pm.start_servers = 50
    pm.min_spare_servers = 40
    pm.max_spare_servers = 192

    These three values need to tweak to overcome those warning. I don't know from where you got those values, but those are bit aggressive I think. As per those value, one new process has to fork when the total number of visitors reaches 10, 20 , etc. If you don't have too much concurrent visitors, you may set

    pm.start_servers = 10
    pm.min_spare_servers = 5
    m.max_spare_servers = 15

    That is fine value and you can tweak it based on your need later! And "free -m" output shows more than 50% of your memory is free!

  13. #13
    Quote Originally Posted by nixtree View Post
    pm.start_servers = 50
    pm.min_spare_servers = 40
    pm.max_spare_servers = 192

    These three values need to tweak to overcome those warning. I don't know from where you got those values, but those are bit aggressive I think. As per those value, one new process has to fork when the total number of visitors reaches 10, 20 , etc. If you don't have too much concurrent visitors, you may set

    pm.start_servers = 10
    pm.min_spare_servers = 5
    m.max_spare_servers = 15

    That is fine value and you can tweak it based on your need later! And "free -m" output shows more than 50% of your memory is free!
    If I set it like at 10/5/15, there would be a lot of error like:

    Code:
    [11-Jan-2014 21:35:32] WARNING: [pool web8] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 31 idle, and 62 total children
    [11-Jan-2014 21:35:33] WARNING: [pool web8] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 16 children, there are 37 idle, and 70 total children
    As I experienced, setting it higher fixed the problem. But not totally since I still encounter this error every other day.

    My concurrent connection sometimes reaches around 2k to 5k. When I reach more than 5k, the server returns an internal server error.

    Based on the results of free -m, the free memory is only 5695. So how come you said 50%? Unless you include the free cache.

  14. #14
    Join Date
    Dec 2011
    Location
    Netherlands
    Posts
    831
    Quote Originally Posted by jaypabs View Post
    If I set it like at 10/5/15, there would be a lot of error like:

    Code:
    [11-Jan-2014 21:35:32] WARNING: [pool web8] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 31 idle, and 62 total children
    [11-Jan-2014 21:35:33] WARNING: [pool web8] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 16 children, there are 37 idle, and 70 total children
    As I experienced, setting it higher fixed the problem. But not totally since I still encounter this error every other day.

    My concurrent connection sometimes reaches around 2k to 5k. When I reach more than 5k, the server returns an internal server error.

    Based on the results of free -m, the free memory is only 5695. So how come you said 50%? Unless you include the free cache.
    http://www.linuxatemyram.com/

  15. #15
    Join Date
    Oct 2010
    Posts
    3,414
    http://www.linuxatemyram.com/

    And Hosting4Real beat me to it while I read the thread.
    SiFuQi.net - Affordable Dedicated Servers in Los Angeles, California
    24x7 Support Enterprise Grade Hardware Automated OS Reinstalls
    Check out our reseller program, with a unique two-tiered discount.

  16. #16
    Join Date
    May 2013
    Location
    India
    Posts
    748
    Yup...read Steven's link and Hosting4Real's instruction to calculate RAM usage. Obviously the settings I gave is not good for high traffic websites.

    Code:
    My concurrent connection sometimes reaches around 2k to 5k. When I reach more than 5k, the server returns an internal server error.
    But it doesn't match with "pm.max_children = 256". May be most pages are static contents? I don't know...anyway keep tweaking your values to fit it to finest and restarting FPM isn't a fix ( that is not an error, but a warning ). That only let you to drop current connection pool and thus to drop that warning until it hit the same threshold again!

  17. #17
    Quote Originally Posted by nixtree View Post
    pm.start_servers = 50
    pm.min_spare_servers = 40
    pm.max_spare_servers = 192

    These three values need to tweak to overcome those warning. I don't know from where you got those values, but those are bit aggressive I think. As per those value, one new process has to fork when the total number of visitors reaches 10, 20 , etc. If you don't have too much concurrent visitors, you may set

    pm.start_servers = 10
    pm.min_spare_servers = 5
    m.max_spare_servers = 15

    That is fine value and you can tweak it based on your need later! And "free -m" output shows more than 50% of your memory is free!
    BTW, can you recommend me a good setting for the following:

    Code:
    pm.max_children = 
    pm.max_requests =

  18. #18
    Join Date
    May 2013
    Location
    India
    Posts
    748
    Cannot..because that varies based on your environment. Set pm.max_children to more than the expected number of concurrent users which needs PHP processing. pm.max_requests = set it to at least 1000 <

  19. #19
    Quote Originally Posted by nixtree View Post
    Cannot..because that varies based on your environment. Set pm.max_children to more than the expected number of concurrent users which needs PHP processing. pm.max_requests = set it to at least 1000 <
    I actually have this settings:

    Code:
    pm.max_children = 256
    pm.start_servers = 50
    pm.min_spare_servers = 40
    pm.max_spare_servers = 192
    pm.max_requests = 500
    But I'm wondering how they are related to each other. I'm confused with max_children and start/min/max_servers.

    Can you please guide me a little about this? What's the use of children and server. Is the children a child of servers created when php-fpm starts?

  20. #20
    Join Date
    May 2013
    Location
    India
    Posts
    748
    Go to http://www.php.net/manual/en/install...figuration.php and read explanations corresponding to each variables. Those all are pretty straight forward explanations. All are variables to control "PHP-FPM processes that are forked on your server" in short

  21. #21
    Quote Originally Posted by nixtree View Post
    Go to http://www.php.net/manual/en/install...figuration.php and read explanations corresponding to each variables. Those all are pretty straight forward explanations. All are variables to control "PHP-FPM processes that are forked on your server" in short
    I already read that, but still it's not clear to me what is the difference among them. max_children and start_servers mentioned about child processes while min_spare_servers and max_spare_servers doesn't mention about it.

    In overall, does it mean that min & max spare servers are also child processes?

  22. #22
    Join Date
    May 2013
    Location
    India
    Posts
    748
    pm.max_children - maximum number of FPM processes on the server ( equals to maximum number of concurrent PHP requests server can process )

    pm.start_servers - Number of FPM processes on start( service php-fpm start )

    pm.min_spare_servers - minimum number of processes that should be idle ( free to serve )

    pm.max_spare_servers - maximum number of processes that should be idle ( free to serve )

    pm.max_requests - The number of requests each child process should execute before respawning

    Hope it is clear!

  23. #23
    Quote Originally Posted by Hosting4Real View Post
    Thank you

    Now, I will not worry too much about ram usage.

Similar Threads

  1. Replies: 7
    Last Post: 03-10-2012, 08:04 AM
  2. Replies: 0
    Last Post: 12-24-2011, 09:45 AM
  3. Shell "mkdir" and "wget"command help
    By galacnet in forum Programming Discussion
    Replies: 5
    Last Post: 01-21-2005, 03:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •