M
M
Max Payne2017-12-12 01:30:32
linux
Max Payne, 2017-12-12 01:30:32

How to deal with deadlocks?

And so, there is a small service with one database, 32 tables in it and about 1.2 million records, ~ 30 requests per second to MariaDB (as PHPMyAdmin says, in fact, in theory, it should be much less) and recently started notice that if you do not do nightly reboots of the server - during the day, and more often at lunchtime or after it, everything is sure to be deadlocked and the service crashes, and even shutting down all application processes does not help, but only restarting MariaDB or immediately the server.
The OS used is Ubuntu 16.04.
I will describe a little the structure of the database, maybe it will help. When designing the database, I was guided by simple rules:
1) Tables to which ONLY SELECT (and very rare UPDATE / DELETE / INSERT, once a week, or even a month) queries use MyISAM.
1.0) Here I included: all tables with static data that do not change + one table with rare INSERTs (several times per hour) and frequent SELECTs.
2) Tables to which go SELECT + UPDATE + INSERT use InnoDB (in MariaDB it is XtraDB).
2.0) Here I included: user table - very frequent SELECT + UPDATE, and rarely INSERT; chat table - very frequent SELECT, rarely UPDATE and INSERT; and others, with which problems are less likely because they are less loaded.
2.1) A highly loaded log table (which has more than a million records) and which uses frequent SELECT + INSERT queries also uses InnoDB (here I doubt the correct choice of subsystem).
The gist of the question is:
Did I do the right thing when choosing subsystems for tables? How can deadlocks be cured?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris Korobkov, 2017-12-12
@BorisKorobkov

1. MySQL can kill deadlock, it does not lead to a server crash.
Specify all deadlock requests. They need to be refactored.
2. Why constantly update users? For counters or the date of the last visit, it is better to choose another storage.
3. Why constantly select users? Use caching
4. Why constantly select logs? Usually logs are only written. Yes, and the database for this, too, is not at all necessary to use.
5. Why constantly select chats? Only enough for new chat members

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question