MySQL – Implementing a Message Queue Per User

MySQLqueue

I am using the same user to connect 4 servers to a database.

Although the database is not overloaded, I think that if a heavy query delay occurs on one server, the other servers are affected, especially for new connections.

Mysql server accepts up to 4030 simultaneous connections and has no query limits per user.

Does Mysql queue the queries of the same user or those of all?

If I create a mysql user for each server will I better optimize user queries and queues?

Thank you so much.

Best Answer

MySQL does not queue queries for the same user. Each connection, regardless of the MySQL user, has its own thread in mysqld (unless you use the thread pool plugin, but that's a separate conversation), and the MySQL Server allows any thread to start a query at any time. It'll do its best to handle all the threads, by using OS thread scheduling. It would do the same thing if you have a single MySQL user for all threads, or a distinct MySQL user for each thread.

It's actually typical in many applications I've seen that the client connects to the MySQL Server using a single MySQL user credential. There is no queuing by user, though it is possible to run so many concurrent queries that they may queue up against each other for access to some shared resources like CPUs or locks. That has nothing to do with which MySQL users are used.

MySQL does support options for setting resource limits per user (see https://dev.mysql.com/doc/refman/8.0/en/user-resources.html), but I have not seen this feature used except in shared hosting environments.