From: Christopher Powers Date: July 21 2011 12:13am Subject: bzr push into mysql-trunk branch (chris.powers:3324 to 3326) WL#4896 List-Archive: http://lists.mysql.com/commits/140397 Message-Id: <201107210013.p6L0D9F6032451@acsmt357.oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 3326 Christopher Powers 2011-07-20 WL#4896 "Performance Schema Net IO" - Remove unnecessary debug asserts in set_socket() functions - Use 'sql' instead of 'com' category for socket keys and update socket_instances_func.test accordingly @ storage/perfschema/pfs.cc Remove unnecessary DBUG_ASSERTs modified: mysql-test/suite/perfschema/r/socket_instances_func.result mysql-test/suite/perfschema/t/socket_instances_func.test storage/perfschema/pfs.cc 3325 Christopher Powers 2011-07-20 WL#4896 "Performance Schema Net IO" Capture number of bytes read from socket recv() for sockets in IDLE state. modified: sql/sql_parse.cc storage/perfschema/pfs.cc 3324 Christopher Powers 2011-07-20 WL#4896 "Performance Schema Net IO" - Handle socket accept() more effectively for listener sockets modified: sql/mysqld.cc storage/perfschema/pfs.cc === modified file 'mysql-test/suite/perfschema/r/socket_instances_func.result' --- a/mysql-test/suite/perfschema/r/socket_instances_func.result 2011-07-15 00:50:02 +0000 +++ b/mysql-test/suite/perfschema/r/socket_instances_func.result 2011-07-21 00:12:39 +0000 @@ -72,52 +72,52 @@ WHERE PORT = @port; Expect 1 1 # Check the content for the default connection (unix domain) -SELECT EVENT_NAME = 'wait/io/socket/com/client_connection' - AND IP = '' AND PORT = 0 AS 'Expect 1' +SELECT COUNT(*) = 1 as 'Expect 1' FROM performance_schema.socket_instances -WHERE THREAD_ID = @thread_id; +WHERE EVENT_NAME = 'wait/io/socket/sql/client_connection' +AND PORT = 0 AND THREAD_ID = @thread_id; Expect 1 1 # Characteristics of 'server_tcpip_socket' entry # Server listening socket, TCP/IP -# There is only one entry with 'wait/io/socket/com/server_tcpip_socket'. -# It shares the same thread id as 'wait/io/socket/com/server_unix_socket'. +# There is only one entry with 'wait/io/socket/sql/server_tcpip_socket'. +# It shares the same thread id as 'wait/io/socket/sql/server_unix_socket'. SELECT COUNT(*) = 1 AS 'Expect 1' FROM performance_schema.socket_instances -WHERE EVENT_NAME = 'wait/io/socket/com/server_tcpip_socket'; +WHERE EVENT_NAME = 'wait/io/socket/sql/server_tcpip_socket'; Expect 1 1 # Get the 'server_tcpip_socket' thread id SELECT THREAD_ID INTO @thread_id FROM performance_schema.socket_instances -WHERE EVENT_NAME = 'wait/io/socket/com/server_tcpip_socket'; +WHERE EVENT_NAME = 'wait/io/socket/sql/server_tcpip_socket'; # Check the content. SELECT THREAD_ID = @thread_id AND PORT = AND IP = '0.0.0.0' AND STATE = 'ACTIVE' AS 'Expect 1' FROM performance_schema.socket_instances -WHERE EVENT_NAME = 'wait/io/socket/com/server_tcpip_socket'; +WHERE EVENT_NAME = 'wait/io/socket/sql/server_tcpip_socket'; Expect 1 1 # Characteristics of 'server_unix_socket' entry # Server listening socket, unix domain (socket file) -# There is only one entry with 'wait/io/socket/com/server_unix_socket'. -# It shares the same thread id as 'wait/io/socket/com/server_tcpip_socket'. +# There is only one entry with 'wait/io/socket/sql/server_unix_socket'. +# It shares the same thread id as 'wait/io/socket/sql/server_tcpip_socket'. SELECT COUNT(*) = 1 AS 'Expect 1' FROM performance_schema.socket_instances -WHERE EVENT_NAME = 'wait/io/socket/com/server_unix_socket'; +WHERE EVENT_NAME = 'wait/io/socket/sql/server_unix_socket'; Expect 1 1 # Get the 'server_unix_socket' thread id SELECT THREAD_ID INTO @thread_id FROM performance_schema.socket_instances -WHERE EVENT_NAME = 'wait/io/socket/com/server_unix_socket'; +WHERE EVENT_NAME = 'wait/io/socket/sql/server_unix_socket'; # Check the content. SELECT THREAD_ID = @thread_id AND PORT = 0 AND IP = '' AND STATE = 'ACTIVE' AS 'Expect 1' FROM performance_schema.socket_instances -WHERE EVENT_NAME = 'wait/io/socket/com/server_unix_socket'; +WHERE EVENT_NAME = 'wait/io/socket/sql/server_unix_socket'; Expect 1 1 # Server listening sockets (TCP and Unix) are handled on the same thread @@ -136,7 +136,7 @@ select @match_thread_id; @match_thread_id 1 # Check content for client connection 1 (tcpip) -SELECT EVENT_NAME = 'wait/io/socket/com/client_connection' +SELECT EVENT_NAME = 'wait/io/socket/sql/client_connection' AND IP = '127.0.0.1' AND PORT = @port AS 'Expect 1' @@ -152,7 +152,7 @@ WHERE THREAD_ID = @thread_id; Expect 1 1 # Check content for client connection 2 (tcpip) -SELECT EVENT_NAME = 'wait/io/socket/com/client_connection' +SELECT EVENT_NAME = 'wait/io/socket/sql/client_connection' AND IP = '127.0.0.1' AND PORT = @port AS 'Expect 1' @@ -168,7 +168,7 @@ WHERE THREAD_ID = @thread_id; Expect 1 1 # Check the content for client connection 3 (unix domain). -SELECT EVENT_NAME = 'wait/io/socket/com/client_connection' +SELECT EVENT_NAME = 'wait/io/socket/sql/client_connection' AND IP = '' AND PORT = 0 AS 'Expect 1' @@ -191,9 +191,9 @@ NOT IN (SELECT EVENT_NAME,OBJECT_INSTANC FROM my_socket_instances) ORDER BY THREAD_ID; EVENT_NAME IP -wait/io/socket/com/client_connection 127.0.0.1 -wait/io/socket/com/client_connection 127.0.0.1 -wait/io/socket/com/client_connection +wait/io/socket/sql/client_connection 127.0.0.1 +wait/io/socket/sql/client_connection 127.0.0.1 +wait/io/socket/sql/client_connection # Disconnect con1, con2 and con3 # Show differences to socket_instances before con1,con1 connecting. # There should be none. === modified file 'mysql-test/suite/perfschema/t/socket_instances_func.test' --- a/mysql-test/suite/perfschema/t/socket_instances_func.test 2011-07-15 00:50:02 +0000 +++ b/mysql-test/suite/perfschema/t/socket_instances_func.test 2011-07-21 00:12:39 +0000 @@ -182,16 +182,16 @@ WHERE PORT = @port; --echo # Check the content for the default connection (unix domain) # EVENT_NAME OBJECT_INSTANCE_BEGIN THREAD_ID SOCKET_ID IP PORT STATE -# wait/io/socket/com/client_connection 139799531958280 16 37 0 ACTIVE +# wait/io/socket/sql/client_connection 139799531958280 16 37 0 ACTIVE --disable_query_log eval set @thread_id = $con0_thread_id; --enable_query_log -SELECT EVENT_NAME = 'wait/io/socket/com/client_connection' - AND IP = '' AND PORT = 0 AS 'Expect 1' +SELECT COUNT(*) = 1 as 'Expect 1' FROM performance_schema.socket_instances -WHERE THREAD_ID = @thread_id; +WHERE EVENT_NAME = 'wait/io/socket/sql/client_connection' +AND PORT = 0 AND THREAD_ID = @thread_id; # # VERIFY SERVER LISTENING SOCKET, TCP/IP @@ -199,19 +199,19 @@ WHERE THREAD_ID = @thread_id; --echo # Characteristics of 'server_tcpip_socket' entry --echo # Server listening socket, TCP/IP ---echo # There is only one entry with 'wait/io/socket/com/server_tcpip_socket'. ---echo # It shares the same thread id as 'wait/io/socket/com/server_unix_socket'. +--echo # There is only one entry with 'wait/io/socket/sql/server_tcpip_socket'. +--echo # It shares the same thread id as 'wait/io/socket/sql/server_unix_socket'. SELECT COUNT(*) = 1 AS 'Expect 1' FROM performance_schema.socket_instances -WHERE EVENT_NAME = 'wait/io/socket/com/server_tcpip_socket'; +WHERE EVENT_NAME = 'wait/io/socket/sql/server_tcpip_socket'; # Store the thread id of server_tcpip_socket --echo # Get the 'server_tcpip_socket' thread id SELECT THREAD_ID INTO @thread_id FROM performance_schema.socket_instances -WHERE EVENT_NAME = 'wait/io/socket/com/server_tcpip_socket'; +WHERE EVENT_NAME = 'wait/io/socket/sql/server_tcpip_socket'; let $server_tcpip_thread_id= `SELECT @thread_id`; @@ -222,7 +222,7 @@ eval SELECT THREAD_ID = @thread_id AND PORT = $MASTER_MYPORT AND IP = '0.0.0.0' AND STATE = 'ACTIVE' AS 'Expect 1' FROM performance_schema.socket_instances -WHERE EVENT_NAME = 'wait/io/socket/com/server_tcpip_socket'; +WHERE EVENT_NAME = 'wait/io/socket/sql/server_tcpip_socket'; # # VERIFY SERVER LISTENING SOCKET, UNIX DOMAIN @@ -230,19 +230,19 @@ WHERE EVENT_NAME = 'wait/io/socket/com/s --echo # Characteristics of 'server_unix_socket' entry --echo # Server listening socket, unix domain (socket file) ---echo # There is only one entry with 'wait/io/socket/com/server_unix_socket'. ---echo # It shares the same thread id as 'wait/io/socket/com/server_tcpip_socket'. +--echo # There is only one entry with 'wait/io/socket/sql/server_unix_socket'. +--echo # It shares the same thread id as 'wait/io/socket/sql/server_tcpip_socket'. SELECT COUNT(*) = 1 AS 'Expect 1' FROM performance_schema.socket_instances -WHERE EVENT_NAME = 'wait/io/socket/com/server_unix_socket'; +WHERE EVENT_NAME = 'wait/io/socket/sql/server_unix_socket'; # Store the thread id of 'server_unix_socket' --echo # Get the 'server_unix_socket' thread id SELECT THREAD_ID INTO @thread_id FROM performance_schema.socket_instances -WHERE EVENT_NAME = 'wait/io/socket/com/server_unix_socket'; +WHERE EVENT_NAME = 'wait/io/socket/sql/server_unix_socket'; let $server_unix_thread_id= `SELECT @thread_id`; @@ -251,7 +251,7 @@ eval SELECT THREAD_ID = @thread_id AND PORT = 0 AND IP = '' AND STATE = 'ACTIVE' AS 'Expect 1' FROM performance_schema.socket_instances -WHERE EVENT_NAME = 'wait/io/socket/com/server_unix_socket'; +WHERE EVENT_NAME = 'wait/io/socket/sql/server_unix_socket'; # # VERIFY SERVER LISTENING SOCKET THREAD IDs @@ -287,7 +287,7 @@ select @match_thread_id; # # EVENT_NAME OBJECT_INSTANCE_BEGIN THREAD_ID SOCKET_ID IP PORT STATE -# wait/io/socket/com/client_connection 140707865187120 18 59 127.0.0.1 59298 IDLE or ACTIVE +# wait/io/socket/sql/client_connection 140707865187120 18 59 127.0.0.1 59298 IDLE or ACTIVE --echo # Check content for client connection 1 (tcpip) @@ -296,7 +296,7 @@ eval set @port = $con1_port; eval set @thread_id = $con1_thread_id; --enable_query_log -eval SELECT EVENT_NAME = 'wait/io/socket/com/client_connection' +eval SELECT EVENT_NAME = 'wait/io/socket/sql/client_connection' AND IP = '127.0.0.1' AND PORT = @port AS 'Expect 1' @@ -315,7 +315,7 @@ WHERE THREAD_ID = @thread_id; # # EVENT_NAME OBJECT_INSTANCE_BEGIN THREAD_ID SOCKET_ID IP PORT STATE -# wait/io/socket/com/client_connection 140707865187120 18 59 127.0.0.1 59298 IDLE or ACTIVE +# wait/io/socket/sql/client_connection 140707865187120 18 59 127.0.0.1 59298 IDLE or ACTIVE --echo # Check content for client connection 2 (tcpip) @@ -324,7 +324,7 @@ eval set @port = $con2_port; eval set @thread_id = $con2_thread_id; --enable_query_log -eval SELECT EVENT_NAME = 'wait/io/socket/com/client_connection' +eval SELECT EVENT_NAME = 'wait/io/socket/sql/client_connection' AND IP = '127.0.0.1' AND PORT = @port AS 'Expect 1' @@ -343,7 +343,7 @@ WHERE THREAD_ID = @thread_id; # # EVENT_NAME OBJECT_INSTANCE_BEGIN THREAD_ID SOCKET_ID IP PORT STATE -# wait/io/socket/com/client_connection 139799531958280 16 37 0 IDLE or ACTIVE +# wait/io/socket/sql/client_connection 139799531958280 16 37 0 IDLE or ACTIVE --echo # Check the content for client connection 3 (unix domain). @@ -351,7 +351,7 @@ WHERE THREAD_ID = @thread_id; eval set @thread_id = $con3_thread_id; --enable_query_log -eval SELECT EVENT_NAME = 'wait/io/socket/com/client_connection' +eval SELECT EVENT_NAME = 'wait/io/socket/sql/client_connection' AND IP = '' AND PORT = 0 AS 'Expect 1' === modified file 'sql/sql_parse.cc' --- a/sql/sql_parse.cc 2011-07-17 03:30:21 +0000 +++ b/sql/sql_parse.cc 2011-07-20 23:11:24 +0000 @@ -790,7 +790,7 @@ bool do_command(THD *thd) ulong packet_length; NET *net= &thd->net; enum enum_server_command command; - // CWP: MYSQL_IDLE_WAIT_VARIABLES(idle_locker, idle_state) /* no ; */ + MYSQL_IDLE_WAIT_VARIABLES(idle_locker, idle_state) /* no ; */ DBUG_ENTER("do_command"); @@ -838,13 +838,13 @@ bool do_command(THD *thd) - do not time the wait on the socket - time the wait as IDLE server time instead. */ - // CWP: disabled mysql_socket_set_state(net->vio->mysql_socket, PSI_SOCKET_STATE_IDLE); - // CWP: MYSQL_START_IDLE_WAIT(idle_locker, &idle_state); + mysql_socket_set_state(net->vio->mysql_socket, PSI_SOCKET_STATE_IDLE); + MYSQL_START_IDLE_WAIT(idle_locker, &idle_state); packet_length= my_net_read(net); - // CWP: MYSQL_END_IDLE_WAIT(idle_locker); - // CWP: mysql_socket_set_state(net->vio->mysql_socket, PSI_SOCKET_STATE_ACTIVE); + MYSQL_END_IDLE_WAIT(idle_locker); + mysql_socket_set_state(net->vio->mysql_socket, PSI_SOCKET_STATE_ACTIVE); if (packet_length == packet_error) { === modified file 'storage/perfschema/pfs.cc' --- a/storage/perfschema/pfs.cc 2011-07-20 18:44:46 +0000 +++ b/storage/perfschema/pfs.cc 2011-07-21 00:12:39 +0000 @@ -2767,7 +2767,7 @@ get_thread_socket_locker_v1(PSI_socket_l DBUG_ASSERT(pfs_socket->m_class != NULL); - if (pfs_socket->m_idle || !pfs_socket->m_enabled) + if (!pfs_socket->m_enabled) return NULL; register uint flags; @@ -2785,7 +2785,8 @@ get_thread_socket_locker_v1(PSI_socket_l state->m_thread= reinterpret_cast (pfs_thread); flags= STATE_FLAG_THREAD; - if (pfs_socket->m_timed) + /* Sockets in IDLE state are timed separately */ + if (pfs_socket->m_timed && !pfs_socket->m_idle) flags|= STATE_FLAG_TIMED; if (flag_events_waits_current) @@ -2819,7 +2820,8 @@ get_thread_socket_locker_v1(PSI_socket_l } else { - if (pfs_socket->m_timed) + /* Sockets in IDLE state are counted but not timed */ + if (pfs_socket->m_timed && !pfs_socket->m_idle) { flags= STATE_FLAG_TIMED; } @@ -2828,10 +2830,10 @@ get_thread_socket_locker_v1(PSI_socket_l flags= 0; /* - get_thread_socket_locker() does not track the byte count associated - with socket operations because the requested and actual byte counts - may differ. This shortcut is therefore only valid for 'miscellaneous' - operations that do not have a byte count. + Even if timing is disabled, end_socket_wait() still needs a locker to + capture the number of bytes sent or received by the socket operation. + However, for operations that do not have a byte count, then just + increment the event counter and return a NULL locker. */ switch (op) { @@ -4574,14 +4576,15 @@ static void end_socket_wait_v1(PSI_socke { PSI_socket_locker_state *state= reinterpret_cast (locker); DBUG_ASSERT(state != NULL); - ulonglong timer_end= 0; - ulonglong wait_time= 0; - bool socket_closed= false; - PFS_socket *socket= reinterpret_cast(state->m_socket); DBUG_ASSERT(socket != NULL); PFS_thread *thread= reinterpret_cast(state->m_thread); + DBUG_ASSERT(thread != NULL); + ulonglong timer_end= 0; + ulonglong wait_time= 0; + bool socket_closed= false; + bool socket_idle= socket->m_idle; PFS_byte_stat *byte_stat; register uint flags= state->m_flags; size_t bytes= ((int)byte_count > -1 ? byte_count : 0); @@ -4686,6 +4689,10 @@ static void end_socket_wait_v1(PSI_socke } } + /* Clear IDLE state */ + if (socket_idle) + socket->m_idle= false; + /* This socket will no longer be used */ if (socket_closed) destroy_socket(socket); @@ -4693,11 +4700,10 @@ static void end_socket_wait_v1(PSI_socke static void set_socket_state_v1(PSI_socket *socket, PSI_socket_state state) { - DBUG_ASSERT(socket); DBUG_ASSERT((state == PSI_SOCKET_STATE_IDLE) || (state == PSI_SOCKET_STATE_ACTIVE)); - PFS_socket *pfs= reinterpret_cast(socket); - if (unlikely(pfs == NULL)) + if (unlikely(socket == NULL)) return; + PFS_socket *pfs= reinterpret_cast(socket); pfs->m_idle= (state == PSI_SOCKET_STATE_IDLE); } @@ -4709,12 +4715,11 @@ static void set_socket_info_v1(PSI_socke const struct sockaddr *addr, socklen_t addr_len) { - DBUG_ASSERT(socket); - PFS_socket *pfs= reinterpret_cast(socket); - - if (unlikely(pfs == NULL)) + if (unlikely(socket == NULL)) return; + PFS_socket *pfs= reinterpret_cast(socket); + /** Set socket descriptor */ if (fd != NULL) pfs->m_fd= *fd; @@ -4738,13 +4743,10 @@ static void set_socket_info_v1(PSI_socke */ static void set_socket_thread_owner_v1(PSI_socket *socket) { - if (likely(socket != NULL)) - { - PFS_socket *pfs_socket= reinterpret_cast(socket); - if (unlikely(pfs_socket == NULL)) - return; - pfs_socket->m_thread_owner= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS); - } + if (unlikely(socket == NULL)) + return; + PFS_socket *pfs_socket= reinterpret_cast(socket); + pfs_socket->m_thread_owner= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS); } /** No bundle (reason: useless for push emails).