MySQL Governor

Monitor and throttle database resource usage per user.

MySQL Governor Dashboard The MySQL Governor interface for monitoring and managing database resource usage.

Overview

MySQL Governor monitors MySQL/MariaDB connections and applies resource throttling based on user resource plans. It helps prevent individual users from consuming excessive database resources.

How It Works

  1. Governor reads active MySQL threads from performance_schema
  2. Maps MySQL users to system users via /var/run/simuzo/dbmap
  3. Calculates resource usage per user
  4. Applies throttling if user exceeds their limits
  5. Slow queries are terminated when limits are exceeded

Accessing MySQL Governor

Navigate to MySQL Governor in the Admin Panel.

Enable/Disable

Use the toggle button to enable or disable MySQL Governor.

Requirements

Monitoring Tab

View all active MySQL connections in real-time.

Displayed Information

ColumnDescription
Thread IDUnique thread identifier
UserMySQL username
DatabaseCurrent database
CommandSQL command type (Query, Sleep, etc.)
StateCurrent thread state
Time (sec)Query execution time
ThrottledWhether throttling is active

Understanding Throttling

Users marked as Throttled are currently exceeding their database resource limits.

Database Map Tab

View user-to-database mappings used by the governor.

Map Entry Types

TypeFormatDescription
useruser:mysql_user:system_userMaps MySQL user to system user
dbdb:database_name:system_userMaps database to system user

Rebuild Map

Click Rebuild Map if:

Prerequisites

Enable performance_schema

# Check if performance_schema is enabled
mysql -e "SHOW VARIABLES LIKE 'performance_schema';"

# Enable if not
mysql -e "SET GLOBAL performance_schema = ON;"

Create Database Map Manually

# Format: user:mysql_user:system_user
# Example:
# user:root:root
# user:webuser_foo:webuser
# db:webuser_wp:webuser

Service Management

# Check service status
systemctl status simuzo-mysql-governor

# Start service
systemctl start simuzo-mysql-governor

# Stop service
systemctl stop simuzo-mysql-governor

# Restart service
systemctl restart simuzo-mysql-governor

# View logs
journalctl -u simuzo-mysql-governor

Governor Throttling

When a user's queries exceed resource limits:

  1. Governor identifies the user via dbmap
  2. Checks user's cGroup limits for database resources
  3. If exceeded, long-running queries are terminated
  4. New connections may be rejected until usage drops

Troubleshooting

Governor Not Working

  1. Check service: systemctl status simuzo-mysql-governor
  2. Verify dbmap exists: cat /var/run/simuzo/dbmap
  3. Check performance_schema: mysql -e "SHOW VARIABLES LIKE 'performance_schema';"
  4. Review logs: /var/simuzo/logs/

No Throttling Despite High Usage

  1. Verify user mappings in dbmap
  2. Check cGroup limits are configured
  3. Ensure database cGroups exist: ls /sys/fs/cgroup/simuzo-db/

performance_schema Not Available

# Add to my.cnf
[mysqld]
performance_schema = ON

# Restart MySQL
systemctl restart mysql
Best Practice Monitor the Monitoring tab regularly to identify users consistently hitting database limits.

Related Topics