Como determinar cuales files y DB son las que consumen mas I/O para detectar problemas de performance

by 26. marzo 2009 13:54

En nuestro motor de base de datos contamos con varias database, cada una de ellas o alguno de sus files pueden estar alojadas en 1 o mas discos.

Ahora bien, el consumo de I/O es uno de los problemas mas frecuentes en performance, es un recurso mecánico y mucho mas lento que cualquier otro componente de nuestro equipo (Memoria y CPU).

Los problemas de I/O por lo general se dan por falta de índices o querys mas escritas, si siempre me traiga todos los registros para mostrar unos pocos estaré haciendo un consumo de I/O mucho mas grande de lo que debería.

Para poder medir como se esta comportando mi I/O podemos utilizar los contadores de Windows (por ejemplo el IDLE del disco físico que queremos medir).

Ahora bien, como podemos detectar cual base de datos y/o file de nuestro SQL son los que mas I/O consumen? para ello podemos utilizar una función llamada fn_virtualfilestats la cual se encuentra disponible en la versión 2000 , 2005 y 2008 de SQL Server.

Esta función básicamente nos retornada el listado de files y el consumo de I/O de cada una.

Aquí abajo les dejo un simple query el cual evalúa los I/O y el porcentaje sobre el total para poder detectar cuales files son los que mas consumen mi I/O

DECLARE @TOTAL_IO INT
DECLARE @TOTAL_BYTES INT
DECLARE @TOTAL_STALL INT

SELECT
                        @TOTAL_IO    = SUM(NUMBERREADS + NUMBERWRITES),
                        @TOTAL_BYTES = SUM(BYTESREAD + BYTESWRITTEN),
                        @TOTAL_STALL = SUM(IOSTALLMS) 
FROM   ::FN_VIRTUALFILESTATS(NULL, NULL)
 
SELECT  
                    [DBNAME] = DB_NAME(FN.[DBID]),       
                    [FILENAME],  
                    [NUMBERREADS], 
                    [NUMBERWRITES],  
                    [BYTESREAD], 
                    [BYTESWRITTEN],
                    [IOSTALLMS],            
                    [TOTALIO] = CAST((NUMBERREADS + NUMBERWRITES) AS BIGINT), 
                    [TOTALBYTES] = (BYTESREAD + BYTESWRITTEN), 
                    [AVGSTALLPERIO] = (1.0 * [IOSTALLMS] / ([NUMBERREADS] + [NUMBERWRITES] + 1)), 
                    [AVGBYTESPERIO] = (1.0 * (BYTESREAD + BYTESWRITTEN) / (NUMBERREADS + NUMBERWRITES + 1)), 
                    [%IO] = (100.0 * (NUMBERREADS + NUMBERWRITES) / @TOTAL_IO), 
                    [%BYTES] = (100.0 * (BYTESREAD + BYTESWRITTEN) / @TOTAL_BYTES),  
                    [%STALL] = (100.0 * IOSTALLMS / @TOTAL_STALL) 
             
    FROM ::FN_VIRTUALFILESTATS(NULL, NULL) AS Fn    INNER JOIN SYSALTFILES F 
    ON Fn.FileId  = F.fileid AND Fn.DbId = F.dbid 
    ORDER BY [%IO] DESC 

 

 

Tags: , , , ,

How To

Comentarios

04/04/2009 15:41:46 #

jaja, che, aunque sea nombrame!!!! Besos

MP Argentina

04/04/2009 15:42:20 #

Porque agrego ese dibujito feo en mi comment???

MP Argentina

22/07/2009 0:31:13 #

Please let me know if you are interested to work as article writer for me? I can offer $10/article.

Betsey Johnson United States

13/08/2009 23:48:25 #

Hey I love your style I will subscribe for your feed please keep posting!

Tx Mens Classic Flyback United States

14/08/2009 22:18:14 #

I would like to add your blog to my blogroll please tell me what anchor should I use?

Timex Womens Classic Silver United States

15/08/2009 21:29:16 #

I would like to add your blog to my blogroll please tell me what anchor should I use?

New Michele Urban Mini United States

16/08/2009 20:22:54 #

Very interesting topic will bookmark your site to check if you write more about in the future.

Mens Black Leather United States

17/08/2009 19:49:39 #

I don't like your template but your posts are quite good so I will check back!

Philip Stein Modern Teslar United States

18/08/2009 17:42:54 #

I think you have to improve a bit the design and usability of your blog.

Movado Mens Esperanza Gold United States

26/08/2009 9:26:04 #

Do you earn decent money from this blog or are you doing it just for fun?

Baume Mercier Classima United States

27/08/2009 7:19:37 #

I don't like your template but your posts are quite good so I will check back!

Baume Mercier Classima United States

Maximiliano Damian Accotto