Current time: 12-24-2024, 01:32 AM Hello There, Guest! (LoginRegister)


Post Reply 
Reducing memory usage
Author Message
pete Offline
Junior Member
*

Posts: 14
Joined: Dec 2009
Reputation: 0
Post: #1
Reducing memory usage
I'm using way more memory than is allocated for me by the virtual machine hosting service (limit is 512MB with 1024MB burst). I checked what is running using the top command and found that I have two large apache2 instances, each clobbering 277MB. Why two? Also, MySQL should have very little work to do but still uses 144MB.

Am I doing something wrong? Can I force these processes to be more frugal?

Note that unfortunately I can't create a swap disk or file, the VPS doesn't support that.

Following is what top tells me (sorted by memory usage):
Code:
PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
13770 www-data  18   0  277m 5036 1440 S    0  0.5   0:00.19 apache2
18199 www-data  15   0  277m 4980 1436 S    0  0.5   0:00.26 apache2
22015 mysql     15   0  144m  19m 5916 S    0  1.9   0:00.57 mysqld
31755 bind      22   0 69444  10m 2076 S    0  1.1   0:00.01 named
25710 vu2000    15   0 35532 9.9m 3240 S    0  1.0   0:00.18 php5-cgi
21768 syslog    15   0 34320 1352  976 S    0  0.1   0:00.50 rsyslogd
21542 vu2001    15   0 33752 7948 2864 S    0  0.8   0:00.64 php5-cgi
21543 vu2001    15   0 33752 7948 2864 S    0  0.8   0:00.58 php5-cgi
25711 vu2000    15   0 33200 7348 2828 S    0  0.7   0:00.22 php5-cgi
5950 vu2002    18   0 31136 5852 3872 S    0  0.6   0:00.00 php5-cgi
25708 vu2000    17   0 31136 5852 3872 S    0  0.6   0:00.00 php5-cgi
21540 vu2001    16   0 31136 5848 3872 S    0  0.6   0:00.00 php5-cgi
5952 vu2002    15   0 31016 3292 1252 S    0  0.3   0:00.00 php5-cgi
5953 vu2002    16   0 31016 3292 1252 S    0  0.3   0:00.00 php5-cgi
13765 root      18   0 12944 9320 2224 S    0  0.9   0:00.13 ispcp-apache-lo
13768 root      18   0 12928 9352 2224 S    0  0.9   0:00.20 ispcp-apache-lo
23564 postgrey  18   0 11652 8416 2772 S    0  0.8   0:00.08 postgrey
29847 root      15   0  8500 2724 2152 S    0  0.3   0:00.06 sshd
11881 polw      18   0  8100 5948 1484 S    0  0.6   0:00.28 policyd-weight
15987 polw      15   0  8100 5936 1476 S    0  0.6   0:00.08 policyd-weight
22480 polw      15   0  7964 5332 1004 S    0  0.5   0:00.01 policyd-weight
22479 polw      16   0  7836 5564 1248 S    0  0.5   0:00.03 policyd-weight
13769 www-data  18   0  6284 2140  584 S    0  0.2   0:00.00 apache2
23850 root      18   0  6284 3632 2072 S    0  0.3   0:00.02 apache2
11714 postfix   15   0  5996 1852 1464 S    0  0.2   0:00.03 qmgr
13767 www-data  16   0  5964 2064  516 S    0  0.2   0:00.00 apache2
7223 postfix   15   0  5860 1736 1388 S    0  0.2   0:00.00 pickup
11711 root      15   0  5848 1788 1424 S    0  0.2   0:00.14 master
21834 root      15   0  5564 1056  648 S    0  0.1   0:00.32 sshd
13823 root      18   0  4384 1888 1448 S    0  0.2   0:00.00 bash
23583 root      15   0  2780 1324  580 S    0  0.1   0:00.10 authdaemond
21758 root      20   0  2392  556  308 T    0  0.1   0:00.00 init
    1 root      15   0  2392 1336 1088 S    0  0.1   0:00.32 init
23579 root      15   0  2368  912  580 S    0  0.1   0:00.06 authdaemond
23580 root      15   0  2368  912  580 S    0  0.1   0:00.07 authdaemond
23581 root      15   0  2368  912  580 S    0  0.1   0:00.09 authdaemond
9431 root      18   0  2332 1104  876 R    0  0.1   0:00.00 top
23582 root      15   0  2148  640  344 S    0  0.1   0:00.06 authdaemond
23574 root      18   0  2144  716  560 S    0  0.1   0:00.00 authdaemond
21756 root      15   0  2084  868  680 S    0  0.1   0:00.02 cron
23595 root      15   0  1980  612  516 S    0  0.1   0:00.00 couriertcpd
23607 root      15   0  1980  612  516 S    0  0.1   0:00.05 couriertcpd
23605 root      18   0  1868  444  356 S    0  0.0   0:00.03 courierlogger
23627 root      15   0  1868  612  512 S    0  0.1   0:00.00 inetd
23573 root      25   0  1868  448  356 S    0  0.0   0:00.00 courierlogger
23594 root      18   0  1868  448  356 S    0  0.0   0:00.00 courierlogger
21750 root      21   0  1844  536  440 S    0  0.1   0:00.00 dd
13764 root      15   0  1744  480  412 S    0  0.0   0:00.00 sh
13766 root      16   0  1744  476  412 S    0  0.0   0:00.00 sh
21863 root      18   0  1744  536  444 S    0  0.1   0:00.00 mysqld_safe
22017 root      19   0  1660  536  460 S    0  0.1   0:00.00 logger
23885 root      18   0  1660  448  376 S    0  0.0   0:00.00 ispcp_daemon
(This post was last modified: 04-07-2010 11:29 AM by pete.)
04-07-2010 11:27 AM
Find all posts by this user Quote this message in a reply
BeNe Offline
Moderator
*****
Moderators

Posts: 5,899
Joined: Jan 2007
Reputation: 68
Post: #2
RE: Reducing memory usage
--> http://www.isp-control.net/documentation...ces_system

Greez BeNe
04-07-2010 03:25 PM
Visit this user's website Find all posts by this user Quote this message in a reply
pete Offline
Junior Member
*

Posts: 14
Joined: Dec 2009
Reputation: 0
Post: #3
RE: Reducing memory usage
Thanks BeNe, I'll try that.
04-08-2010 03:11 PM
Find all posts by this user Quote this message in a reply
dcreation Offline
Junior Member
*

Posts: 85
Joined: Apr 2009
Reputation: 0
Post: #4
RE: Reducing memory usage
Your Apache dont use that much memory Wink
It uses "0,5% of total" which means around 3MB.
(This post was last modified: 04-08-2010 08:58 PM by dcreation.)
04-08-2010 08:58 PM
Find all posts by this user Quote this message in a reply
kilburn Offline
Development Team
*****
Dev Team

Posts: 2,182
Joined: Feb 2007
Reputation: 34
Post: #5
RE: Reducing memory usage
Tracking memory usage is not a simple task, and dcreation gave you an initial hint of it.

First of all, assuming that you have no SWAP space, the virtual memory (VIRT) used by a process is completely irrelevant.
Next, the most important figure is the physical memory being used (RES column), which says that your apache instances are consuming approximately 5mb each).

Nevertheless, this is not entirely true, as part of this memory is shared with other processes (those that use the same libraries). A hint about the amount of memory that *might* be shared with other processes is shown in the SHR column. For your apache case, this column shows that approx. 1.3mb of each apache process are potentially being shared (not just among the apache process, but with any other program using the same libs).

Finally, adding the RES value of all your processes gives you a *worst case* (this is, considering that no memory is shared between processes at all which is NOT the case) of 180mb being used by your system.
(This post was last modified: 04-08-2010 10:25 PM by kilburn.)
04-08-2010 10:24 PM
Visit this user's website Find all posts by this user Quote this message in a reply
pete Offline
Junior Member
*

Posts: 14
Joined: Dec 2009
Reputation: 0
Post: #6
RE: Reducing memory usage
BeNe, your suggestion worked a treat, thanks.

dcreation, in theory you're right but in my case the VPS I'm using doesn't have swap space so all virtual memory equals virtual machine memory. My limit is 1GB and my server is often dangerously close to that mark. Not surprisingly, at times things stop working due to memory allocation errors.

With BeNe's help, I now reduce overall memory down to about 400mb.
(04-08-2010 10:24 PM)kilburn Wrote:  First of all, assuming that you have no SWAP space, the virtual memory (VIRT) used by a process is completely irrelevant.

Just when I thought I could understand this stuff someone throws a spanner in the works.

What is virtual memory then?

I mean, in C (and implicitly C++) we use malloc and free to manage the applications heap storage. Apart from the heap, there is stack space, code of the module itself and shared libraries, but combined, these would be a small fraction of the 144mb stated.

So I assume that a large portion of the 144mb has been allocated via [many calls to] malloc. In the absence of a swap device, where exactly would the OS put allocated memory?

I can only assume that the "no" in your comment is a typo. If I don't have a SWAP device, then surely virtual memory=physical memory (with the exceptions of shared code you mentioned), right?

If not, what is "virtual memory" in top's vocabulary?
(This post was last modified: 04-09-2010 07:59 PM by pete.)
04-09-2010 07:29 PM
Find all posts by this user Quote this message in a reply
kilburn Offline
Development Team
*****
Dev Team

Posts: 2,182
Joined: Feb 2007
Reputation: 34
Post: #7
RE: Reducing memory usage
See this thread for further insight Wink
04-10-2010 03:27 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)