Gentoo Archives: gentoo-user

From: kashani <kashani-list@××××××××.net>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Web Server Memory Issues
Date: Thu, 13 Jan 2011 20:22:42
In Reply to: [gentoo-user] Web Server Memory Issues by Kaddeh
1 On 1/12/2011 10:59 AM, Kaddeh wrote:
2 > So, I have run into an interesting problem while building out a web
3 > server for a client which I haven't come across before and I was hoping
4 > that the list would be a good way for me to find the answer.
5 > A little beckground on the systems:
6 > P4 @ 3.0Ghz
7 > 2GB PC2 4200
8 > 2x 250GB drives in RAID1
9 > The system configurations are default for the most part with the server
10 > running MySQL and Apache.
11 > The problem that I am running into at this point, however is that the
12 > machine seems to run out of memory and will segfault either apache or
13 > mysql when does so, when apache segfaults, it is a recoverable error,
14 > when mysql does it, mysql can't recover short of restarting it.
15 > At this point, I have found a soft fix by running a cron job every 6
16 > hours or so to clear the cached memory, which seems to be the problem,
17 > however, I would like to find a more permanent fix to this issue.
18 > Anything that would help at this point would be much appreciated.
19 > Cheers
20 > Kad
22 Overall I'd expect your Mysql is running slow, which causes Apache to
23 back up, which create more Apache children while your code blocks on the
24 db, which then uses all the RAM.
26 1. Assuming you're running prefork, Turn KeepAlives Off if you haven't
27 already. That'll reduce the number of Apache threads sitting around
28 doing nothing but using your RAM.
30 2. The default my.conf in Gentoo (and nearly all distros) is configured
31 to use 64MB. You should bump this up to 512MB total. The two settings I
32 would touch are the following and THEY ARE SEPARATE POOLS that do not
33 share configured memory with each other. Configure accordingly.
34 innodb_buffer_pool_size = 16M
35 key_buffer = 16M
37 Both variables are dynamic and can be set from with Mysql use set
38 variables key_buffer='10240000'; syntax.
40 Assuming you use Innodb tables I'd try 256MB for that setting and 128MB
41 for the key_buffer and see how it goes.
43 3. Mysql slow query log. Turn it on and look at it. Your db design
44 sounds sketchy at best and I'd be surprised if your weren't seeing a ton
45 of slow queries especially with no db tuning.
47 4. /tmp is how big? Make sure it's a couple of gigs so that Mysql can
48 build tmp tables in it. Again your db design is strange enough that you
49 might be generating large tmp tables that file /tmp (and / if you
50 haven't separated them) and causes Mysql problems. This is a fairly
51 common problem in my experience. The simplest solution is:
52 sudo mkdid -p /home/mysql
53 sudo chown -R mysql: /home/mysql
54 vi /etc/mysql/my.cnf and change to tmpdir = /home/mysql/
55 sudo /etc/init.d/mysql restart
57 Yes, tmpdir is *not* a dynamic variable so you will have to restart
58 Mysql to make this change.
60 kashani