Gentoo Archives: gentoo-user

From: kashani <kashani-list@××××××××.net>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] mysqld invoked oom-killer
Date: Wed, 20 Jul 2011 23:55:07
Message-Id: 4E276A9D.5030801@badapple.net
In Reply to: Re: [gentoo-user] mysqld invoked oom-killer by Grant
1 On 7/20/2011 4:08 PM, Grant wrote:
2 >>> I ran into an out of memory problem. The first mention of it in the
3 >>> kernel log is "mysqld invoked oom-killer". I haven't run into this
4 >>> before. I do have a swap partition but I don't activate it based on
5 >>> something I read previously that I later found out was wrong so I
6 >>> suppose I should activate it. Is fstab the way to do that? I have a
7 >>> commented line in there for swap.
8 >>
9 >> Yes, just uncomment it and should be automatic. (you can use "swapon"
10 >> to enable it without rebooting)
11 >
12 > Got it.
13 >
14 >>> Can anyone tell how much swap this is:
15 >>>
16 >>> /dev/sda2 80325 1140614 530145 82 Linux swap / Solaris
17 >>>
18 >>> If it's something like 512MB, that may not have prevented me from
19 >>> running out of memory since I have 4GB RAM. Is there any way to find
20 >>> out if there was a memory leak or other problem that should be
21 >>> investigated?
22 >>
23 >> That's 512MB. You can also create a swap file to supplement the swap
24 >> partition if you don't want to or aren't able to repartition.
25 >
26 > So I'm sure I have the concept right, is adding a 1GB swap partition
27 > functionally identical to adding 1GB RAM with regard to the potential
28 > for out-of-memory conditions?
29 >
30 >> I'd check the MySQL logs to see if it shows anything. Maybe check the
31 >> settings with regard to memory upper limits (Google it, there's a lot
32 >> of info about MySQL RAM management).
33 >
34 > Nothing in the log and from what I read online, an error should be
35 > logged if I reach mysql's memory limit.
36 >
37 >> If you're running any other servers that utilize MySQL like Apache or
38 >> something, check its access logs to see if you had an abnormal number
39 >> of connections. Bruteforce hacking or some kind of flooding/DOS attack
40 >> might cause it to use more memory than it ordinarily would.
41 >
42 > It runs apache and I found some info there.
43 >
44 >> A Basic "what's using up my memory?" technique is to log the output of
45 >> "top" by using the -b command. Something like "top -b> toplog.txt".
46 >> Then you can go back to the time when the OOM occurred and see what
47 >> was using a lot of RAM at that time.
48 >
49 > The kernel actually logged some top-like output and it looks like I
50 > had a large number of apache2 processes running, likely 256 processes
51 > which is the default MaxClients. The specified total_vm for each
52 > process was about 67000 which means 256 x 67MB = 17GB???
53 >
54 > I looked over my apache2 log and I was hit severely by a single IP
55 > right as the server went down. However, that IP looks to be a
56 > residential customer in the US and they engaged in normal browsing
57 > behavior both before and after the disruption. I think that IP may
58 > have done the refresh-100-times thing out of frustration as the server
59 > started to go down.
60 >
61 > Does it sound like apache2 was using up all the memory? If so, should
62 > I look further for a catalyst or did this likely happen slowly? What
63 > can I do to prevent it from happening again? Should I switch apache2
64 > from prefork to threads?
65
66 Switching from prefork to threads and vice versa can be very difficult
67 depending on which modules and libraries your site uses. It is not on
68 the list of things you should try first. Or second. Maybe 37th.
69 I wouldn't expect adding swap to do much in this case. Your site gets
70 hit hard, Mysql is a bit slow, Apache processes start stacking up, the
71 system starts swapping, disk is really slow compared to RAM, and
72 everything grinds to a complete halt possibly locking the machine up.
73
74 The easiest thing to try is to turn off keepalives so child processes
75 aren't hanging around keeping connections up. Also lower the number of
76 Apache children to 8 * number of processors or a minimum of 32. Test a
77 bit. Turning off keep alive can cause problems for Flash based uploaders
78 to your site and code that expect the connection to stay up. For most
79 sites this shouldn't matter.
80
81 Next I'd look at tuning your Mysql config. If you've never touched
82 my.cnf, by default it's set to use 64MB IIRC. You may need to raise this
83 to get better performance. key_buffer and innodb_buffer_pool_size are
84 the only two I'd modify without knowing more.
85
86 kashani

Replies

Subject Author
Re: [gentoo-user] mysqld invoked oom-killer Adam Carter <adamcarter3@×××××.com>
Re: [gentoo-user] mysqld invoked oom-killer Michael Mol <mikemol@×××××.com>
Re: [gentoo-user] mysqld invoked oom-killer Grant <emailgrant@×××××.com>
Re: [gentoo-user] mysqld invoked oom-killer Grant <emailgrant@×××××.com>