Advertisement
Guest User

SLOB.R v0.6

a guest
Feb 20th, 2013
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 8.05 KB | None | 0 0
  1. # SLOB.R version 0.6
  2. #   BJP 2013 - Twitter @BrianPardy - http://pardydba.wordpress.com/
  3. # See http://wp.me/p2Jp2m-4i for more information
  4. #
  5. #
  6. # Assumes three possible SLOB test models: READS, REDO, WRITES
  7. #   READS are readers-only
  8. #   REDO and WRITES are writers only, differing in size of buffer_cache (small = REDO, large = WRITES)
  9. #
  10. #   Reports PREADS in SLOB.R READS model
  11. #   Reports REDO in SLOB.R REDO model
  12. #   Reports PWRITES in SLOB.R WRITES model
  13. #   Use SLOB.R meta-model READWRITE to report PREADS+PWRITES in WRITES model
  14. #
  15. # Setup:
  16. #   Run SLOB as usual, with at least three runs for each variable tested for each model
  17. #   Save awr.txt between runs in filename matching [something]-variable.writers.readers
  18. #     Example:  AWR-FCSAN-run1.8.0, AWR-FCSAN-run2.8.0 (...) AWR-FCSAN-run10.8.0
  19. #               AWR-ISCSINAS-run1.8.0, AWR-ISCSINAS-run2.8.0 (...) AWR-ISCSINAS-run10.8.0
  20. #       (In this case, the variables would be "FCSCAN" and "ISCSINAS", comparing fibrechannel SAN to NAS)
  21. #   Run awr_info.sh from SLOB distribution against all AWR files at the end and save the output
  22. #   Load awr_info.sh output into R with:  SLOB <- loadSLOB("filename")
  23. #
  24. # Hints:
  25. #   Best results achieved with more SLOB runs - myavg() drops high and low values per set, averages remaining
  26. #
  27. # Detailed example usage:
  28. #   Testing SLOB read, redo and readwrite models 10 times each with 8, 16, and 32 sessions on EXT3 vs EXT4
  29. #   Used a tablespace on EXT3 for EXT3 testing and a tablespace on EXT4 for EXT4 testing
  30. #   Used redo logs on EXT3 for EXT3 REDO testing and redo logs on EXT4 for EXT4 REDO testing
  31. #   Ran SLOB/misc/awr_info.sh on all awr.txt reports generated from these 60 SLOB runs
  32. #   Saved awr_info.sh output as filename "awrinfo"
  33. #
  34. #  (Start R)
  35. #  > source("SLOB.R")
  36. #  > SLOB <- loadSLOB("awrinfo")
  37. #  > SLOB.sesscounts < c(8, 16, 32)            # Specify the number of sessions used in tests
  38. #  > SLOB.read.vars <- c('EXT3', 'EXT4')       # Specify the variables for READ testing: EXT3 vs EXT4
  39. #  > SLOB.redo.vars <- SLOB.read.vars          # Same variables for REDO testing as for READ testing
  40. #  > SLOB.readwrite.vars <- SLOB.read.vars     # Same variables for READWRITEtesting as for READ testing
  41. #  > SLOB.reads <- SLOBreads(SLOB, SLOB.reads.vars, SLOB.sesscounts)
  42. #  > SLOB.redo <- SLOBredo(SLOB, SLOB.redo.vars, SLOB.sesscounts)
  43. #  > SLOB.readwrite <- SLOBreadwrite(SLOB, SLOB.readwrite.vars, SLOB.sesscounts)
  44. ### Previous three lines populate SLOB.reads, SLOB.redo and SLOB.readwrite variables with AWR results
  45. ### You can then interrogate those variables by typing their names
  46. # > SLOB.reads
  47. #             8       16       32  Overall
  48. # XFS  27223.89 46248.05 61667.21 44886.22
  49. # EXT3 30076.77 49302.59 59113.00 46094.39
  50. #
  51. #
  52. # Usage variants for more detailed investigation.  Consider this advanced usage.
  53. #   Most people should just use SLOBreads(), SLOBredo() and SLOBreadwrite()
  54. #
  55. #
  56. #   Get average REDO bytes for variable 'foo' across all sessions:
  57. #     avg(SLOB, 'REDO', 'foo')
  58. #     redoavg(SLOB, 'foo')
  59. #
  60. #   Get average REDO bytes for variable 'foo' with 8 sessions:
  61. #     avg(SLOB, 'REDO', 'foo', 8)
  62. #     redoavg(SLOB, 'foo', 8)
  63. #
  64. #   Get average PREADS (physical read) for variable 'foo' across all sessions:
  65. #     avg(SLOB, 'READS', 'foo')
  66. #     readavg(SLOB, 'foo')
  67. #
  68. #   Get average PWRITES (physical writes) for variable 'foo' with 16 sessions:
  69. #     avg(SLOB, 'WRITES', 'foo', 16)
  70. #     writeavg(SLOB, 'foo', 16)
  71. #
  72. #   Get sum of PREADS and PWRITES for variable 'foo' with 32 sessions:
  73. #     avg(SLOB, 'READWRITE', 'foo', 32)
  74. #     readwriteavg(SLOB, 'foo', 32)
  75. #
  76. #   Get average REDO bytes for multiple variables ('foo' and 'bar') across all sessions:
  77. #     sapply(c('foo', 'bar'), redoavg, dat=SLOB)
  78. #       or for 16 sessions:
  79. #     sapply(c('foo', 'bar'), redoavg, dat=SLOB, sessioncount=16)
  80. #     alternate:   sapply(c('foo', 'bar'), avg, dat=SLOB, sessioncount=16, model='READS')
  81. #     (Note: This returns separate results for each variable, it does not combine and average them)
  82. #
  83. #   Get sum of PREADS and PWRITES for multiple variables ('XFS' and 'EXT3') across 16 sessions:
  84. #     sapply(c('XFS', 'EXT3'), avg, dat=SLOB, sessioncount=16, model='READWRITE')
  85. #
  86. #   View the top waits in XFS READ model with 16 sessions:
  87. #     waits(SLOB, str='XFS', model='READS', sessioncount=16)
  88. #
  89. #   View all data for a particular model with a specific session count:
  90. #     SLOB[intersect(REDO(SLOB), sessions(16, SLOB)),]
  91. #
  92. #
  93.  
  94.  
  95. getruns <- function(dat, model, str, sessioncount) {
  96.   tmp <- intersect(grep(str, dat$FILE), eval(parse(text=paste(model, '(dat)', sep=''))))          
  97.   if(missing(sessioncount)) { return(tmp)}
  98.   else { intersect(tmp, sessions(sessioncount, dat))}
  99. }
  100.  
  101. loadSLOB <- function(filename) {
  102.   read.table(file=filename, sep="|", header=TRUE)
  103. }
  104.  
  105. # heuristically identify REDO model runs - if this sucks for you, comment it out
  106. # and uncomment the alternate REDO function below.  It expects your filenames to include
  107. # the string '-REDO-' when testing REDO performance.
  108. REDO <- function(dat) {
  109.   setdiff(which(dat$REDO/(dat$PWRITES*8192) > 2), READS(dat))
  110. }
  111.  
  112. #REDO <- function(dat) {
  113. #  grep('-REDO-', dat$FILE)
  114. #}
  115.  
  116. WRITES <- function(dat) {
  117.   setdiff(which(dat$WRITERS > 0), REDO(dat))
  118. }
  119.  
  120. READS <- function(dat) {
  121.   which(dat$READERS > 0)
  122. }
  123.  
  124. READWRITE <- function(dat) {
  125.   WRITES(dat)
  126. }
  127.  
  128. sessions <- function(n, dat) {
  129.   union(which(dat$WRITERS == n), which(dat$READERS == n))
  130. }
  131.  
  132. myavg <- function(z) {
  133.   mean(z[!z %in% c(min(z), max(z))])
  134. }
  135.  
  136. getavg <- function(mode, dat) {
  137.    myavg(eval(parse(text=paste('dat$', mode, sep=''))))
  138. }
  139.  
  140. redoavg <- function(dat, ...) {
  141.   getavg('REDO', dat[getruns(dat, 'REDO', ...),])
  142. }
  143.  
  144. readavg <- function(dat, ...) {
  145.   getavg('PREADS', dat[getruns(dat, 'READS', ...),])
  146. }
  147.  
  148. writeavg <- function(dat, ...) {
  149.   getavg('PWRITES', dat[getruns(dat, 'WRITES', ...),])
  150. }
  151.  
  152. readwriteavg <- function(dat, ...) {
  153.   getavg('PWRITES', dat[getruns(dat, 'WRITES', ...),]) + getavg('PREADS', dat[getruns(dat, 'WRITES', ...),])
  154. }
  155.  
  156. avg <- function(dat, model, ...) {
  157.   if(model=='REDO') {
  158.     getavg('REDO', dat[getruns(dat, 'REDO', ...),])
  159.   } else if(model=='READS') {
  160.     getavg('PREADS', dat[getruns(dat, 'READS', ...),])
  161.   } else if (model=='WRITES') {
  162.     getavg('PWRITES', dat[getruns(dat, 'WRITES', ...),])
  163.   } else if (model=='READWRITE') {
  164.     getavg('PWRITES', dat[getruns(dat, 'WRITES', ...),]) + getavg('PREADS', dat[getruns(dat, 'WRITES', ...),])
  165.   }
  166. }
  167.  
  168. waits <- function(dat, ...) {
  169.   as.character(dat[getruns(dat, ...), 'TOP.WAIT'])
  170. }
  171.  
  172. testdata <- function(dat, model, str, ...) {
  173.   if(model=='REDO') {
  174.     sapply(str, avg, dat=dat, model='REDO', ...)
  175.   } else if(model=='READS') {
  176.     sapply(str, avg, dat=dat, model='READS', ...)
  177.   } else if(model=='WRITES') {
  178.     sapply(str, avg, dat=dat, model='WRITES', ...)
  179.   } else if (model=='READWRITE') {
  180.     sapply(str, avg, dat=dat, model='READWRITE', ...)
  181.   }
  182. }
  183.  
  184. readdata <- function(dat, str, ...) {
  185.   sapply(str, avg, dat=dat, model='READS', ...)
  186. }
  187.  
  188. redodata <- function(dat, str, ...) {
  189.   sapply(str, avg, dat=dat, model='REDO', ...)
  190. }
  191.  
  192. readwritedata <- function(dat, str, ...) {
  193.   sapply(str, avg, dat=dat, model='READWRITE', ...)
  194. }
  195.  
  196. SLOBreads <- function(dat, strs, sessioncounts) {
  197.   z <- data.frame()
  198.   for(i in sessioncounts) {
  199.     z <- rbind(z, readdata(dat, strs, i))
  200.   }
  201.   z <- rbind(z, readdata(dat, strs))
  202.   z <- t(z)
  203.   colnames(z) <- c(sessioncounts, 'Overall')
  204.   rownames(z) <- strs
  205.   return(z)
  206. }
  207.  
  208. SLOBredo <- function(dat, strs, sessioncounts) {
  209.   z <- data.frame()
  210.   for(i in sessioncounts) {
  211.     z <- rbind(z, redodata(dat, strs, i))
  212.   }
  213.   z <- rbind(z, redodata(dat, strs))
  214.   z <- t(z)
  215.   colnames(z) <- c(sessioncounts, 'Overall')
  216.   rownames(z) <- strs
  217.   return(z)
  218. }
  219.  
  220. SLOBreadwrite <- function(dat, strs, sessioncounts) {
  221.   z <- data.frame()
  222.   for(i in sessioncounts) {
  223.     z <- rbind(z, readwritedata(dat, strs, i))
  224.   }
  225.   z <- rbind(z, readwritedata(dat, strs))
  226.   z <- t(z)
  227.   colnames(z) <- c(sessioncounts, 'Overall')
  228.   rownames(z) <- strs
  229.   return(z)
  230. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement