0

On a server with 30GB of memory serving somewhat high-volume traffic.

For some reason recently Apache2 has started running threads with insane memory usage. 500MB-750MB per thread is not uncommon right now.

php.ini has memory_limit = 128M (php7.0 default).

Apache prefork config is on defaults.

The result is that we're running with only ~1GB of free memory.

What am I missing?

We have Nginx proxying requests and it's processes are more like ~60MB per thread. Here is a screenshot of running top

Top Screenshot

Any insight as to what could be driving this is appreciated!

peterh
  • 4,953
  • 13
  • 30
  • 44
Wes
  • 103
  • 1

1 Answers1

3

From that top output it looks like Apache processes have 20-50MB "res" (resident) in memory. The "virt" isn't memory you need to worry about, generally, it can be mapped files and isn't actual RAM used.

I can see that you have 28GB of memory "cached". This is typically cached files. This is a good thing, it saves the OS from having to go to the disk to access files.

I think you may benefit from the "Linux Ate My RAM" website.

What exactly is the problem this is causing? Does your system every report "out of memory", or processes fail because of lack of RAM?

Tim
  • 31,888
  • 7
  • 52
  • 78
  • The cached memory thing makes sense now. Sorry - I'm not much of an infrastructure guy. Biggest challenge is having nginx 504 timeouts recently - trying to narrow down the possible performance bottlenecks. – Wes Jun 21 '17 at 18:57
  • For your 504's, you might try to capture `netstat -aeenp` as root periodically during these times. Count the number of connections in time wait, close wait, etc. This is sometimes hard to spot in logs. If that is the issue, I can offer suggestions for a way around it. – Aaron Jun 21 '17 at 19:14
  • It's a common misunderstanding. Suggest you gather information and post a question about the timeouts. curl showing the problem, applicable logs, and configurations would be key information to share. – Tim Jun 21 '17 at 19:14
  • You probably mean MB, not KB up there, since the numbers are in kilobytes already. – Tollef Fog Heen Jun 21 '17 at 20:33
  • Thanks @TollefFogHeen, I wasn't sure what the units were – Tim Jun 21 '17 at 20:36
  • @TollefFogHeen - Wouldn't 668084 under VIRT translate to 668MB since it's in KB in `top` already? – Wes Jun 21 '17 at 22:10
  • @Aaron - Great suggestion. I will look at this and let you know if I have any questions. – Wes Jun 21 '17 at 22:11
  • @Wes, correct, but VIRT isn't very interesting, you want to look at RES. See the answer and links. :-) – Tollef Fog Heen Jun 22 '17 at 14:12
  • @TollefFogHeen Thanks for helping me understand that. Looking at the RES numbers, it seems much more normal. Not an infrastructure guy but that's definitely helpful. – Wes Jun 23 '17 at 15:27