Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
flame-clmc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
flame
flame-clmc
Commits
9626d3ec
Commit
9626d3ec
authored
7 years ago
by
MJB
Browse files
Options
Downloads
Patches
Plain Diff
removed global tags:wq
parent
20578fec
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/mediaServiceSim/simulator_v2.py
+23
-23
23 additions, 23 deletions
src/mediaServiceSim/simulator_v2.py
with
23 additions
and
23 deletions
src/mediaServiceSim/simulator_v2.py
+
23
−
23
View file @
9626d3ec
...
...
@@ -8,8 +8,10 @@ from random import random, randint
class
sim
:
def
__init__
(
self
,
influx_url
):
# requests per second for different quality levels
self
.
quality_request_rate
=
{
"
locA
"
:
[
10
,
20
,
10
],
"
locB
"
:
[
5
,
30
,
5
]}
self
.
influx_db
=
'
testDB
'
self
.
quality_request_rate
=
{
"
DC1
"
:
[
10
,
20
,
10
],
"
DC2
"
:
[
5
,
30
,
5
]}
# We don't need this as the db is CLMC metrics
self
.
influx_db
=
'
CLMCMetrics
'
self
.
influx_url
=
influx_url
# Teardown DB from previous sim and bring it back up
self
.
_deleteDB
()
...
...
@@ -19,38 +21,37 @@ class sim:
def
run
(
self
,
simulation_length_seconds
):
start_time
=
time
.
time
()
current_time
=
int
(
time
.
time
())
surrogate_services
=
[{
'
location
'
:
'
locA
'
,
'
cpu
'
:
2
,
'
sfc
'
:
'
scenario1_template
'
,
'
sfc_i
'
:
'
Scenario1_Template_I1
'
,
'
sf_package
'
:
'
MS_STREAMING
'
,
'
sf_i
'
:
'
MS_STREAMING_1
'
,
'
mem
'
:
'
8GB
'
,
'
storage
'
:
'
1TB
'
},
{
'
location
'
:
'
locB
'
,
'
cpu
'
:
4
,
'
sfc
'
:
'
scenario1_template
'
,
'
sfc_i
'
:
'
Scenario1_Template_I1
'
,
'
sf_package
'
:
'
MS_STREAMING
'
,
'
sf_i
'
:
'
MS_STREAMING_2
'
,
'
mem
'
:
'
8GB
'
,
'
storage
'
:
'
1TB
'
}
surrogate_services
=
[{
'
agent_url
'
:
'
http://192.168.50.11:8186
'
,
'
location
'
:
'
DC1
'
,
'
cpu
'
:
2
,
'
mem
'
:
'
8GB
'
,
'
storage
'
:
'
1TB
'
},
{
'
agent_url
'
:
'
http://192.168.50.12:8186
'
,
'
location
'
:
'
DC2
'
,
'
cpu
'
:
4
,
'
mem
'
:
'
8GB
'
,
'
storage
'
:
'
1TB
'
}
]
# Simulate surrogate services being asserted
for
service
in
surrogate_services
:
self
.
_sendInfluxData
(
lp
.
generate_vm_config
(
'
starting
'
,
service
[
'
cpu
'
],
service
[
'
mem
'
],
service
[
'
storage
'
],
current_time
))
self
.
_sendInfluxData
(
service
[
'
agent_url
'
],
lp
.
generate_vm_config
(
'
starting
'
,
service
[
'
cpu
'
],
service
[
'
mem
'
],
service
[
'
storage
'
],
current_time
))
for
service
in
surrogate_services
:
self
.
_sendInfluxData
(
lp
.
generate_vm_config
(
'
running
'
,
service
[
'
cpu
'
],
service
[
'
mem
'
],
service
[
'
storage
'
],
current_time
))
self
.
_sendInfluxData
(
service
[
'
agent_url
'
],
lp
.
generate_vm_config
(
'
running
'
,
service
[
'
cpu
'
],
service
[
'
mem
'
],
service
[
'
storage
'
],
current_time
))
# Run simulation
for
i
in
range
(
simulation_length_seconds
):
for
service
in
surrogate_services
:
# Scale CPU usage on number of requests, quality and cpu allocation
cpu_usage
=
self
.
quality_request_rate
[
service
[
'
location
'
]][
0
]
cpu_usage
+=
self
.
quality_request_rate
[
service
[
'
location
'
]][
1
]
*
2
cpu_usage
+=
self
.
quality_request_rate
[
service
[
'
location
'
]][
2
]
*
4
cpu_usage
=
cpu_usage
/
service
[
'
cpu
'
]
cpu_usage
=
cpu_usage
/
100
# Transform into %
self
.
_sendInfluxData
(
lp
.
generate_cpu_report
(
service
[
'
location
'
],
service
[
'
sfc
'
],
service
[
'
sfc_i
'
],
service
[
'
sf_package
'
],
service
[
'
sf_i
'
],
cpu_usage
,
cpu_usage
,
current_time
))
self
.
_sendInfluxData
(
service
[
'
agent_url
'
],
lp
.
generate_cpu_report
(
cpu_usage
,
cpu_usage
,
current_time
))
# Scale SENT/REC bytes on requests and quality
bytes
=
self
.
quality_request_rate
[
service
[
'
location
'
]][
0
]
bytes
+=
self
.
quality_request_rate
[
service
[
'
location
'
]][
1
]
*
2
bytes
+=
self
.
quality_request_rate
[
service
[
'
location
'
]][
2
]
*
4
bytes_sent
=
1024
*
bytes
bytes_rec
=
32
*
bytes
self
.
_sendInfluxData
(
lp
.
generate_network_report
(
bytes_rec
,
bytes_sent
,
current_time
))
self
.
_sendInfluxData
(
service
[
'
agent_url
'
],
lp
.
generate_network_report
(
bytes_rec
,
bytes_sent
,
current_time
))
# Scale MPEG Dash on requests, quality, cpu usage
avg_response_time
=
randint
(
0
,
5
*
self
.
quality_request_rate
[
service
[
'
location
'
]][
0
])
avg_response_time
+=
randint
(
0
,
10
*
self
.
quality_request_rate
[
service
[
'
location
'
]][
1
])
...
...
@@ -58,34 +59,33 @@ class sim:
avg_response_time
*=
cpu_usage
peak_response_time
=
avg_response_time
+
randint
(
30
,
60
)
requests
=
sum
(
self
.
quality_request_rate
[
service
[
'
location
'
]])
self
.
_sendInfluxData
(
lp
.
generate_mpegdash_report
(
'
https://Netflix.com/scream
'
,
requests
,
avg_response_time
,
peak_response_time
,
current_time
))
self
.
_sendInfluxData
(
service
[
'
agent_url
'
],
lp
.
generate_mpegdash_report
(
'
https://Netflix.com/scream
'
,
requests
,
avg_response_time
,
peak_response_time
,
current_time
))
# Add a second to the clock
current_time
+=
1000
end_time
=
time
.
time
()
print
(
"
Simulation Finished. Start time {0}. End time {1}. Total time {2}
"
.
format
(
start_time
,
end_time
,
end_time
-
start_time
))
def
_createDB
(
self
):
self
.
_sendInfluxQuery
(
'
CREATE DATABASE
'
+
self
.
influx_db
)
self
.
_sendInfluxQuery
(
self
.
influx_url
,
'
CREATE DATABASE
'
+
self
.
influx_db
)
def
_deleteDB
(
self
):
self
.
_sendInfluxQuery
(
'
DROP DATABASE
'
+
self
.
influx_db
)
self
.
_sendInfluxQuery
(
self
.
influx_url
,
'
DROP DATABASE
'
+
self
.
influx_db
)
def
_sendInfluxQuery
(
self
,
query
):
def
_sendInfluxQuery
(
self
,
url
,
query
):
query
=
urllib
.
parse
.
urlencode
({
'
q
'
:
query
})
query
=
query
.
encode
(
'
ascii
'
)
req
=
urllib
.
request
.
Request
(
self
.
influx_
url
+
'
/query
'
,
query
)
req
=
urllib
.
request
.
Request
(
url
+
'
/query
'
,
query
)
urllib
.
request
.
urlopen
(
req
)
def
_sendInfluxData
(
self
,
data
):
def
_sendInfluxData
(
self
,
url
,
data
):
data
=
data
.
encode
()
header
=
{
'
Content-Type
'
:
'
application/octet-stream
'
}
req
=
urllib
.
request
.
Request
(
self
.
influx_
url
+
'
/write?db=
'
+
self
.
influx_db
,
data
,
header
)
req
=
urllib
.
request
.
Request
(
url
+
'
/write?db=
'
+
self
.
influx_db
,
data
,
header
)
urllib
.
request
.
urlopen
(
req
)
simulator
=
sim
(
'
http://
localhost:81
86
'
)
simulator
=
sim
(
'
http://
192.168.50.10:80
86
'
)
simulator
.
run
(
180
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment