Guest User

Untitled

a guest
Dec 15th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.75 KB | None | 0 0
  1. while (select count(*) from @temp_machine_events where processed = 0) > 0
  2. begin
  3. select top 1 @actual_machine_event_time=[time], @machine_id = machine_id, @machine_event_type=event_type, @host_available_cpu = cpu, @host_available_memory=memory
  4. from @temp_machine_events
  5. where processed = 0 order by [time] asc
  6.  
  7. select @prev_machine_event_time = prev_machine_event_time, @cpu_request_total = prev_cpu_request_total,@memory_request_total = prev_memory_request_total
  8. from @temp_machine_event_time
  9. where machine_id = @machine_id
  10.  
  11. if (@machine_event_type = 0 )
  12. begin
  13. set @time_last_added_happened = @actual_machine_event_time
  14. end
  15. else if (@machine_event_type = 1 )
  16. begin
  17. set @time_last_failure_happen = @actual_machine_event_time
  18. set @failure_total = @failure_total + 1
  19. set @total_uptime = @total_uptime + (@time_last_failure_happen - @time_last_added_happened)
  20. set @MTBF = @total_uptime/@failure_total
  21. end
  22.  
  23. declare @temp_machine_events table
  24. (
  25. [time] bigint not null,
  26. machine_id bigint,
  27. event_type int,
  28. cpu float,
  29. memory float,
  30. processed int
  31. )
  32.  
  33. declare @max_task_time bigint
  34. select @max_task_time = max([time]) from failed_hosts_task_events
  35.  
  36. insert into @temp_machine_events
  37.  
  38. select [time], machine_id, event_type, cpu, memory, 0 as processed from [failure_host_machine_events_test]
  39.  
  40. order by [time]
  41.  
  42.  
  43. insert into @temp_machine_events
  44. select @max_task_time, t.machine_id, t.event_type, t.cpu, t.memory, 0 as processed from @temp_machine_events as t
  45. inner join
  46. (
  47. select machine_id, max([time]) as [time] from @temp_machine_events group by machine_id
  48. ) as t_in on t.machine_id = t_in.machine_id and t.[time] = t_in.[time]
  49.  
  50. declare @temp_machine_event_time table
  51. (
  52. machine_id bigint,
  53. prev_machine_event_time bigint,
  54. prev_cpu_request_total float,
  55. prev_memory_request_total float,
  56. prev_total_uptime float
  57. )
  58.  
  59. insert into @temp_machine_event_time
  60. select machine_id, -1 as prev_machine_event_time, 0 as prev_cpu_request_total, 0 as prev_memory_request_total,0 as prev_total_uptime
  61. from failure_host_machine_events_test group by machine_id
  62.  
  63. declare @prev_machine_event_time bigint
  64. declare @actual_machine_event_time bigint
  65.  
  66. declare @machine_id bigint
  67. declare @machine_event_type int
  68. declare @host_available_cpu float
  69. declare @host_available_memory float
  70.  
  71. declare @temp_task_events table
  72. (
  73. [time] bigint not null,
  74. job_id bigint,
  75. task_index int,
  76. machine_id bigint,
  77. event_type int,
  78. cpu_request float,
  79. memory_request float,
  80. cpu_request_total float,
  81. memory_request_total float,
  82. cpu_over_rate float,
  83. memory_over_rate float,
  84. host_cpu_capacity float,
  85. host_memory_capacity float,
  86. time_last_failure_happen float,
  87. time_last_added_happen float,
  88. failure_total int,
  89. total_uptime float,
  90. MTBF float,
  91. processed int
  92. )
  93.  
  94. declare @task_event_time bigint
  95. declare @task_event_type int
  96. declare @job_id bigint
  97. declare @task_index int
  98. declare @cpu_request float
  99. declare @memory_request float
  100. declare @cpu_request_prev float
  101. declare @memory_request_prev float
  102. declare @cpu_request_total float
  103. declare @memory_request_total float
  104. declare @host_cpu_total float
  105. declare @host_memory_total float
  106. declare @time_last_failure_happen float
  107. declare @time_last_added_happened float
  108. declare @time_last_failure_happen_prev float
  109. declare @time_last_added_happen_prev float
  110. declare @failure_total float
  111. declare @failure_total_prev float
  112. declare @total_uptime float
  113. declare @MTBF float
  114.  
  115. set @time_last_failure_happen = 0
  116. set @time_last_added_happened = 0
  117. set @failure_total = 0
  118. set @total_uptime = 0
  119. set @MTBF = 0
  120.  
  121. while (select count(*) from @temp_machine_events where processed = 0) > 0
  122. begin
  123. select top 1 @actual_machine_event_time=[time], @machine_id = machine_id, @machine_event_type=event_type, @host_available_cpu = cpu, @host_available_memory=memory
  124. from @temp_machine_events
  125. where processed = 0 order by [time] asc
  126.  
  127. select @prev_machine_event_time = prev_machine_event_time, @cpu_request_total = prev_cpu_request_total,@memory_request_total = prev_memory_request_total
  128. from @temp_machine_event_time
  129. where machine_id = @machine_id
  130.  
  131.  
  132.  
  133. if (@machine_event_type = 0 )
  134. begin
  135. set @time_last_added_happened = @actual_machine_event_time
  136. end
  137. else if (@machine_event_type = 1 )
  138. begin
  139. set @time_last_failure_happen = @actual_machine_event_time
  140. set @failure_total = @failure_total + 1
  141. set @total_uptime = @total_uptime + (@time_last_failure_happen - @time_last_added_happened)
  142. set @MTBF = @total_uptime/@failure_total
  143. end
  144.  
  145. insert into @temp_task_events
  146. select
  147. te.[time], min(job_id), min(task_index), min(machine_id), max(te.event_type), sum(cpu_request) as cpu_request, sum(memory_request) as memory_request, 0 as cpu_request_total, 0 as memory_request_total, 0 as cpu_over_rate, 0 as memory_over_rate, 0 as host_cpu_capacity, 0 as host_memory_capacity,
  148. time_last_failure_happen = @time_last_failure_happen,time_last_added_happened= @time_last_added_happened,
  149. failure_total = @failure_total,total_uptime =@total_uptime, MTBF=@MTBF, 0 as processed
  150. from failed_hosts_task_events as te
  151.  
  152. where te.machine_id = @machine_id and te.event_type!=0 and te.[time] > @prev_machine_event_time and te.[time] <= @actual_machine_event_time
  153. group by te.[time]
  154.  
  155. while (select count(*) from @temp_task_events where processed = 0) > 0
  156. begin
  157. select top 1 @task_event_time = [time], @job_id = job_id, @task_index = task_index, @task_event_type=event_type,
  158. @cpu_request=cpu_request, @memory_request=memory_request from @temp_task_events where processed = 0 order by [time] asc
  159.  
  160.  
  161.  
  162. if @task_event_type = 1
  163. begin
  164. set @cpu_request_total = @cpu_request_total + @cpu_request
  165. set @memory_request_total = @memory_request_total + @memory_request
  166. end
  167. else if @task_event_type = 8
  168. begin
  169. select * from @temp_task_events
  170. select top 1 @cpu_request_prev = cpu_request, @memory_request_prev = memory_request from failed_hosts_task_events where [time]<@task_event_time and job_id=@job_id and task_index=@task_index and event_type in (1,8) order by [time] desc
  171.  
  172. set @cpu_request_total = @cpu_request_total + (@cpu_request - @cpu_request_prev)
  173. set @memory_request_total = @memory_request_total + (@memory_request - @memory_request_prev)
  174. end
  175. else
  176. begin
  177. set @cpu_request_total = @cpu_request_total - @cpu_request
  178. set @memory_request_total = @memory_request_total - @memory_request
  179. end
  180.  
  181.  
  182. update @temp_task_events set processed = 1 where [time] = @task_event_time and machine_id=@machine_id
  183.  
  184.  
  185. update @temp_task_events set MTBF = @MTBF where [time] = @task_event_time and machine_id=@machine_id
  186.  
  187. update @temp_task_events set processed = 1 where [time] = @task_event_time and machine_id=@machine_id
  188. update @temp_task_events set cpu_request_total = @cpu_request_total where [time] = @task_event_time and machine_id=@machine_id
  189. update @temp_task_events set memory_request_total = @memory_request_total where [time] = @task_event_time and machine_id=@machine_id
  190. update @temp_task_events set cpu_over_rate = @cpu_request_total/@host_available_cpu where [time] = @task_event_time and machine_id=@machine_id
  191. update @temp_task_events set memory_over_rate = @memory_request_total/@host_available_memory where [time] = @task_event_time and machine_id=@machine_id
  192. update @temp_task_events set host_cpu_capacity = @host_available_cpu where [time] = @task_event_time and machine_id=@machine_id
  193. update @temp_task_events set host_memory_capacity = @host_available_memory where [time] = @task_event_time and machine_id=@machine_id
  194.  
  195. end
  196.  
  197. update @temp_machine_events set processed = 1 where machine_id = @machine_id and [time] = @actual_machine_event_time
  198. update @temp_machine_event_time set prev_machine_event_time = @actual_machine_event_time, prev_cpu_request_total = @cpu_request_total, prev_memory_request_total = @memory_request_total where machine_id = @machine_id
  199.  
  200. insert into overbookingandFailure_rates
  201. select [time], machine_id, event_type, cpu_request, memory_request, cpu_over_rate, memory_over_rate, cpu_request_total,
  202. memory_request_total, host_cpu_capacity, host_memory_capacity,MTBF from @temp_task_events
  203.  
  204. delete from @temp_task_events
  205. --select [time], machine_id, cpu_over_rate ,MTBF,total_uptime,failure_total,time_last_failure_happen,time_last_added_happen,MTBF from @temp_task_events
  206. end
Add Comment
Please, Sign In to add comment