LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Limit User Processes (https://www.linuxquestions.org/questions/linux-server-73/limit-user-processes-788267/)

Rundi 02-10-2010 11:31 AM

Limit User Processes
 
I have some domains on a VPS server. Typical account memory usage for all domains runs at 50% of available, but I have a problem. One domain is causing me trouble because intermittently traffic will spike on that domain, causing so many requests within 1 min that I exceed my memory allocation for my entire VPS package. Apache is then killed but the virtualization software and Apache must then be restarted. A sample snippet from tops right before the sever went down would like like this:

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
27816 coldclim 18 0 39524 26m 5880 R 3.7 5.1 0:00.77 php
27710 coldclim 18 0 34876 21m 5592 R 2.3 4.2 0:00.40 php
27850 coldclim 18 0 29444 15m 5432 R 1.1 3.1 0:00.25 php
27860 coldclim 17 0 32412 18m 5516 R 1.1 3.7 0:00.33 php
27858 coldclim 18 0 35136 21m 5592 R 0.8 4.2 0:00.42 php
27987 coldclim 17 0 21028 5556 3232 R 0.8 1.1 0:00.03 php
27856 coldclim 18 0 32420 18m 5516 R 0.6 3.7 0:00.34 php
27947 coldclim 16 0 25804 12m 5432 R 0.6 2.4 0:00.13 php
27958 coldclim 16 0 25544 12m 5432 R 0.6 2.4 0:00.12 php
27960 coldclim 16 0 24104 10m 5376 R 0.6 2.1 0:00.10 php
27962 coldclim 18 0 27884 14m 5432 R 0.6 2.8 0:00.19 php
27854 coldclim 18 0 34880 21m 5592 R 0.3 4.1 0:00.40 php
27830 coldclim 18 0 36176 22m 5732 R 0.0 4.4 0:00.50 php
27831 coldclim 18 0 32932 19m 5528 R 0.0 3.8 0:00.35 php
27851 coldclim 18 0 32412 18m 5524 R 0.0 3.7 0:00.34 php
27852 coldclim 18 0 29176 15m 5432 R 0.0 3.1 0:00.24 php
27855 coldclim 18 0 27612 14m 5432 R 0.0 2.8 0:00.18 php
27857 coldclim 18 0 31364 17m 5496 R 0.0 3.5 0:00.29 php
27861 coldclim 18 0 24500 11m 5428 R 0.0 2.2 0:00.11 php
27862 coldclim 18 0 30848 17m 5476 R 0.0 3.4 0:00.28 php
27956 coldclim 18 0 25800 12m 5432 R 0.0 2.4 0:00.14 php
27961 coldclim 18 0 22400 8440 4584 R 0.0 1.6 0:00.04 php
27973 coldclim 18 0 24376 10m 5388 R 0.0 2.1 0:00.09 php
27974 coldclim 18 0 23188 9204 4900 R 0.0 1.8 0:00.05 php

All of that memory usage adds up. I would like to "throttle" the number of processes that user/domain can run. I think this would be a quick and easy way to keep the domain from taking down my entire VPS. My understanding is that I could do this with the /etc/security/limits.conf file.

Is that correct?

I have never done this before. Do I want to set a hard or soft limit? I think if I wanted to limit the number of processes for "coldclim" to 15 I would add a line to limits.conf like this:
Code:

coldclim  hard  nproc 15
Assuming that is correct, can anyone tell me how the website would respond once it reached its limit? Would visitor queries become sluggish, or would the website not come up for them at all?

Thanks for the help!

rweaver 02-10-2010 12:05 PM

If it's exhausting the memory of the server your maxclients is probably set to high or you need to do some optimizations to get rid of modules you don't need to lower the memory foot print. You could also probably optimize and limit php a bit further if you cared to.

As far as your limits.conf entry goes that looks correct provided the full username in /etc/passwd (or whatever pam is authenticating off of) is coldclim. A hard limit is enforced by the kernel, any attempt to exceed it will fail. The exact behavior would be determined by your apache settings (like is keepalive off or on, etc.) That being said, it's going to prevent the site from being viewed at some level.

Rundi 02-10-2010 12:54 PM

Adjusting maxclients is another way to go about it, but my understanding is that maxclients limits *all* the domains on the VPS, not just the one domain. Since the other domains are run under other users my idea was to use the limits.conf to selectively limit the one domain which is being a hog and leave the others alone.

. . . the troublesome domain is a website of my Mom's and I am getting tired of troubleshooting stuff all the time for her, so I am looking for a simple way to keep her "mess" boxed in so as to not take the rest of the server down.

rweaver 02-10-2010 01:54 PM

The maxclients setting determines the maximum number apache can spawn.

Lets say all the sites you host have a 75% increase in traffic and that puts them on par with the traffic this one site gets but none of them high enough to be effected by the limits... the server will still crash.

Your maxclients is to high for the amount of ram you have, so when you reach that top end there are more clients being spawned than you have memory to work with, it starts to swap, and eventually crashes once the iowait reaches absurd amounts.

Take a look at this:
http://2bits.com/articles/tuning-the...parameter.html

This is an entirely different issue from limiting via limits.conf

Placing a hard limit via the limit.conf prevents one user from 'stealing' others resources in a shared environment. Having a limit that is to high for maxclients means that your server will crash under load (even if its spread over all the users so that none are reaching a hard limit) rather than just slow down.

You've got two issues: One a user who utilizes more resources than you find acceptable (hard limits fix that), and two your maxclients is too high for the amount of ram in the system (thus just setting a hard limit for one user will just offload the problem temporarily until another site spikes in traffic, even if you set it for all the sites if you had enough traffic spread over them all the problem would still occur).

Rundi 02-10-2010 02:08 PM

Okay, yes. That makes sense. I will need to do both. Thanks for the link.


All times are GMT -5. The time now is 05:31 AM.