forked from ik2sb/PICS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sim_entity_cloudbroker.py
executable file
·3923 lines (2893 loc) · 182 KB
/
sim_entity_cloudbroker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import os
import sys
import time
import logging
import random
from threading import Condition
import inspect
import math
import numpy as np
from operator import itemgetter
import sim_global_variables as simgval
import sim_lib_common as clib
import sim_object as simobj
import sim_lib_regression as reg
import sim_lib_timeseries as ts
import sim_entity_iaas as iaas
Global_Curr_Sim_Clock = -99
Global_Curr_Sim_Clock_CV = Condition()
g_flag_sim_entity_term = False # Sim Entity (Thread) Termination Flag
g_flag_sim_entity_term_CV = Condition()
g_my_block_id = None # global var for current block id
g_log_handler = None # global var for log handler
g_job_recv_log_handler = None # global var for job recv log handler
g_job_comp_log_handler = None # global var for job comp log handler
g_sim_trace_log_handler = None # global var for sim trace log handler
g_sim_conf = None
gQ_OUT = None # global var for q_out to event handler
g_job_logs = [0,0,0,0] # job log [0] : Recv (Cumm), Recv (Unit), Comp (Cumm), Comp (Unit)
g_job_logs_cv = Condition()
g_last_job_arrival_clock = 0
g_Job_Arrival_Rate = []
g_Job_Arrival_Rate_CV = Condition()
g_Received_Jobs = []
g_Received_Jobs_CV = Condition()
g_Completed_Jobs = []
g_Completed_Jobs_CV = Condition()
# Running VM List (including creating)
g_Running_VM_Instances = []
g_Running_VM_Instances_CV = Condition()
# Stopped VM List
g_Stopped_VM_Instances = []
g_Stopped_VM_Instances_CV = Condition()
# Temporary VM List
g_Temp_VM_Instances = []
g_Temp_VM_Instances_CV = Condition()
g_Startup_Lags = []
g_Startup_Lags_CV = Condition()
# Related to Logs
def set_log (path):
logger = logging.getLogger('cloud_broker')
log_file = path + '/[' + str(g_my_block_id) + ']-cloud_broker.log'
# for log file write...
hdlr = logging.FileHandler(log_file)
formatter = logging.Formatter('%(message)s')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
# for stdout...
ch = logging.StreamHandler(sys.stdout)
formatter = logging.Formatter('%(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
logger.setLevel(logging.INFO)
return logger
def set_job_recv_log (path):
logger = logging.getLogger('job_rev_log')
log_file = path + '/[' + str(g_my_block_id) + ']-job_recv_list.log'
hdlr = logging.FileHandler(log_file)
#hdlr = logging.FileHandler(path + '/job_recv_list.log')
formatter = logging.Formatter('%(message)s')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.INFO)
return logger
def set_job_comp_log (path):
logger = logging.getLogger('job_complete_log')
log_file = path + '/[' + str(g_my_block_id) + ']-job_complete_list.log'
hdlr = logging.FileHandler(log_file)
#hdlr = logging.FileHandler(path + '/job_complete_list.log')
formatter = logging.Formatter('%(message)s')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.INFO)
return logger
def set_broker_job_report_log (path):
logger = logging.getLogger('broker_job_complete_report_log')
log_file = path + '/3.report_job_complete_report.csv'
hdlr = logging.FileHandler(log_file)
#hdlr = logging.FileHandler(path + '/job_complete_list.log')
formatter = logging.Formatter('%(message)s')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.INFO)
return logger
def set_broker_vm_report_log (path):
logger = logging.getLogger('broker_vm_complete_report_log')
log_file = path + '/4.report_vm_usage_report.csv'
hdlr = logging.FileHandler(log_file)
#hdlr = logging.FileHandler(path + '/job_complete_list.log')
formatter = logging.Formatter('%(message)s')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.INFO)
return logger
def set_broker_sim_trace_log (path):
logger = logging.getLogger('vm_job_trace_log')
log_file = path + '/1.report_simulation_trace_broker.csv'
hdlr = logging.FileHandler(log_file)
#hdlr = logging.FileHandler(path + '/job_complete_list.log')
formatter = logging.Formatter('%(message)s')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.INFO)
return logger
def set_g_job_logs (j_recv_cumm, j_recv_unit, j_comp_cumm, j_comp_unit):
global g_job_logs
g_job_logs_cv.acquire()
g_job_logs[0] += j_recv_cumm
g_job_logs[1] += j_recv_unit
g_job_logs[2] += j_comp_cumm
g_job_logs[3] += j_comp_unit
g_job_logs_cv.notify()
g_job_logs_cv.release()
def clear_g_job_logs_unit ():
global g_job_logs
g_job_logs_cv.acquire()
g_job_logs[1] = 0
g_job_logs[3] = 0
g_job_logs_cv.notify()
g_job_logs_cv.release()
def set_broker_sim_entity_term_flag (val):
global g_flag_sim_entity_term
if val is not True and val is not False:
return
if g_flag_sim_entity_term == val:
return
g_flag_sim_entity_term_CV.acquire()
g_flag_sim_entity_term = val
g_flag_sim_entity_term_CV.notify()
g_flag_sim_entity_term_CV.release()
def write_job_complete_log (job):
if job.status != simgval.gJOB_ST_COMPLETED and job.status != simgval.gJOB_ST_FAILED:
clib.display_job_obj(Global_Curr_Sim_Clock, job)
clib.sim_exit()
return
total_duration = job.time_complete - job.time_create
run_time = job.time_complete - job.time_start
diff = job.deadline - total_duration
#job_comp_log.info ('CL\tID\tJN\tADR\tIN\tCPU\tOUT\tDL\tVM\tTG\tTA\tTS\tTC\tTD\tRT\tDF\tST')
g_job_comp_log_handler.info ('%d\t%d\t%s\t%d\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%s' %
(Global_Curr_Sim_Clock, job.id, job.name, job.act_duration_on_VM, job.act_nettime_on_VM[0], job.act_cputime_on_VM, job.act_nettime_on_VM[1], job.deadline, job.VM_id,
job.time_create, job.time_assign, job.time_start, job.time_complete,
total_duration, run_time, diff, simgval.get_sim_code_str(job.status)))
# Related to Job Arrival Rate
def insert_job_arrival_rate (clock):
global g_last_job_arrival_clock
global g_Job_Arrival_Rate
arrival_interval = 0
g_Job_Arrival_Rate_CV.acquire()
if len(g_Job_Arrival_Rate) > 0:
arrival_interval = clock - g_last_job_arrival_clock
else:
arrival_interval = clock
g_last_job_arrival_clock = clock
g_Job_Arrival_Rate.append(arrival_interval)
g_Job_Arrival_Rate_CV.notify()
g_Job_Arrival_Rate_CV.release()
def get_mean_job_arrival_rate ():
return int(math.ceil(np.mean(g_Job_Arrival_Rate)))
def get_max_job_arrival_rate ():
return max (g_Job_Arrival_Rate)
def get_recent_sample_cnt ():
return g_sim_conf.vm_scale_down_policy_recent_sample_cnt
def get_alpha_ma ():
return float(g_sim_conf.vm_scale_down_policy_param1)
def get_beta_ma ():
return float(g_sim_conf.vm_scale_down_policy_param2)
def get_AR_order ():
return int(g_sim_conf.vm_scale_down_policy_param1)
def get_MA_order ():
return int(g_sim_conf.vm_scale_down_policy_param2)
def get_DF_order ():
return int(g_sim_conf.vm_scale_down_policy_param3)
def get_recent_n_job_arrival_list (cnt):
index = -cnt
return g_Job_Arrival_Rate[index:]
def get_mean_recent_n_job_arrival_rate (cnt):
n_recents = get_recent_n_job_arrival_list (cnt)
return int(math.ceil(np.mean(n_recents)))
def get_max_recent_n_job_arrival_rate (cnt):
n_recents = get_recent_n_job_arrival_list (cnt)
return max (n_recents)
# Related to Jobs
def create_Job_Object (job_evt):
job_uid = simobj.generate_JOB_UID()
job = simobj.Job (job_uid, job_evt, Global_Curr_Sim_Clock)
return job
def insert_job_into_ReceivedJobList (job):
global g_Received_Jobs
global g_Received_Jobs_CV
g_Received_Jobs_CV.acquire()
g_Received_Jobs.append (job)
g_Received_Jobs_CV.notify()
g_Received_Jobs_CV.release()
def get_job_from_ReceivedJobList_by_JobID (job_id):
global g_Received_Jobs
global g_Received_Jobs_CV
for j in g_Received_Jobs:
if j.id == job_id:
return j
return None
def get_job_from_ReceivedJobList (job_id, vm_id):
global g_Received_Jobs
global g_Received_Jobs_CV
job_index = -1
job = None
for j in g_Received_Jobs:
if j.id == job_id and j.VM_id == vm_id:
job_index = g_Received_Jobs.index(j)
break
if job_index > -1:
g_Received_Jobs_CV.acquire()
job = g_Received_Jobs.pop(job_index)
g_Received_Jobs_CV.notify()
g_Received_Jobs_CV.release()
return job
def insert_job_into_CompletedJobList (job):
global g_Completed_Jobs
global g_Completed_Jobs_CV
g_Completed_Jobs_CV.acquire()
g_Completed_Jobs.append (job)
g_Completed_Jobs_CV.notify()
g_Completed_Jobs_CV.release()
# Related to VMs
def get_detailed_number_of_VM_status ():
vm_run = get_number_Running_VM_Instances ()
vm_act = 0
vm_stup = 0
for vm in g_Running_VM_Instances:
if vm.status == simgval.gVM_ST_CREATING:
vm_stup += 1
elif vm.status == simgval.gVM_ST_ACTIVE:
vm_act += 1
else:
g_log_handler.error('[Broker__] %s VM Status (%s) Error in g_Running_VM_Instances' % (Global_Curr_Sim_Clock, vm.id, simgval.get_sim_code_str(vm.status)))
clib.logwrite_VM_Instance_Lists (g_log_handler, "[Broker__] " + str(Global_Curr_Sim_Clock), "Error g_Running_VM_Instances", g_Running_VM_Instances)
clib.sim_exit()
vm_stop = len(g_Stopped_VM_Instances)
return vm_run, vm_stup, vm_act, vm_stop
# this is only for simulation trace...
def get_vm_current_total_cost ():
vm_total_cost = 0
for v in g_Running_VM_Instances:
vm_running_time = Global_Curr_Sim_Clock - v.time_create
vm_cost, _ = iaas.get_vm_cost_and_billing_hour (vm_running_time, v.unit_price)
vm_total_cost += vm_cost
for v in g_Stopped_VM_Instances:
vm_running_time = simobj.get_vm_billing_clock (v)
vm_cost, _ = iaas.get_vm_cost_and_billing_hour (vm_running_time, v.unit_price)
vm_total_cost += vm_cost
for v in g_Temp_VM_Instances:
vm_running_time = Global_Curr_Sim_Clock - vm.time_create
vm_cost, _ = iaas.get_vm_cost_and_billing_hour (vm_running_time, v.unit_price)
vm_total_cost += vm_cost
return vm_total_cost
def get_number_Running_VM_Instances ():
return len (g_Running_VM_Instances)
def get_running_VM_IDs ():
IDs = []
for v in g_Running_VM_Instances:
IDs.append(v.id)
return IDs
def get_running_VM_IDs_by_VMType (vm_type_name):
IDs = []
for v in g_Running_VM_Instances:
if v.type_name == vm_type_name:
IDs.append(v.id)
return IDs
def get_running_VM_by_VM_ID (vm_id):
for v in g_Running_VM_Instances:
if v.id == vm_id:
return v
return None
def create_new_VM_Instance (vm_type_obj, vscale_victim_id=-1):
new_vm_uid = simobj.generate_VM_UID()
new_vm = simobj.VM_Instance (new_vm_uid, "VM-" + str(new_vm_uid), vm_type_obj.vm_type_name, vm_type_obj.vm_type_unit_price, Global_Curr_Sim_Clock)
g_log_handler.info('[Broker__] %s VM Created: ID:%d, IID: %s, Type: %s, Price: $%s, Status: %s' % (Global_Curr_Sim_Clock, new_vm.id, new_vm.instance_id, new_vm.type_name, new_vm.unit_price, simgval.get_sim_code_str(new_vm.status)))
# insert the created VM into running list
if vscale_victim_id == -1: # which means normal new VM creation
insert_VM_into_Running_VM_Instances (new_vm)
g_log_handler.info('[Broker__] %s Insert VM(%d,%s,$%s,%s) into Running VM List' % (Global_Curr_Sim_Clock, new_vm.id, new_vm.type_name, new_vm.unit_price, simgval.get_sim_code_str(new_vm.status)))
else: # this means new vm creation for vertical scaling
# set vscale_victim_id --> this points out previous vm id
simobj.set_VM_vscale_victim_id(new_vm, vscale_victim_id)
insert_VM_into_Temp_VM_Instances (new_vm)
g_log_handler.info('[Broker__] %s Insert VM(%d,%s,$%s,%s) into Temp VM List' % (Global_Curr_Sim_Clock, new_vm.id, new_vm.type_name, new_vm.unit_price, simgval.get_sim_code_str(new_vm.status)))
return new_vm_uid
def insert_VM_into_Running_VM_Instances (vm):
global g_Running_VM_Instances
global g_Running_VM_Instances_CV
#curframe = inspect.currentframe()
#calframe = inspect.getouterframes(curframe, 2)
#g_log_handler.info (str(Global_Curr_Sim_Clock) + "")
#g_log_handler.info (str(Global_Curr_Sim_Clock) + " insert_VM_into_Running_VM_Instances")
#g_log_handler.info (str(Global_Curr_Sim_Clock) + "\tVM INFO : ID: %d, ST: %s" % (vm.id, simgval.get_sim_code_str(vm.status)))
#g_log_handler.info (str(Global_Curr_Sim_Clock) + "\tCaller : %s, %s:%d" % (calframe[1][3], calframe[1][1], calframe[1][2]))
#g_log_handler.info (str(Global_Curr_Sim_Clock) + "")
#clib.logwrite_VM_Instance_Lists(g_log_handler, Global_Curr_Sim_Clock, "BEFORE insert_VM_into_Running_VM_Instances", g_Running_VM_Instances)
#g_log_handler.info (str(Global_Curr_Sim_Clock) + "")
g_Running_VM_Instances_CV.acquire()
g_Running_VM_Instances.append(vm)
g_Running_VM_Instances_CV.notify()
g_Running_VM_Instances_CV.release()
#clib.logwrite_VM_Instance_Lists(g_log_handler, Global_Curr_Sim_Clock, "AFTER insert_VM_into_Running_VM_Instances", g_Running_VM_Instances)
#g_log_handler.info (str(Global_Curr_Sim_Clock) + "")
def find_VM_from_Running_VM_Instances (vm_id):
index = -1
for vm in g_Running_VM_Instances:
if vm.id == vm_id:
index = g_Running_VM_Instances.index(vm)
return True, index
return False, index
def get_VM_from_Running_VM_Instances (vm_id):
for vm in g_Running_VM_Instances:
if vm.id == vm_id:
return vm
return None
def remove_VM_from_Running_VM_Instances (vm_id):
global g_Running_VM_Instances
global g_Running_VM_Instances_CV
for vm in g_Running_VM_Instances:
if vm.id == vm_id:
#curframe = inspect.currentframe()
#calframe = inspect.getouterframes(curframe, 2)
#g_log_handler.info (str(Global_Curr_Sim_Clock) + "")
#g_log_handler.info (str(Global_Curr_Sim_Clock) + " remove_VM_from_Running_VM_Instances")
#g_log_handler.info (str(Global_Curr_Sim_Clock) + "\tVM INFO : ID: %d" % (vm.id))
#g_log_handler.info (str(Global_Curr_Sim_Clock) + "\tCaller : %s, %s:%d" % (calframe[1][3], calframe[1][1], calframe[1][2]))
#g_log_handler.info (str(Global_Curr_Sim_Clock) + "")
#clib.logwrite_VM_Instance_Lists(g_log_handler, Global_Curr_Sim_Clock, "BEFORE remove_VM_from_Running_VM_Instances", g_Running_VM_Instances)
#g_log_handler.info (str(Global_Curr_Sim_Clock) + "")
g_Running_VM_Instances_CV.acquire()
g_Running_VM_Instances.remove(vm)
g_Running_VM_Instances_CV.notify()
g_Running_VM_Instances_CV.release()
#clib.logwrite_VM_Instance_Lists(g_log_handler, Global_Curr_Sim_Clock, "AFTER remove_VM_from_Running_VM_Instances", g_Running_VM_Instances)
#g_log_handler.info (str(Global_Curr_Sim_Clock) + "")
return True
return False
def insert_VM_into_Stopped_VM_Instances (vm):
global g_Stopped_VM_Instances
global g_Stopped_VM_Instances_CV
#curframe = inspect.currentframe()
#calframe = inspect.getouterframes(curframe, 2)
#g_log_handler.info (str(Global_Curr_Sim_Clock) + "")
#g_log_handler.info (str(Global_Curr_Sim_Clock) + " insert_VM_into_Stopped_VM_Instances")
#g_log_handler.info (str(Global_Curr_Sim_Clock) + "\tVM INFO : ID: %d, ST: %s" % (vm.id, simgval.get_sim_code_str(vm.status)))
#g_log_handler.info (str(Global_Curr_Sim_Clock) + "\tCaller : %s, %s:%d" % (calframe[1][3], calframe[1][1], calframe[1][2]))
#g_log_handler.info (str(Global_Curr_Sim_Clock) + "")
#clib.logwrite_VM_Instance_Lists(g_log_handler, Global_Curr_Sim_Clock, "BEFORE insert_VM_into_Stopped_VM_Instances", g_Stopped_VM_Instances)
#g_log_handler.info (str(Global_Curr_Sim_Clock) + "")
g_Stopped_VM_Instances_CV.acquire()
g_Stopped_VM_Instances.append(vm)
g_Stopped_VM_Instances_CV.notify()
g_Stopped_VM_Instances_CV.release()
#clib.logwrite_VM_Instance_Lists(g_log_handler, Global_Curr_Sim_Clock, "AFTER insert_VM_into_Stopped_VM_Instances", g_Stopped_VM_Instances)
#g_log_handler.info (str(Global_Curr_Sim_Clock) + "")
def get_VM_from_Stopped_VM_Instances (vm_id):
for vm in g_Stopped_VM_Instances:
if vm.id == vm_id:
return vm
return None
# related to Temp_VM_Instances
def insert_VM_into_Temp_VM_Instances (vm):
global g_Temp_VM_Instances
global g_Temp_VM_Instances_CV
#curframe = inspect.currentframe()
#calframe = inspect.getouterframes(curframe, 2)
#g_log_handler.info (str(Global_Curr_Sim_Clock) + "")
#g_log_handler.info (str(Global_Curr_Sim_Clock) + " insert_VM_into_Temp_VM_Instances")
#g_log_handler.info (str(Global_Curr_Sim_Clock) + "\tVM INFO : ID: %d, ST: %s" % (vm.id, simgval.get_sim_code_str(vm.status)))
#g_log_handler.info (str(Global_Curr_Sim_Clock) + "\tCaller : %s, %s:%d" % (calframe[1][3], calframe[1][1], calframe[1][2]))
#g_log_handler.info (str(Global_Curr_Sim_Clock) + "")
#clib.logwrite_VM_Instance_Lists(g_log_handler, Global_Curr_Sim_Clock, "BEFORE insert_VM_into_Temp_VM_Instances", g_Temp_VM_Instances)
#g_log_handler.info (str(Global_Curr_Sim_Clock) + "")
g_Temp_VM_Instances_CV.acquire()
g_Temp_VM_Instances.append(vm)
g_Temp_VM_Instances_CV.notify()
g_Temp_VM_Instances_CV.release()
#clib.logwrite_VM_Instance_Lists(g_log_handler, Global_Curr_Sim_Clock, "AFTER insert_VM_into_Temp_VM_Instances", g_Temp_VM_Instances)
#g_log_handler.info (str(Global_Curr_Sim_Clock) + "")
def get_VM_from_Temp_VM_Instances (vm_id):
for vm in g_Temp_VM_Instances:
if vm.id == vm_id:
return vm
return None
def remove_VM_from_Temp_VM_Instances (vm_id):
global g_Temp_VM_Instances
global g_Temp_VM_Instances_CV
for vm in g_Temp_VM_Instances:
if vm.id == vm_id:
#curframe = inspect.currentframe()
#calframe = inspect.getouterframes(curframe, 2)
#g_log_handler.info (str(Global_Curr_Sim_Clock) + "")
#g_log_handler.info (str(Global_Curr_Sim_Clock) + " remove_VM_from_Temp_VM_Instances")
#g_log_handler.info (str(Global_Curr_Sim_Clock) + "\tVM INFO : ID: %d" % (vm.id))
#g_log_handler.info (str(Global_Curr_Sim_Clock) + "\tCaller : %s, %s:%d" % (calframe[1][3], calframe[1][1], calframe[1][2]))
#g_log_handler.info (str(Global_Curr_Sim_Clock) + "")
#clib.logwrite_VM_Instance_Lists(g_log_handler, Global_Curr_Sim_Clock, "BEFORE remove_VM_from_Temp_VM_Instances", g_Temp_VM_Instances)
#g_log_handler.info (str(Global_Curr_Sim_Clock) + "")
g_Temp_VM_Instances_CV.acquire()
g_Temp_VM_Instances.remove(vm)
g_Temp_VM_Instances_CV.notify()
g_Temp_VM_Instances_CV.release()
#clib.logwrite_VM_Instance_Lists(g_log_handler, Global_Curr_Sim_Clock, "AFTER remove_VM_from_Temp_VM_Instances", g_Temp_VM_Instances)
#g_log_handler.info (str(Global_Curr_Sim_Clock) + "")
return True
return False
def insert_job_into_VM_Job_Queue (vm_id, job, is_migration=False):
if is_migration is True:
vm = get_VM_from_Temp_VM_Instances(vm_id)
else:
vm = get_VM_from_Running_VM_Instances(vm_id)
if vm is None:
job_str = simobj.get_job_info_str(job)
g_log_handler.error("[Broker__] %s VM (ID:%d) not found for %s Assignment!" % (str(Global_Curr_Sim_Clock), vm_id, job_str))
clib.logwrite_VM_Instance_Lists (g_log_handler, "[Broker__] " + str(Global_Curr_Sim_Clock), "Current g_Running_VM_Instances", g_Running_VM_Instances)
clib.sim_exit()
simobj.insert_job_into_VM_job_queue (vm, job)
simobj.set_Job_status (job, simgval.gJOB_ST_ASSIGNED)
simobj.set_Job_time_assign (job, Global_Curr_Sim_Clock)
simobj.set_Job_VM_info (job, vm.id, vm.type_name)
def get_VM_sd_policy_activated (vm_id):
vm = get_VM_from_Running_VM_Instances(vm_id)
if vm is None:
g_log_handler.error ("[Broker__] %s VM (ID:%d) not found in current running VM List" % (str(Global_Curr_Sim_Clock), vm_id))
clib.logwrite_VM_Instance_Lists (g_log_handler, "[Broker__] " + str(Global_Curr_Sim_Clock), "Current g_Running_VM_Instances", g_Running_VM_Instances)
clib.sim_exit()
return vm.sd_policy_activated
def update_VM_sd_wait_time (vm_id, wait_time):
vm = get_VM_from_Running_VM_Instances(vm_id)
if vm is None:
g_log_handler.error ("[Broker__] %s VM (ID:%d) not found in current running VM List" % (str(Global_Curr_Sim_Clock), vm_id))
clib.logwrite_VM_Instance_Lists (g_log_handler, "[Broker__] " + str(Global_Curr_Sim_Clock), "Current g_Running_VM_Instances", g_Running_VM_Instances)
clib.sim_exit()
simobj.set_VM_sd_wait_time(vm, wait_time)
def get_vm_wait_time_bounds ():
bounds = [g_sim_conf.vm_scale_down_policy_min_wait_time, g_sim_conf.vm_scale_down_policy_max_wait_time]
return bounds
def get_vm_scale_down_unit ():
return g_sim_conf.vm_scale_down_policy_unit
def get_average_startup_lagtime ():
if len(g_Startup_Lags) < 1:
return int(math.ceil((g_sim_conf.min_startup_lag + g_sim_conf.max_startup_lag)/2.0))
else:
return int(math.ceil(np.mean(g_Startup_Lags)))
def get_max_startup_lagtime ():
return int(g_sim_conf.max_startup_lag)
# Storage Simulation Debug Point - Done on 10.29.2014
def cal_estimated_job_completion_time (vm_id, job_actual_duration_infos):
# input parameters
# vm_id -- id for vm obj
# job_actual_duration_infos
# job_actual_duration[0] == total job duration on VM (including cpu + i/o)
# job_actual_duration[1] == cputime on VM
# job_actual_duration[2] == nettime on VM
vm = get_VM_from_Running_VM_Instances (vm_id)
if vm is None:
g_log_handler.error("[Broker__] %s CAL_EJCT: VM (ID:%d, TY:%s) not found!" % (str(Global_Curr_Sim_Clock), vm_id, vm.type_name))
clib.logwrite_VM_Instance_Lists (g_log_handler, "[Broker__] " + str(Global_Curr_Sim_Clock), "Current g_Running_VM_Instances", g_Running_VM_Instances)
clib.sim_exit()
# procedure
# if vm status == simgval.gVM_ST_ACTIVE
# if vm's current job is None:
# jct = sum (j[2] for j in vm.job_queue) + job_actual_duration[0]
# else (is not none)
# jct = remaining time of currnet job [duration - (current clock - vm.time_active)] + sum (j[2] for j in vm.job_queue) + job_duration
# elif vm.status == gVM_ST_CREATING
# calculate average_startup_lag = math.ceil(np.average(g_Startup_Lags)) if len(g_Startup_Lags) > 0 else math.ceil((min + max)/2)
# jct = remaining startup lag [average_startup_lag - (curr_clock - vm.time_create)] + sum (j[2] for j in vm.job_queue) + job_duration
# else: return sys.maxint
est_job_comp_time = sys.maxint
g_log_handler.info ("[Broker__] %s CAL_EJCT: VM (ID:%d, TY:%s)'s Status: %s" % (str(Global_Curr_Sim_Clock), vm.id, vm.type_name, simgval.get_sim_code_str(vm.status)))
if vm.status == simgval.gVM_ST_CREATING:
# JCT = [average_startup_lag - (curr_clock - vm.time_create)] + sum (j[2] for j in vm.job_queue) + job_duration
avg_startup_lag = get_average_startup_lagtime()
curr_running_time = Global_Curr_Sim_Clock - vm.time_create
if avg_startup_lag <= curr_running_time:
avg_startup_lag = get_max_startup_lagtime()
exe_time_q_jobs = clib.get_sum_job_actual_duration (vm.job_queue)
g_log_handler.info("[Broker__] %s\t\tCalculate Estimated Job Completion Time on VM (ID:%d,ST:%s)" % (str(Global_Curr_Sim_Clock), vm.id, simgval.get_sim_code_str(vm.status)))
g_log_handler.info("[Broker__] %s\t\tCAL_EJCT: AVG Startup Lag: %d" % (str(Global_Curr_Sim_Clock), avg_startup_lag))
g_log_handler.info("[Broker__] %s\t\tCAL_EJCT: VM(%d)'s Curr RunTime (Clock-TC): %d" % (str(Global_Curr_Sim_Clock), vm.id, curr_running_time))
g_log_handler.info("[Broker__] %s\t\tCAL_EJCT: VM(%d)'s JRT in Queue[len:%d]: %d" % (str(Global_Curr_Sim_Clock), vm.id, len(vm.job_queue), exe_time_q_jobs))
g_log_handler.info("[Broker__] %s\t\tCAL_EJCT: Recv Job Actual Duration: %s (CPU:%s, IO:%s)" % (str(Global_Curr_Sim_Clock), job_actual_duration_infos[0], job_actual_duration_infos[1], job_actual_duration_infos[2]))
# estimated job completion time
est_job_comp_time = avg_startup_lag - curr_running_time + exe_time_q_jobs + job_actual_duration_infos[0]
g_log_handler.info("[Broker__] %s\t\tCAL_EJCT: EJCT (%d) = AVG_ST_LAG (%d) - CURR_RT (%d) + JET_JQ (%d) + JR (%s - CPU:%s, IO:%s)" \
% (str(Global_Curr_Sim_Clock), est_job_comp_time, avg_startup_lag, curr_running_time, exe_time_q_jobs, job_actual_duration_infos[0], job_actual_duration_infos[1], job_actual_duration_infos[2]))
elif vm.status == simgval.gVM_ST_ACTIVE:
# vm status is active (complete startup)
exe_time_q_jobs = clib.get_sum_job_actual_duration (vm.job_queue)
if vm.current_job == None:
# current job is None (VM is Idle)
g_log_handler.info("[Broker__] %s CAL_EJCT: VM (ID:%dm, TY:%s)'s Current Job is None [CST:%d]" \
% (str(Global_Curr_Sim_Clock), vm.id, vm.type_name, vm.current_job_start_clock))
if vm.current_job_start_clock != -1:
g_log_handler.error("[Broker__] %s CAL_EJCT: VM (ID:%d, TY:%s)'s Invalid Current Job (%s) Start Time (%d)" \
% (str(Global_Curr_Sim_Clock), vm.id, vm.type_name, vm.current_job, vm.current_job_start_clock))
clib.logwrite_vm_obj(g_log_handler, "[Broker__] " + str(Global_Curr_Sim_Clock), vm)
clib.sim_exit() # 2015-03-30
# JCT = sum (j[2] for j in vm.job_queue) + job_duration
g_log_handler.info("[Broker__] %s\t\tCalculate Estimated Job Completion Time on VM (ID:%d,ST:%s)" % (str(Global_Curr_Sim_Clock), vm.id, simgval.get_sim_code_str(vm.status)))
g_log_handler.info("[Broker__] %s\t\tCAL_EJCT: VM (ID:%d, TY:%s)'s JRT in Queue [len:%d]: %d" % (str(Global_Curr_Sim_Clock), vm.id, vm.type_name, len(vm.job_queue), exe_time_q_jobs))
g_log_handler.info("[Broker__] %s\t\tCAL_EJCT: Recv Job Actual Duration: %s (CPU:%s, IO:%s)" % (str(Global_Curr_Sim_Clock), job_actual_duration_infos[0], job_actual_duration_infos[1], job_actual_duration_infos[2]))
# estimated job completion time
est_job_comp_time = exe_time_q_jobs + job_actual_duration_infos[0]
g_log_handler.info ("[Broker__] %s\t\tCAL_EJCT: EJCT (%d) = JET_JQ (%d) + JR (%s - CPU:%s, IO:%s)" \
% (str(Global_Curr_Sim_Clock), est_job_comp_time, exe_time_q_jobs, job_actual_duration_infos[0], job_actual_duration_infos[1], job_actual_duration_infos[2]))
else:
# current job is NOT None (VM is processing the current job)
g_log_handler.info ("[Broker__] %s CAL_EJCT: VM (ID:%d, TY:%s)'s Current Job (ID:%d,NM:%s,ADR:%d (C:%s,IO:%s),DL:%d) is NOT None [CST:%d]" \
% (str(Global_Curr_Sim_Clock), vm.id, vm.type_name, vm.current_job.id, vm.current_job.name, vm.current_job.act_duration_on_VM, vm.current_job.act_cputime_on_VM, vm.current_job.act_nettime_on_VM, vm.current_job.deadline, vm.current_job_start_clock))
if vm.current_job_start_clock == -1:
g_log_handler.error ("[Broker__] %s CAL_EJCT: VM (ID:%d, TY:%s)'s Invalid Current Job (%s) Start Time (%d)" \
% (str(Global_Curr_Sim_Clock), vm.id, vm.type_name, simobj.get_job_info_str(vm.current_job), vm.current_job_start_clock))
clib.logwrite_vm_obj(g_log_handler, "[Broker__] " + str(Global_Curr_Sim_Clock), vm)
clib.sim_exit()
# jct = remaining running time of current job + sum of duration in job queue + job_duration
# remaining running time of current job =.current_job_start_clock + current_job.duration - clock
sum_past_job_exe_time = clib.get_sum_job_actual_duration (vm.job_history)
remaining_time_curr_job = vm.current_job_start_clock + vm.current_job.act_duration_on_VM - Global_Curr_Sim_Clock
if remaining_time_curr_job < 0:
g_log_handler.error ("[Broker__] %s CAL_EJCT: Remaining Exe Time for Current %s is Negative: %d = CJST (%d) + CJADR (%d - C:%s/IO:%s) - CL(%d)" \
% (str(Global_Curr_Sim_Clock), simobj.get_job_info_str(vm.current_job), remaining_time_curr_job, vm.current_job_start_clock, vm.current_job.act_duration_on_VM, vm.current_job.act_cputime_on_VM, vm.current_job.act_nettime_on_VM, Global_Curr_Sim_Clock))
clib.sim_exit()
g_log_handler.error("[Broker__] %s\t\tCalculate Estimated Job Completion Time on VM (ID:%d,ST:%s)" % (str(Global_Curr_Sim_Clock), vm.id, simgval.get_sim_code_str(vm.status)))
g_log_handler.error("[Broker__] %s\t\tCAL_EJCT: Current Simulation Clock: %d" % (str(Global_Curr_Sim_Clock), Global_Curr_Sim_Clock))
g_log_handler.error("[Broker__] %s\t\tCAL_EJCT: Remaining Exe Time for Current %s: %d = CJST (%d) + CJADR (%d - C:%s/IO:%s) - CL(%d)" \
% (str(Global_Curr_Sim_Clock), simobj.get_job_info_str(vm.current_job), remaining_time_curr_job, vm.current_job_start_clock,
vm.current_job.act_duration_on_VM, vm.current_job.act_cputime_on_VM, vm.current_job.act_nettime_on_VM, Global_Curr_Sim_Clock))
g_log_handler.error("[Broker__] %s\t\tCAL_EJCT: VM(ID:%d, TY:%s)'s JRT in Queue [len:%d]: %d" % (str(Global_Curr_Sim_Clock), vm.id, vm.type_name, len(vm.job_queue), exe_time_q_jobs))
g_log_handler.error("[Broker__] %s\t\tCAL_EJCT: Recv Job Actual Duration: %s (CPU:%s, IO:%s)" % (str(Global_Curr_Sim_Clock), job_actual_duration_infos[0], job_actual_duration_infos[1], job_actual_duration_infos[2]))
# calculate estimate job execution time on the VM
est_job_comp_time = remaining_time_curr_job + exe_time_q_jobs + job_actual_duration_infos[0]
g_log_handler.info("[Broker__] %s\t\tCAL_EJCT: EJCT (%d) = REMAIN_CR (%d) + JET_JQ (%d) + JR (%s - CPU:%s, IO:%s)" \
% (str(Global_Curr_Sim_Clock), est_job_comp_time, remaining_time_curr_job, exe_time_q_jobs, job_actual_duration_infos[0], job_actual_duration_infos[1], job_actual_duration_infos[2]))
return est_job_comp_time
# Related to Vscale
# Storage Simulation Debug Point - Done on 10.29.2014
def cal_estimation_job_complete_clock_for_VM (vm_obj, job_id):
# this lib only can be used when [1] vm.status == simgval.gVM_ST_ACTIVE && [2] vm.current_job == None
if vm_obj.status != simgval.gVM_ST_ACTIVE:
g_log_handler.error("[Broker__] %s CAL_EJCC: %s Status Error!" % (str(Global_Curr_Sim_Clock), vm_obj.get_str_info()))
clib.sim_exit()
curr_job_remain = 0
if vm_obj.current_job != None:
curr_job_remain = (vm_obj.current_job.time_start + vm_obj.current_job.act_duration_on_VM) - Global_Curr_Sim_Clock
if curr_job_remain < 0:
curr_job_remain = 0
remaining_clock = Global_Curr_Sim_Clock + curr_job_remain
for qjob in vm_obj.job_queue:
remaining_clock += qjob.act_duration_on_VM
if qjob.id == job_id:
return remaining_clock
return remaining_clock
# check for storage simulation on 10.29.2014
def check_all_deadline_meet (vm_obj):
return_val = True
sum_dl_mismatch = 0
sum_total_act_duration = 0
number_of_missed_jobs = 0
for job in vm_obj.job_queue:
sum_total_act_duration += job.act_duration_on_VM
clock_job_deadline = job.time_create + job.deadline
est_job_comp_time = cal_estimation_job_complete_clock_for_VM (vm_obj, job.id)
if est_job_comp_time > clock_job_deadline:
sum_dl_mismatch += (est_job_comp_time - clock_job_deadline)
number_of_missed_jobs += 1
return_val = False
return return_val, sum_dl_mismatch, sum_total_act_duration, number_of_missed_jobs
# VM Evaluation based on vm selection method
def do_VM_evaluation (vm_run_time, vm_unit_cost):
# 1. cost-based selection
if g_sim_conf.vm_selection_method == simgval.gVM_SEL_METHOD_COST:
return vm_unit_cost
# 2. perf-based selection
elif g_sim_conf.vm_selection_method == simgval.gVM_SEL_METHOD_PERF:
return vm_run_time
# 3. cost-perf balanced selection
elif g_sim_conf.vm_selection_method == simgval.gVM_SEL_METHOD_COSTPERF:
return round (vm_run_time * (vm_unit_cost / float (g_sim_conf.billing_unit_clock)), 3)
# error case
else:
g_log_handler.error("[Broker__] %s do_VM_evaluation Error! - Unknown VM Selection Code (%s)" % (str(Global_Curr_Sim_Clock), simgval.get_sim_code_str(g_sim_conf.vm_selection_method)))
clib.sim_exit()
# if return 0: both vm has same evaluation result
# if return 1: first vm is better
# if returl 2: second vm is better
# Storage Simulation Debug Point - check for storage simulation - 10/29/2014
def do_VM_compare (vm_info1, vm_info2):
if vm_info1 == vm_info2:
g_log_handler.error("[Broker__] %s do_VM_compare Error! - Two arguments are the same (arg1:%s, arg2:%s)" \
% (str(Global_Curr_Sim_Clock), vm_info1, vm_info2))
clib.sim_exit()
# vm_info1 = [vm_type_name, vm_type_unit_price, vm_run_time]
vm_eval1 = do_VM_evaluation (vm_info1[2], vm_info1[1])
vm_eval2 = do_VM_evaluation (vm_info2[2], vm_info2[1])
if vm_eval1 < vm_eval2:
return 1
elif vm_eval1 == vm_eval2:
return 0
else:
return 2
# Storage Scaling Debug Point - Done 12a.m. 10/29/2014
def VScale_VM_Select (vm_obj):
# [1] find vm types that can meet all deadline for jobs
# [2] if there are multiple number of VM types, then select VM based on vm selection method
# [3] if there is no VMs can meet deadline --> choose least deadline mismatch.
# data structure, [vm_type_obj info, duration, # of mismatched job, sum of mismatched time]
vscale_matched_vm_infos = []
vscale_mismatched_vm_infos = []
avg_startup_lag = get_average_startup_lagtime()
jobs = vm_obj.job_queue
print ""
print "======================================================================================================================================"
for vm_type in g_sim_conf.vm_types:
print "VScale VM Type Info:", vm_type.get_infos()
print "--------------------------------------------------------------------------------------------------------------------------------------"
vm_evals = []
vm_run_time = 1 # 1 is first distance of Vscale from now.
vm_run_time += avg_startup_lag
num_match_job = 0
num_mismatch_job = 0
sum_mismatch_time = 0
for job in jobs:
job_duration_infos = cal_job_actual_duration_on_VM (vm_type, job)
vm_run_time += job_duration_infos[0]
job_complete_clock = Global_Curr_Sim_Clock + vm_run_time
job_deadline_clock = job.time_create + job.deadline
mismatch_time = 0
if job_deadline_clock >= job_complete_clock:
num_match_job += 1
else:
num_mismatch_job += 1
mismatch_time = job_complete_clock - job_deadline_clock
sum_mismatch_time += mismatch_time
print " JOB_COMP_CLOCK = ", job_complete_clock, "\t| JOB_DL_CLOCK = ", job_deadline_clock, "\t| VM RUNTIME = ", vm_run_time, "\t| MISMATCH = ", mismatch_time ,"\t| SUM_MISMATCH = ", sum_mismatch_time
vm_evals.append(vm_type)
vm_evals.append(vm_run_time)
vm_evals.append(num_mismatch_job)
vm_evals.append(sum_mismatch_time)
# for vm evaluation -- this can be a function
vm_evl_result = do_VM_evaluation (vm_run_time, vm_type.vm_type_unit_price)
vm_evals.append(vm_evl_result)
if num_mismatch_job == 0:
vscale_matched_vm_infos.append (vm_evals)
else:
vscale_mismatched_vm_infos.append (vm_evals)
print "======================================================================================================================================"
print ""
print "======================================================================================================================================"
print "Matched VM List"
print "--------------------------------------------------------------------------------------------------------------------------------------"
if len(vscale_matched_vm_infos) > 0:
for v in vscale_matched_vm_infos:
print " ", v[0].get_infos(), v[1], v[2], v[3], v[4]
else:
print " None -- No VM Type can meet the all deadlines for all jobs"
print "--------------------------------------------------------------------------------------------------------------------------------------"
print "Mismatched VM List"
print "--------------------------------------------------------------------------------------------------------------------------------------"
if len(vscale_mismatched_vm_infos) > 0:
for v in vscale_mismatched_vm_infos:
print " ", v[0].get_infos(), v[1], v[2], v[3], v[4]
else:
print " None -- All VM Type can meet the all deadlines for all jobs"
print "======================================================================================================================================"
print ""
print "======================================================================================================================================"
if len(vscale_matched_vm_infos) < 1:
print "Final Sorting (%s) -- No VM Type can meet the all deadlines for all jobs" % simgval.get_sim_code_str(g_sim_conf.vm_selection_method)
print "--------------------------------------------------------------------------------------------------------------------------------------"
vscale_mismatched_vm_infos.sort(key=itemgetter(2,3))
for sort_index, v in enumerate(vscale_mismatched_vm_infos):
if sort_index == 0:
print " VM:", v[0].get_infos(), ",\tVM_RT:", v[1], ",\t#_MISSED_J:", v[2], ",\tSUM_MISSED_TM,", v[3], ",\tEVAL:", v[4], " -- Selected (*)"
else:
print " VM:", v[0].get_infos(), ",\tVM_RT:", v[1], ",\t#_MISSED_J:", v[2], ",\tSUM_MISSED_TM,", v[3], ",\tEVAL:", v[4]
print "======================================================================================================================================"
return vscale_mismatched_vm_infos[0][0], vscale_mismatched_vm_infos[0][1], vscale_mismatched_vm_infos[0][3], vscale_mismatched_vm_infos[0][2]
elif len (vscale_matched_vm_infos) == 1:
print "Final Sorting (%s) -- Only One VM Type can meet the all deadlines for all jobs" % simgval.get_sim_code_str(g_sim_conf.vm_selection_method)
print "--------------------------------------------------------------------------------------------------------------------------------------"
print " VM:", vscale_matched_vm_infos[0][0].get_infos(), ",\tVM_RT:", vscale_matched_vm_infos[0][1], ",\t#_MISSED_J:", vscale_matched_vm_infos[0][2], ",\tSUM_MISSED_TM,", vscale_matched_vm_infos[0][3], ",\tEVAL:", vscale_matched_vm_infos[0][4], " -- Selected (*)"
print "======================================================================================================================================"
return vscale_matched_vm_infos[0][0], vscale_matched_vm_infos[0][1], vscale_matched_vm_infos[0][3], vscale_matched_vm_infos[0][2]
else:
print "Final Sorting (%s) -- Multiple VM Types can meet the all deadlines for all jobs" % simgval.get_sim_code_str(g_sim_conf.vm_selection_method)
print "--------------------------------------------------------------------------------------------------------------------------------------"
vscale_matched_vm_infos.sort (key=lambda vm_info: vm_info[4])
for sorted_index, v in enumerate(vscale_matched_vm_infos):
if sorted_index == 0:
print " VM:", v[0].get_infos(), ",\tVM_RT:", v[1], ",\t#_MISSED_J:", v[2], ",\tSUM_MISSED_TM,", v[3], ",\tEVAL:", v[4], " -- Selected (*)"
else:
print " VM:", v[0].get_infos(), ",\tVM_RT:", v[1], ",\t#_MISSED_J:", v[2], ",\tSUM_MISSED_TM,", v[3], ",\tEVAL:", v[4]
print "======================================================================================================================================"
return vscale_matched_vm_infos[0][0], vscale_matched_vm_infos[0][1], vscale_matched_vm_infos[0][3], vscale_matched_vm_infos[0][2]
def VScale_Trigger_Condition_Check (vm_obj):
check_Vscale = False
# check Vscale trigger condition
# check num of further jobs
if len(vm_obj.job_queue) > 0:
# Vscale enable
if g_sim_conf.enable_vertical_scaling == True:
curr_run_vm_cnt = get_number_Running_VM_Instances()
max_cap = g_sim_conf.job_assign_max_running_vms
# Vscale can be activated when the num of curr run vms == max cap of vm
if curr_run_vm_cnt == max_cap:
check_Vscale = True
# this is error case
elif curr_run_vm_cnt > max_cap:
g_log_handler.error ("[Broker__] %s VM Max Cap (%d) Error! - # of Curr Running VMs (%d)" % (str(Global_Curr_Sim_Clock), max_cap, curr_run_vm_cnt))
clib.sim_exit()
# num of curr run VMs < max_cap: Vscale disabled.