Gentoo Archives: gentoo-user

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

Replies

Subject Author
Re: [gentoo-user] mysqld invoked oom-killer kashani <kashani-list@××××××××.net>
Re: [gentoo-user] mysqld invoked oom-killer Grant <emailgrant@×××××.com>