Bug #35074 max_used_connections is not correct
Submitted: 5 Mar 2008 11:47 Modified: 26 Mar 2008 18:04
Reporter: Alexander Nozdrin Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:5.1 OS:Any
Assigned to: Alexander Nozdrin CPU Architecture:Any

[5 Mar 2008 11:47] Alexander Nozdrin
Description:
According to The Manual: Max_used_connections is the maximum number of connections
that have been in use simultaneously since the server started. This is however
not always true.

The problem is that max_used_connections is calculated as follows:
  max_used_connections= thread_count - delayed_insert_threads;

This expression does not take into account other server threads,
like Event Scheduler, Event Execution threads, NDB threads, ...
That leads to the wrong statistics.

This bug is quite close to Bug#33507.

How to repeat:
Start another internal server thread. For example, let's start Event Scheduler
with no event in the queue (the exactly one thread will be started).

$ ./mysqld # Start mysqld, event scheduler is disabled.

$ ./mysql -u root # Connect as root.
> select id, user from information_schema.processlist order by id;
+----+------+
| id | user |
+----+------+
|  1 | root |
+----+------+

> show status like 'max_used_connections';
+----------------------+-------+
| Variable_name        | Value |
+----------------------+-------+
| Max_used_connections | 1     |
+----------------------+-------+

> set global event_scheduler = on;

> select id, user from information_schema.processlist order by id;
+----+-----------------+
| id | user            |
+----+-----------------+
|  1 | root            |
|  2 | event_scheduler |
+----+-----------------+

> exit

Reconnect to update/recalculate max_used_connections.

$ ./mysql -u root

> show status like 'max_used_connections';
+----------------------+-------+
| Variable_name        | Value |
+----------------------+-------+
| Max_used_connections | 2     |
+----------------------+-------+
[13 Mar 2008 9:01] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/43902

ChangeSet@1.2562, 2008-03-13 12:02:12+03:00, anozdrin@quad. +3 -0
  Fix for Bug#35074: max_used_connections is not correct.
  
  The problem was that number of threads was used to calculate
  max_used_connections.
  
  The fix is to use number of active connections.
[14 Mar 2008 8:07] Alexander Nozdrin
Pushed into 5.1-runtime.
[26 Mar 2008 14:13] Bugs System
Pushed into 5.1.24-rc
[26 Mar 2008 18:04] Paul Dubois
Noted in 5.1.24 changelog.

Non-connection threads were being counted in the value of the
Max_used_connections status variable.
[27 Mar 2008 17:50] Bugs System
Pushed into 6.0.5-alpha
[3 Apr 2008 15:10] Jon Stephens
Also noted fix in the 5.1.23-ndb-6.3.11 and 6.0.5 changelogs.