SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Combining R and SQL Server to diagnose performance bottlenecks


Combining R and SQL Server to diagnose performance bottlenecks

Author
Message
nick.dale.burns
nick.dale.burns
Mr or Mrs. 500
Mr or Mrs. 500 (577 reputation)Mr or Mrs. 500 (577 reputation)Mr or Mrs. 500 (577 reputation)Mr or Mrs. 500 (577 reputation)Mr or Mrs. 500 (577 reputation)Mr or Mrs. 500 (577 reputation)Mr or Mrs. 500 (577 reputation)Mr or Mrs. 500 (577 reputation)

Group: General Forum Members
Points: 577 Visits: 270
Comments posted to this topic are about the item Combining R and SQL Server to diagnose performance bottlenecks
Craig Thomson-419971
Craig Thomson-419971
SSC Veteran
SSC Veteran (261 reputation)SSC Veteran (261 reputation)SSC Veteran (261 reputation)SSC Veteran (261 reputation)SSC Veteran (261 reputation)SSC Veteran (261 reputation)SSC Veteran (261 reputation)SSC Veteran (261 reputation)

Group: General Forum Members
Points: 261 Visits: 376
Gosh, I wish I understood that.
Robert Sterbal-482516
Robert Sterbal-482516
Mr or Mrs. 500
Mr or Mrs. 500 (589 reputation)Mr or Mrs. 500 (589 reputation)Mr or Mrs. 500 (589 reputation)Mr or Mrs. 500 (589 reputation)Mr or Mrs. 500 (589 reputation)Mr or Mrs. 500 (589 reputation)Mr or Mrs. 500 (589 reputation)Mr or Mrs. 500 (589 reputation)

Group: General Forum Members
Points: 589 Visits: 285
How important is the integration to the process? I'm not likely to see SQL Server 2016 in production for years. I have performance problems today that might benefit from the method.
nick.dale.burns
nick.dale.burns
Mr or Mrs. 500
Mr or Mrs. 500 (577 reputation)Mr or Mrs. 500 (577 reputation)Mr or Mrs. 500 (577 reputation)Mr or Mrs. 500 (577 reputation)Mr or Mrs. 500 (577 reputation)Mr or Mrs. 500 (577 reputation)Mr or Mrs. 500 (577 reputation)Mr or Mrs. 500 (577 reputation)

Group: General Forum Members
Points: 577 Visits: 270
Hi Craig, thank you for your response. I don't think it is really terribly difficult, but I guess the big disappointment is that it isn't a hard and fast answer Sad But it is the start of a more targeted investigation - specifically focusing on the worst tables.

Assuming that there are issues with queries or index design, focus on the points that scatter out from the rest and start to look at the most expensive queries and the indexes on those tables. You will only have to do this a few times to start to see common patterns that you will quickly begin to recognise.

Regards,
Nick
nick.dale.burns
nick.dale.burns
Mr or Mrs. 500
Mr or Mrs. 500 (577 reputation)Mr or Mrs. 500 (577 reputation)Mr or Mrs. 500 (577 reputation)Mr or Mrs. 500 (577 reputation)Mr or Mrs. 500 (577 reputation)Mr or Mrs. 500 (577 reputation)Mr or Mrs. 500 (577 reputation)Mr or Mrs. 500 (577 reputation)

Group: General Forum Members
Points: 577 Visits: 270
Hi Robert - good news! This analysis does not need SQL Server 2016. Run the DMV query, save the results to a CSV and then use R to read the CSV and analyse it like any other data set.

There is one big caveat here; that the analysis primarily focuses on the way that data is being read from tables, i.e. poor indexing or nasty queries. Common issues like memory, CPU, disk, recent changes in the environment etc. should be excluded as well.

Regards,
Nick
Robert Sterbal-482516
Robert Sterbal-482516
Mr or Mrs. 500
Mr or Mrs. 500 (589 reputation)Mr or Mrs. 500 (589 reputation)Mr or Mrs. 500 (589 reputation)Mr or Mrs. 500 (589 reputation)Mr or Mrs. 500 (589 reputation)Mr or Mrs. 500 (589 reputation)Mr or Mrs. 500 (589 reputation)Mr or Mrs. 500 (589 reputation)

Group: General Forum Members
Points: 589 Visits: 285
nick.dale.burns (12/7/2015)
Hi Robert - good news! This analysis does not need SQL Server 2016. Run the DMV query, save the results to a CSV and then use R to read the CSV and analyse it like any other data set.

There is one big caveat here; that the analysis primarily focuses on the way that data is being read from tables, i.e. poor indexing or nasty queries. Common issues like memory, CPU, disk, recent changes in the environment etc. should be excluded as well.

Regards,
Nick


Great!

Do you have some traces set up as a models for excluding those events? Should I share my attempts here?
Grant Fritchey
Grant Fritchey
SSC Guru
SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)

Group: General Forum Members
Points: 94139 Visits: 33010
Thanks for this. Very timely. I'm just barely getting started in R and this was extremely useful.

A couple of notes though. The query you start with, it has an ORDER BY clause on a column that's not defined. I changed my query like this:

SELECT  OBJECT_NAME(ops.object_id) AS [Object Name],
SUM(ops.range_scan_count) AS [Range Scans],
SUM(ops.singleton_lookup_count) AS [Singleton Lookups],
SUM(ops.row_lock_count) AS [Row Locks],
SUM(ops.row_lock_wait_in_ms) AS [Row Lock Waits (ms)],
SUM(ops.page_lock_count) AS [Page Locks],
SUM(ops.page_lock_wait_in_ms) AS [Page Lock Waits (ms)],
SUM(ops.page_io_latch_wait_in_ms) AS [Page IO Latch Wait (ms)],
SUM(ops.row_lock_count) AS [RowCount]
FROM sys.dm_db_index_operational_stats(NULL, NULL, NULL, NULL) AS ops
INNER JOIN sys.indexes AS idx
ON idx.object_id = ops.object_id
AND idx.index_id = ops.index_id
INNER JOIN sys.sysindexes AS sysidx
ON idx.object_id = sysidx.id
WHERE ops.object_id > 100
GROUP BY ops.object_id
ORDER BY [RowCount] DESC;



Is that what you were originally going for, or should I just ignore the ORDER BY clause?

----------------------------------------------------
The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood...
Theodore Roosevelt

The Scary DBA
Author of: SQL Server Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
Grant Fritchey
Grant Fritchey
SSC Guru
SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)

Group: General Forum Members
Points: 94139 Visits: 33010
Looks like this code was missing a set of quotes:

data <- read.csv("hotspots_data.csv)


Or am I wrong on that. I ran my local copy with closing quotes around the hotspots_data.csv file name and it worked, or did I break things?

Just trying to understand here. It's all new to me.

----------------------------------------------------
The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood...
Theodore Roosevelt

The Scary DBA
Author of: SQL Server Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
Grant Fritchey
Grant Fritchey
SSC Guru
SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)

Group: General Forum Members
Points: 94139 Visits: 33010
I'm getting errors from this bit. It could be that I'm using RevolutionR, or it could be Steve's formatting:

# load GGPLOT library(ggplot2) plot.data <- data.frame(pca$x[, 1:2]) g <- ggplot(plot.data, aes(x=PC1, y=PC2)) + geom_point(colour=alpha("steelblue", 0.5), size=3) + geom_text(label=1:102, colour="darkgrey", hjust=1.5) + theme_bw() print(g) 


----------------------------------------------------
The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood...
Theodore Roosevelt

The Scary DBA
Author of: SQL Server Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
Grant Fritchey
Grant Fritchey
SSC Guru
SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)

Group: General Forum Members
Points: 94139 Visits: 33010
Ah, figured out that part of my problem is that I don't have the GGPLOT library. Off to track that down.

Seriously, thanks again for this. You've started me exploring exactly the kind of thing I was hoping to get out of R in the first place. It's truly appreciated.

----------------------------------------------------
The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood...
Theodore Roosevelt

The Scary DBA
Author of: SQL Server Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search