News for hackers. Stuff that matters.
Re:The Linux kernel's inability to gracefully handle low mem... by HugThem on Tuesday August 06, 2019 @01:23AM (#20622392)
I witnessed MySQL bringing linux servers down two.

In my case it happens like this:

I have a long running PHP process that constantly fires away mostly SELECT but also a bunch of INSERT and UPDATE statements and also some DELETEs.

Since the DB and the key files do not fit into memory, its all disk bound work.

All tables are MyISAM.

Like clockwork, this stalls the virtual machine once per day.

All I can do is to hard power down the VM and restart it. Afterwards the table data is corrupted beyond repair.

Not sure it is related to memory though. Because the memory usage of PHP and MySQL seem to be constant. Most RAM seems to be used by Linux for caches.

Re:The Linux kernel's inability to gracefully handle low mem... by kokey on Tuesday August 06, 2019 @04:00AM (#20623175)
The most common cause here is something causing a situation where some queries hang or takes a long time to complete, while also locking access to something, while new queries keep coming in. This builds up quickly.

A good way to catch this would be to have something log the list of running queries every couple of seconds. Look at this log after the crash and you'll hopefully be able to identify which are the long running processes, and which are the regular queries that builds up.

To fix it would be a combination of making the queries that cause the locking to be less like that, also perhaps putting in a limit on how many queries can build up and also implement a way for the regular queries that build up to time out or fail quicker or more gracefully.

Re:The Linux kernel's inability to gracefully handle low mem... by HugThem on Tuesday August 06, 2019 @04:44AM (#20623408)
I fire the queries sequentially. So there is never more then one query running.
Re:The Linux kernel's inability to gracefully handle low mem... by kilburn on Tuesday August 06, 2019 @07:14AM (#20624114)
The "once per day" part is suspicious. Maybe a scheduled backup is what's running the other query ;)
Re:The Linux kernel's inability to gracefully handle low mem... by HugThem on Tuesday August 06, 2019 @07:22AM (#20624155)
I hade the same suspicion. Especially since the provider indeed runs a nightly backup of the VMs. But even after turning that off, the VM stalled the next night again.
Re:The Linux kernel's inability to gracefully handle low mem... by z3t4 on Tuesday August 06, 2019 @02:21AM (#20622664)
Try doing some rate limiting in order to not cause the dead lock. Should probably also disable write cache. And if it still doesn't work switch to a bare metal machine. And give it a lot of swap and up the swappiness. Swapping is a much better alternative then crashing. VPS providers doesn't like swap because it will tear their SSD disks, so the swap and swappiness is probably preset too low.
Re:The Linux kernel's inability to gracefully handle low mem... by HugThem on Tuesday August 06, 2019 @04:46AM (#20623418)
I tried sleeping 0.1s every 5s or so. It did not help. Still crashed.

I don't think swapping would even occur since neither mysql nor php grow their memory usage over time.

It's not an SSD. It's good old rusty HD.

Re:The Linux kernel's inability to gracefully handle low mem... by jmiserez on Tuesday August 06, 2019 @02:49AM (#20622794)
>Afterwards the table data is corrupted beyond repair.

That should not happen with a DB even if you turn off the power. Are you sure the hardware is good?

Re:The Linux kernel's inability to gracefully handle low mem... by smueller1234 on Tuesday August 06, 2019 @02:53AM (#20622813)
GP ist using the MyISAM storage engine. It's not crash safe. This is sad but expected behavior.

Don't use MyISAM!

Re:The Linux kernel's inability to gracefully handle low mem... by ygra on Tuesday August 06, 2019 @03:01AM (#20622847)
Is there any reason to ever use it (or: Why does it still exist)? In-memory databases for caches or other things that are not critical? I have to admit, I was astounded when I first got the error message from MySQL that a table was corrupted and that I should run REPAIR TABLE. That sounded like very weird behavior for a database.
Re:The Linux kernel's inability to gracefully handle low mem... by smueller1234 on Tuesday August 06, 2019 @09:45AM (#20625081)
Any remaining reasonable use cases would be sufficiently corner-casey that that the first order approximation is "if you want it to behave like a database, no, you do not want MyISAM".

This being said, at least some years ago, a use case I saw that held SOME water then was generating MyISAM tables offline, importing them as-is into a running MySQL (or taking an instance offline and bringing it back up) and then serving from it read-only. At least at the time, this provided better RO performance than InnoDB. I wouldn't be surprised if that was still true. Please don't do that at home!

Also, I think until the previous-to-most-recent release, some internal tables were still MyISAM, causing MySQL overall to have some very rare cases of not being crash safe. Again, I think that's since been resolved in 5.8(?).

Re:The Linux kernel's inability to gracefully handle low mem... by HugThem on Tuesday August 06, 2019 @04:48AM (#20623428)

    Is there any reason to ever use it
It is faster, uses less disk space and has a more logical filesystem layout.
Re:The Linux kernel's inability to gracefully handle low mem... by amaccuish on Tuesday August 06, 2019 @06:13AM (#20623844)
What do you mean by more logical? innodb_file_per_table has existed for a while now.
Re:The Linux kernel's inability to gracefully handle low mem... by HugThem on Tuesday August 06, 2019 @06:45AM (#20623983)
A flag with that name exists, yes. But it does not seperate table data into one file per table. It will still put stuff related to the tables into the central ibdata1 file.

Google "ibdata1 one file per table" to see all the pain it causes.

Re:The Linux kernel's inability to gracefully handle low mem... by amaccuish on Tuesday August 06, 2019 @09:36AM (#20625009)
False.

> But it does not seperate table data into one file per table

That's because if you didn't have it set when creating the database, it won't move data to the new fs layout when you set the setting on, without an OPTIMIZE. If you had it on from the beginning, table data is per file. I literally just did an ls on my /va/lib/mysql and there's a folder per database, in which there are 2 files per table (.frm and .ibd).

When innodb_file_per_table is on, and the database has been OPTIMIZEd, only the following is stored in ibdata1 [0]:

- data dictionary aka metadata of InnoDB tables

- change buffer

- doublewrite buffer

- undo logs

[0] https://www.percona.com/blog/2013/08/20/why-is-the-ibdata1-f...

Re:The Linux kernel's inability to gracefully handle low mem... by HugThem on Tuesday August 06, 2019 @12:46PM (#20626899)

   only the following is stored in ibdata1
You say "only", I say "clusterfuck".

Just look at the very page you linked to. It's a totally confusing concept that befuddles users and causes questions "we often receive", starts "panic", can "unfortunately" not easily be analyzed and you might need to "kill threads" and initiate "rollbacks" to fix the problems it brings.

MyISAM got that right. One dir per database.

Re:The Linux kernel's inability to gracefully handle low mem... by amaccuish on Tuesday August 06, 2019 @02:44PM (#20628182)
Ok but I don't get why you're so obsessed with the fs layout anyway. You should mostly treat it as a black box. And the point of ibdata1 is safety, which as you stated higher up is a serious problem with MyISAM. Even if it's not oom situations, you'll end up stuck sooner or later. You have been warned.
Re:The Linux kernel's inability to gracefully handle low mem... by HugThem on Tuesday August 06, 2019 @03:22PM (#20628565)

    You should mostly treat it as a black box
Again, check the very link you posted. People do that. Until shit hits the fan. And then they have to take that black box apart. Which is not easy.
Re:The Linux kernel's inability to gracefully handle low mem... by PeCaN on Tuesday August 06, 2019 @03:33AM (#20623017)
welcome to MySQL