Mehul Bhuva is an AI and Data Platform Engineer bringing two decades of specialized experience across Microsoft's technology ecosystem. His proficiency spans Azure, Databricks, Microsoft AI Foundry, Azure Data Factory, Blazor/Angular frameworks, Powershell and Power BI.
Wednesday, November 2, 2016
Tuesday, November 1, 2016
Monitor Read/Write Latency on your SQL Database
SQL query to monitor Read/Write latency on your SQL Server database. Can be of great help while performance tuning your SQL database.
Copy and run this query against your database:
SELECT
[ReadLatencyAvg ms] =
CASE WHEN [num_of_reads] = 0
THEN 0 ELSE ([io_stall_read_ms] / [num_of_reads]) END,
[WriteLatencyAvg ms] =
CASE WHEN [num_of_writes] = 0
THEN 0 ELSE ([io_stall_write_ms] / [num_of_writes]) END,
[LatencyAvg ms] =
CASE WHEN ([num_of_reads] = 0 AND [num_of_writes] = 0)
THEN 0 ELSE ([io_stall] / ([num_of_reads] + [num_of_writes])) END,
[AvgBPerRead] =
CASE WHEN [num_of_reads] = 0
THEN 0 ELSE ([num_of_bytes_read] / [num_of_reads]) END,
[AvgBPerWrite] =
CASE WHEN [num_of_writes] = 0
THEN 0 ELSE ([num_of_bytes_written] / [num_of_writes]) END,
[AvgBPerTransfer] =
CASE WHEN ([num_of_reads] = 0 AND [num_of_writes] = 0)
THEN 0 ELSE
(([num_of_bytes_read] + [num_of_bytes_written]) /
([num_of_reads] + [num_of_writes])) END,
LEFT ([mf].[physical_name], 2) AS [Drive],
DB_NAME ([vfs].[database_id]) AS [DB],
[mf].[physical_name],
[vfs].[file_id]
FROM
sys.dm_io_virtual_file_stats (NULL,NULL) AS [vfs]
JOIN sys.master_files AS [mf]
ON [vfs].[database_id] = [mf].[database_id]
AND [vfs].[file_id] = [mf].[file_id]
-- WHERE [vfs].[file_id] = 1 -- mdf data files
-- WHERE [vfs].[file_id] = 2 -- log files
-- ORDER BY [LatencyAvg ms] DESC
-- ORDER BY [ReadLatencyAvg ms] DESC
ORDER BY [WriteLatencyAvg ms] DESC;
GO
Industry-wide bechmarks for performance evaluation:
-- Excellent: < 1ms
-- Very good: < 5ms
-- Good: 5 – 10ms
-- Poor: 10 – 20ms
-- Bad: 20 – 100ms
-- Really bad: 100 – 500ms
-- Really Really Bad: > 500ms
Copy and run this query against your database:
SELECT
[ReadLatencyAvg ms] =
CASE WHEN [num_of_reads] = 0
THEN 0 ELSE ([io_stall_read_ms] / [num_of_reads]) END,
[WriteLatencyAvg ms] =
CASE WHEN [num_of_writes] = 0
THEN 0 ELSE ([io_stall_write_ms] / [num_of_writes]) END,
[LatencyAvg ms] =
CASE WHEN ([num_of_reads] = 0 AND [num_of_writes] = 0)
THEN 0 ELSE ([io_stall] / ([num_of_reads] + [num_of_writes])) END,
[AvgBPerRead] =
CASE WHEN [num_of_reads] = 0
THEN 0 ELSE ([num_of_bytes_read] / [num_of_reads]) END,
[AvgBPerWrite] =
CASE WHEN [num_of_writes] = 0
THEN 0 ELSE ([num_of_bytes_written] / [num_of_writes]) END,
[AvgBPerTransfer] =
CASE WHEN ([num_of_reads] = 0 AND [num_of_writes] = 0)
THEN 0 ELSE
(([num_of_bytes_read] + [num_of_bytes_written]) /
([num_of_reads] + [num_of_writes])) END,
LEFT ([mf].[physical_name], 2) AS [Drive],
DB_NAME ([vfs].[database_id]) AS [DB],
[mf].[physical_name],
[vfs].[file_id]
FROM
sys.dm_io_virtual_file_stats (NULL,NULL) AS [vfs]
JOIN sys.master_files AS [mf]
ON [vfs].[database_id] = [mf].[database_id]
AND [vfs].[file_id] = [mf].[file_id]
-- WHERE [vfs].[file_id] = 1 -- mdf data files
-- WHERE [vfs].[file_id] = 2 -- log files
-- ORDER BY [LatencyAvg ms] DESC
-- ORDER BY [ReadLatencyAvg ms] DESC
ORDER BY [WriteLatencyAvg ms] DESC;
GO
Industry-wide bechmarks for performance evaluation:
-- Excellent: < 1ms
-- Very good: < 5ms
-- Good: 5 – 10ms
-- Poor: 10 – 20ms
-- Bad: 20 – 100ms
-- Really bad: 100 – 500ms
-- Really Really Bad: > 500ms
Friday, February 19, 2016
Dependency Injection in MVC .NET
I found an excellent article that explains why Dependency Injection (DI) can be so helpful, especially when you write .NET Applications using MVC. With DI we can enforce Single Responsibility principle, perform BDD (Behavior driven development), develop testable code,write Automated Unit test cases and enforce good design practices.
Read the full post here to understand why Dependency injection can be so helpful:
http://www.mikesdotnetting.com/article/285/asp-net-5-dependency-injection-and-services-in-mvc
Read the full post here to understand why Dependency injection can be so helpful:
http://www.mikesdotnetting.com/article/285/asp-net-5-dependency-injection-and-services-in-mvc
Thursday, January 21, 2016
Entity Framework Performance
I found an excellent article that talks about enhancing Entity Framework performance: https://www.simple-talk.com/dotnet/.net-tools/entity-framework-performance-and-what-you-can-do-about-it/
It covers a lot of good practices in writing queries against Entity Framework.
It covers a lot of good practices in writing queries against Entity Framework.
Subscribe to:
Posts (Atom)





