USER_STATISTICS shows incorrect value for number of concurrent connections

Bug #728082 reported by Swany
18
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Percona Server moved to https://jira.percona.com/projects/PS
Status tracked in 5.7
5.1
Won't Fix
Medium
Unassigned
5.5
Fix Released
Medium
Nickolay Ihalainen
5.6
Fix Released
Medium
Nickolay Ihalainen
5.7
Fix Released
Medium
Nickolay Ihalainen

Bug Description

mysql> select * from USER_STATISTICS where user='cactiuser'\G
*************************** 1. row ***************************
                  USER: cactiuser
     TOTAL_CONNECTIONS: 1002
CONCURRENT_CONNECTIONS: 0
        CONNECTED_TIME: 23918
             BUSY_TIME: 41
              CPU_TIME: 32
        BYTES_RECEIVED: 1823054
            BYTES_SENT: 933888
  BINLOG_BYTES_WRITTEN: 0
          ROWS_FETCHED: 698035
          ROWS_UPDATED: 4422
       TABLE_ROWS_READ: 19428245
       SELECT_COMMANDS: 7832
       UPDATE_COMMANDS: 2398
        OTHER_COMMANDS: 4620
   COMMIT_TRANSACTIONS: 9306
 ROLLBACK_TRANSACTIONS: 0
    DENIED_CONNECTIONS: 0
      LOST_CONNECTIONS: 0
         ACCESS_DENIED: 0
         EMPTY_QUERIES: 2625
1 row in set (0.00 sec)

Note that CONCURRENT_CONNECTIONS shows 0, but it should always be at least 1, and in this case it should be much higher:

In the following snippet from SHOW PROCESSLIST you can see multiple concurrent connections by this user:
*************************** 19. row ***************************
     Id: 389
   User: cactiuser
   Host: localhost
     db: cacti
Command: Sleep
   Time: 710
  State:
   Info: NULL
*************************** 20. row ***************************
     Id: 390
   User: cactiuser
   Host: localhost
     db: cacti
Command: Sleep
   Time: 3937
  State:
   Info: NULL
*************************** 21. row ***************************
     Id: 391
   User: cactiuser
   Host: localhost
     db: cacti
Command: Sleep
   Time: 710
  State:
   Info: NULL
21 rows in set (0.00 sec)

Tags: userstat

Related branches

Revision history for this message
Swany (greenlion) wrote :

Percona Server 5.5.8-55

Stewart Smith (stewart)
Changed in percona-server:
importance: Undecided → Medium
assignee: nobody → Valentine Gostev (core-longbow)
Revision history for this message
Valentine Gostev (longbow) wrote :

Oleg, please examine the patch source (I could not find the condition when concurrent_connections is different from zero)

Changed in percona-server:
assignee: Valentine Gostev (longbow) → Oleg Tsarev (tsarev)
status: New → Confirmed
Oleg Tsarev (tsarev)
Changed in percona-server:
status: Confirmed → In Progress
Revision history for this message
Oleg Tsarev (tsarev) wrote :

I found following:
userstats.patch was incorrectly ported from google-patches.

Oleg Tsarev (tsarev)
tags: added: userstats
Oleg Tsarev (tsarev)
Changed in percona-server:
status: In Progress → Fix Committed
status: Fix Committed → In Progress
Revision history for this message
Oleg Tsarev (tsarev) wrote :

In fix I did following (comment from commit):

------
Add set_connections function (related to incomplete port from Google patch) and add call to send_user_stats and send_thread_stats (bug #728082, bug #608027). Without this call statistcs from separated thread didn't aggregated to global_[client|thread|user]_stats.
------

Every thread contains STATS diff_stats structure, which collected information about CPU_Time/other counters after every executed query.
Function "set_connection_stats" extract this information from thread to global_[client|thread|user]_stats.

Port from Google patch was incomplete - set_connection_stats missed, and information doesn't moved from THD to HASH table.

Revision history for this message
Oleg Tsarev (tsarev) wrote :

Additional information. Concurrent_connection is update in increment_count_by_name ([client|user]_stats) and increment_count_by_id (thread_stats).

Before fix this information updated just after thread complete (and just for this thread), as result Concurrent_connection always zero.

After my fix, set_connection_stats clean all Concurrent_connections counter, and calculate it directly from every thread (set_connection_stats called on SHOW [CLIENT|THREAD|USER]_STATS).

tags: added: userstat
removed: userstats
Revision history for this message
Laurynas Biveinis (laurynas-biveinis) wrote :
Revision history for this message
Shahriyar Rzayev (rzayev-sehriyar) wrote :

Percona now uses JIRA for bug reports so this bug report is migrated to: https://jira.percona.com/browse/PS-1193

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.