Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- while (select count(*) from @temp_machine_events where processed = 0) > 0
- begin
- 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
- from @temp_machine_events
- where processed = 0 order by [time] asc
- select @prev_machine_event_time = prev_machine_event_time, @cpu_request_total = prev_cpu_request_total,@memory_request_total = prev_memory_request_total
- from @temp_machine_event_time
- where machine_id = @machine_id
- if (@machine_event_type = 0 )
- begin
- set @time_last_added_happened = @actual_machine_event_time
- end
- else if (@machine_event_type = 1 )
- begin
- set @time_last_failure_happen = @actual_machine_event_time
- set @failure_total = @failure_total + 1
- set @total_uptime = @total_uptime + (@time_last_failure_happen - @time_last_added_happened)
- set @MTBF = @total_uptime/@failure_total
- end
- declare @temp_machine_events table
- (
- [time] bigint not null,
- machine_id bigint,
- event_type int,
- cpu float,
- memory float,
- processed int
- )
- declare @max_task_time bigint
- select @max_task_time = max([time]) from failed_hosts_task_events
- insert into @temp_machine_events
- select [time], machine_id, event_type, cpu, memory, 0 as processed from [failure_host_machine_events_test]
- order by [time]
- insert into @temp_machine_events
- select @max_task_time, t.machine_id, t.event_type, t.cpu, t.memory, 0 as processed from @temp_machine_events as t
- inner join
- (
- select machine_id, max([time]) as [time] from @temp_machine_events group by machine_id
- ) as t_in on t.machine_id = t_in.machine_id and t.[time] = t_in.[time]
- declare @temp_machine_event_time table
- (
- machine_id bigint,
- prev_machine_event_time bigint,
- prev_cpu_request_total float,
- prev_memory_request_total float,
- prev_total_uptime float
- )
- insert into @temp_machine_event_time
- 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
- from failure_host_machine_events_test group by machine_id
- declare @prev_machine_event_time bigint
- declare @actual_machine_event_time bigint
- declare @machine_id bigint
- declare @machine_event_type int
- declare @host_available_cpu float
- declare @host_available_memory float
- declare @temp_task_events table
- (
- [time] bigint not null,
- job_id bigint,
- task_index int,
- machine_id bigint,
- event_type int,
- cpu_request float,
- memory_request float,
- cpu_request_total float,
- memory_request_total float,
- cpu_over_rate float,
- memory_over_rate float,
- host_cpu_capacity float,
- host_memory_capacity float,
- time_last_failure_happen float,
- time_last_added_happen float,
- failure_total int,
- total_uptime float,
- MTBF float,
- processed int
- )
- declare @task_event_time bigint
- declare @task_event_type int
- declare @job_id bigint
- declare @task_index int
- declare @cpu_request float
- declare @memory_request float
- declare @cpu_request_prev float
- declare @memory_request_prev float
- declare @cpu_request_total float
- declare @memory_request_total float
- declare @host_cpu_total float
- declare @host_memory_total float
- declare @time_last_failure_happen float
- declare @time_last_added_happened float
- declare @time_last_failure_happen_prev float
- declare @time_last_added_happen_prev float
- declare @failure_total float
- declare @failure_total_prev float
- declare @total_uptime float
- declare @MTBF float
- set @time_last_failure_happen = 0
- set @time_last_added_happened = 0
- set @failure_total = 0
- set @total_uptime = 0
- set @MTBF = 0
- while (select count(*) from @temp_machine_events where processed = 0) > 0
- begin
- 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
- from @temp_machine_events
- where processed = 0 order by [time] asc
- select @prev_machine_event_time = prev_machine_event_time, @cpu_request_total = prev_cpu_request_total,@memory_request_total = prev_memory_request_total
- from @temp_machine_event_time
- where machine_id = @machine_id
- if (@machine_event_type = 0 )
- begin
- set @time_last_added_happened = @actual_machine_event_time
- end
- else if (@machine_event_type = 1 )
- begin
- set @time_last_failure_happen = @actual_machine_event_time
- set @failure_total = @failure_total + 1
- set @total_uptime = @total_uptime + (@time_last_failure_happen - @time_last_added_happened)
- set @MTBF = @total_uptime/@failure_total
- end
- insert into @temp_task_events
- select
- 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,
- time_last_failure_happen = @time_last_failure_happen,time_last_added_happened= @time_last_added_happened,
- failure_total = @failure_total,total_uptime =@total_uptime, MTBF=@MTBF, 0 as processed
- from failed_hosts_task_events as te
- 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
- group by te.[time]
- while (select count(*) from @temp_task_events where processed = 0) > 0
- begin
- select top 1 @task_event_time = [time], @job_id = job_id, @task_index = task_index, @task_event_type=event_type,
- @cpu_request=cpu_request, @memory_request=memory_request from @temp_task_events where processed = 0 order by [time] asc
- if @task_event_type = 1
- begin
- set @cpu_request_total = @cpu_request_total + @cpu_request
- set @memory_request_total = @memory_request_total + @memory_request
- end
- else if @task_event_type = 8
- begin
- select * from @temp_task_events
- 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
- set @cpu_request_total = @cpu_request_total + (@cpu_request - @cpu_request_prev)
- set @memory_request_total = @memory_request_total + (@memory_request - @memory_request_prev)
- end
- else
- begin
- set @cpu_request_total = @cpu_request_total - @cpu_request
- set @memory_request_total = @memory_request_total - @memory_request
- end
- update @temp_task_events set processed = 1 where [time] = @task_event_time and machine_id=@machine_id
- update @temp_task_events set MTBF = @MTBF where [time] = @task_event_time and machine_id=@machine_id
- update @temp_task_events set processed = 1 where [time] = @task_event_time and machine_id=@machine_id
- update @temp_task_events set cpu_request_total = @cpu_request_total where [time] = @task_event_time and machine_id=@machine_id
- update @temp_task_events set memory_request_total = @memory_request_total where [time] = @task_event_time and machine_id=@machine_id
- update @temp_task_events set cpu_over_rate = @cpu_request_total/@host_available_cpu where [time] = @task_event_time and machine_id=@machine_id
- update @temp_task_events set memory_over_rate = @memory_request_total/@host_available_memory where [time] = @task_event_time and machine_id=@machine_id
- update @temp_task_events set host_cpu_capacity = @host_available_cpu where [time] = @task_event_time and machine_id=@machine_id
- update @temp_task_events set host_memory_capacity = @host_available_memory where [time] = @task_event_time and machine_id=@machine_id
- end
- update @temp_machine_events set processed = 1 where machine_id = @machine_id and [time] = @actual_machine_event_time
- 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
- insert into overbookingandFailure_rates
- select [time], machine_id, event_type, cpu_request, memory_request, cpu_over_rate, memory_over_rate, cpu_request_total,
- memory_request_total, host_cpu_capacity, host_memory_capacity,MTBF from @temp_task_events
- delete from @temp_task_events
- --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
- end
Add Comment
Please, Sign In to add comment