Re: [gentoo-user] anyone having apache2 memory issues

2006-04-01 Thread Jim
On Fri, 2006-03-31 at 20:50 -0800, Alan Bailward wrote:
 Hey all.  I recently swapped my apache 1.3 site (personal blog, albums,
 etc) over to apache 2 (stable) and all seemed to go well.  However
 lately I've been having a lot of out of memory issues on the server.
 Even when memory is still available 
snip

What output do you get from: top -b -n 1

For example, here is my apache output:

[EMAIL PROTECTED] top -b -n 1
top - 11:48:06 up 2 days, 15:11,  2 users,  load average: 0.00, 0.03,
0.04
Tasks:  88 total,   2 running,  86 sleeping,   0 stopped,   0 zombie
Cpu(s):  7.4% us,  5.0% sy,  0.0% ni, 86.2% id,  0.8% wa,  0.0% hi,
0.5% si
Mem:   2010484k total,  1678576k used,   331908k free,   264884k buffers
Swap:   522104k total,  136k used,   521968k free,   945556k cached

  PID USER  PR  NI  VIRT  RES  SHR S %CPU %MEMTIME+  COMMAND
15536 root  16   0 56784  10m 4864 S  0.0  0.6   0:00.16 apache2
16374 apache16   0 57188 9816 3108 S  0.0  0.5   0:00.10 apache2
6481 apache15   0 57172 9780 3100 S  0.0  0.5   0:00.02 apache2

Go through top and see what is sucking up your memory.  Or you can use
gnome-system-monitor, which I like better.

Here is a little program I tossed together to free that cached memory.
Just run it and specify an amount of memory in MB.  Do not run this as
root, a normal user is fine.


I have 2 GB and after running VMWare I run:

mem 1200

Which frees all that cached memory that VMWare sucked up.  If you have 
1 GB, you should turn swap off before you run this, otherwise you might
just be allocating memory from swap and defeat the purpose.

Before you run the program, look at the output of free to see how much
you should try to free.  For example,

[EMAIL PROTECTED] free -m
total  used  free  shared  buffers  cached
Mem: 1963  1643   3190 258 923
-/+ buffers/cache:  461  1502
Swap: 509 0   509

I have 923 MB sitting in cache.  So if I run:

[EMAIL PROTECTED] mem 1200
allocating: 1200MB bytes of memory
allocated: 1258291200MB bytes of memory
freed 1258291200MB bytes of memory

I now have 1.2 GB free:

[EMAIL PROTECTED] free -m
total  used  free  shared  buffers  cached
Mem: 1963   715  1248   0   45 307
-/+ buffers/cache:  362  1600
Swap:509  0   509

To compile the program, just do:
You can replace $CFLAGS with whatever you like, for example -O3.

[EMAIL PROTECTED] gcc $CFLAGS -o mem mem.c
[EMAIL PROTECTED] sudo cp mem /usr/bin



 BEGIN CUT 
#include stdlib.h
#include stdio.h

int main(int argc, char* argv[])
{
  char* ptr  = 0;
  int   i= 0;
  int   size = 0;
  
  if (argc != 2)
  {
printf(Usage: %s SIZE\nwhere SIZE is the size of 
  memory to allocate in  MB\n, argv[0]);
return 1;
  }
  
  /* get the size in MB from the command line */
  size = atoi(argv[1]);
  
  printf(allocating: %iMB bytes of memory\n, size);
  ptr = (char*)malloc(1024 * 1024 * size);
  
  if (ptr)
  {
printf(allocated: %iMB bytes of memory\n, (1024 * 1024 * size));
for (i=0; i(1024 * 1024 * size); i++)
{
  ptr[i]=1;
}
free(ptr);
printf(freed %iMB bytes of memory\n, (1024 * 1024 * size));
  }
  else
printf(failed to allocate %iMB bytes of memory\n,
  (1024 * 1024 * size));
  
  return 0;
}
 END CUT 

You might want to try:

# mem 225

Jim
-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
I'm a geek, but I don't get it. 36-24-36 = -24. What's the significance?
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Florida, USA, Earth, Solar System, Milky Way

-- 
gentoo-user@gentoo.org mailing list



Re: [gentoo-user] anyone having apache2 memory issues

2006-04-01 Thread Alexander Skwar

Jim wrote:


Here is a little program I tossed together to free that cached memory.


Hm. Why do this? Do you actually get any performance benefits
after having freed the memory occupied by the cache?

In theory, you shouldn't see any benefits, as the system
should throw away memory pages occupied by cache stuff,
as soon as there are more important requests (like
any malloc).

Or am I wrong?

Alexander Skwar
--
Netscape is not a newsreader, and probably never shall be.
-- Tom Christiansen
--
gentoo-user@gentoo.org mailing list



Re: [gentoo-user] anyone having apache2 memory issues

2006-04-01 Thread Jim
On Sat, 2006-04-01 at 22:24 +0200, Alexander Skwar wrote:
 Jim wrote:
 
  Here is a little program I tossed together to free that cached memory.
 
 Hm. Why do this? Do you actually get any performance benefits
 after having freed the memory occupied by the cache?
 
 In theory, you shouldn't see any benefits, as the system
 should throw away memory pages occupied by cache stuff,
 as soon as there are more important requests (like
 any malloc).
 
 Or am I wrong?

That is how it should be.  However I noticed when I only had 512 MB of
memory that most of my memory would be used and I would see a lot of
cache.  Instead of that cache being freed or used, I would see a lot of
swap file usage which really kills performance.

I basically don't want to see swap touched unless I actually run out of
physical memory.

The best thing to do besides have a bunch of memory is to tune your
swappiness:

http://kerneltrap.org/node/3000

Now that I have 2 GB of memory, I don't worry about it any more.
However when I had 512MB it was an issues, especially when trying to run
apache, mysql, postfix, courier and a full desktop.

Jim
-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
I'm a geek, but I don't get it. 36-24-36 = -24. What's the significance?
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Florida, USA, Earth, Solar System, Milky Way

-- 
gentoo-user@gentoo.org mailing list



[gentoo-user] anyone having apache2 memory issues

2006-03-31 Thread Alan Bailward
Hey all.  I recently swapped my apache 1.3 site (personal blog, albums,
etc) over to apache 2 (stable) and all seemed to go well.  However
lately I've been having a lot of out of memory issues on the server.
Even when memory is still available 

naked alan # free -m
 total   used   free sharedbufferscached
Mem:   505475 29  0 33   219
-/+ buffers/cache:222282
Swap:  525 75450

vmstat:
procs ---memory-- ---swap-- -io --system--
cpu
 r  b   swpd   free   buff  cache   si   sobibo   incs us sy
id wa
 0  0  77020  50124  34212 20667200 2 5  103   126  0  1
99  1
(sorry about the wrapping)

I'm still getting errors like this in my site's error log:


[Fri Mar 31 20:07:08 2006] [error] [client 209.123.8.19] (12)Cannot
allocate memory: couldn't create child process: 12: mt-tb.cgi
[Fri Mar 31 20:07:08 2006] [error] [client 209.123.8.19] (12)Cannot
allocate memory: couldn't spawn child
process: /var/www/arcterex.net/htdocs/mt/mt-tb.cgi[Fri Mar 31 20:07:09
2006] [error] [client 209.123.8.19] (12)Cannot allocate memory: couldn't
create child process: 12: mt-tb.cgi

This happens for most of the pages when I got to my movable site admin
pages (all cgi).

I'm using pretty much the stock apache2 config files on a 512mb athlon
xp2600 server.  I've used threads -threads and mpm-prefork in my
USE flags, with pretty much the same results :(  The server itself is a
standard samba/apache/mysql system which seemed to run mostly ok under
apache 1.3, so I'm really wondering what the heck is going on.  When the
server reports the out of memory conditions I can sometimes hit the page
a couple of times and then it'll come up.  Other times apache will run
with 100% cpu and slowly use up memory and swap until I have to (slowly)
login and kill it by hand.

Anyone seen anything like this or have an idea on how to fix?

TIA

Alan

-- 
Alan [EMAIL PROTECTED] - http://arcterex.net

Backups are for people who don't pray. -- big Mike

-- 
gentoo-user@gentoo.org mailing list