Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pa2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nilesh Jagdish
pa2
Commits
1f49a832
Commit
1f49a832
authored
Mar 23, 2021
by
Nilesh Jagdish
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Current working code
parent
7344f9f9
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
267 additions
and
20 deletions
+267
-20
client.py
client.py
+29
-5
config.py
config.py
+1
-0
monitor.py
monitor.py
+72
-15
server.py
server.py
+45
-0
server2.xml
server2.xml
+120
-0
No files found.
client.py
View file @
1f49a832
from
__future__
import
print_function
import
socket
import
socket
import
concurrent.futures
import
concurrent.futures
import
urllib.request
import
urllib.request
import
random
import
random
import
time
import
time
import
sys
import
libvirt
import
config
TCP_IP
=
'192.168.123.174'
TCP_IP
=
'192.168.123.174'
TCP_PORT
=
9001
TCP_PORT
=
9001
BUFFER_SIZE
=
1024
BUFFER_SIZE
=
1024
server_conns
=
[[
'192.168.123.174'
,
9001
]]
# server_ips = ['192.168.123.174']
server_ips
=
config
.
new_server_ips
def
send_request
(
request
,
server_index
):
def
send_request
(
request
,
server_index
):
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
s
.
connect
((
server_
conns
[
server_index
][
0
],
server_conns
[
server_index
][
1
]
))
s
.
connect
((
server_
ips
[
server_index
],
TCP_PORT
))
s
.
send
(
request
.
encode
(
'ascii'
))
s
.
send
(
request
.
encode
(
'ascii'
))
data
=
s
.
recv
(
BUFFER_SIZE
)
data
=
s
.
recv
(
BUFFER_SIZE
)
s
.
close
()
s
.
close
()
...
@@ -21,12 +27,30 @@ def send_request(request, server_index):
...
@@ -21,12 +27,30 @@ def send_request(request, server_index):
request
=
'3,50'
request
=
'3,50'
server_index
=
0
server_index
=
0
conn
=
libvirt
.
open
(
'qemu:///system'
)
if
conn
==
None
:
print
(
'Failed to open connection to qemu:///system'
,
file
=
sys
.
stderr
)
exit
(
1
)
i
=
0
while
(
True
)
:
while
(
True
)
:
l
=
[
request
]
*
50
if
(
i
<
10
):
server_index
=
(
server_index
+
1
)
%
len
(
server_conns
)
l
=
[
request
]
*
100
else
:
l
=
[
request
]
*
200
server_index
=
(
server_index
+
1
)
%
len
(
server_ips
)
f
=
open
(
'server_ips.txt'
,
'r'
)
server_ips
=
[
line
.
strip
()
for
line
in
f
.
readlines
()]
# print(config.new_server_ips)
# print(server_ips)
print
(
server_index
)
# for lease in conn.networkLookupByName("default").DHCPLeases():
# if lease['ipaddr'] not in server_ips:
# server_ips.append(lease['ipaddr'])
with
concurrent
.
futures
.
ThreadPoolExecutor
(
max_workers
=
2
)
as
executor
:
with
concurrent
.
futures
.
ThreadPoolExecutor
(
max_workers
=
2
)
as
executor
:
req_sender
=
[
executor
.
submit
(
send_request
,
request
,
server_index
)
for
request
in
l
]
req_sender
=
[
executor
.
submit
(
send_request
,
request
,
server_index
)
for
request
in
l
]
for
future
in
concurrent
.
futures
.
as_completed
(
req_sender
):
for
future
in
concurrent
.
futures
.
as_completed
(
req_sender
):
data
=
future
.
result
()
data
=
future
.
result
()
print
(
data
)
# print(data)
i
+=
1
time
.
sleep
(
0.5
)
time
.
sleep
(
0.5
)
\ No newline at end of file
config.py
0 → 100644
View file @
1f49a832
new_server_ips
=
[
'192.168.123.174'
]
\ No newline at end of file
monitor.py
View file @
1f49a832
import
sys
import
sys
import
libvirt
import
libvirt
import
time
import
time
import
config
import
threading
import
socket
conn
=
libvirt
.
open
(
'qemu:///system'
)
conn
=
libvirt
.
open
(
'qemu:///system'
)
if
conn
==
None
:
if
conn
==
None
:
...
@@ -12,22 +15,76 @@ dom = conn.lookupByName(domainName)
...
@@ -12,22 +15,76 @@ dom = conn.lookupByName(domainName)
if
dom
==
None
:
if
dom
==
None
:
print
(
'Failed to get the domain object'
,
file
=
sys
.
stderr
)
print
(
'Failed to get the domain object'
,
file
=
sys
.
stderr
)
N
=
10
f1
=
open
(
'server_ips.txt'
,
'w'
)
cpu_stats
=
dom
.
getCPUStats
(
True
)
f1
.
write
(
config
.
new_server_ips
[
0
])
cpu_time1
=
0
f1
.
close
()
cpu_time2
=
0
for
(
i
,
cpu
)
in
enumerate
(
cpu_stats
):
cpu_time1
=
cpu
[
'cpu_time'
]
/
1000000000.
print
(
'CPU '
+
str
(
i
)
+
' Time: '
+
str
(
cpu
[
'cpu_time'
]
/
1000000000.
))
time
.
sleep
(
N
)
def
establish_conn
(
server_ip
,
port
):
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
cpu_stats
=
dom
.
getCPUStats
(
True
)
sock
.
settimeout
(
10
)
for
(
i
,
cpu
)
in
enumerate
(
cpu_stats
):
while
(
True
):
cpu_time2
=
cpu
[
'cpu_time'
]
/
1000000000.
try
:
print
(
'CPU '
+
str
(
i
)
+
' Time: '
+
str
(
cpu
[
'cpu_time'
]
/
1000000000.
))
sock
.
connect
((
server_ip
,
port
))
break
print
(
100
*
(
cpu_time2
-
cpu_time1
)
/
N
)
# except socket.gaierror, e:
# print "Address-related error connecting to server: %s" % e
# sys.exit(1)
except
socket
.
error
:
print
(
"Connection error: {}"
.
format
(
socket
.
error
))
print
(
"Connection established..."
)
sock
.
settimeout
(
None
)
sock
.
close
()
print
(
"Monitor program started running..."
)
ind
=
0
while
(
True
):
N
=
10
cpu_time1
=
0
cpu_time2
=
0
cpu_stats1
=
dom
.
getCPUStats
(
True
)
for
(
i
,
cpu
)
in
enumerate
(
cpu_stats1
):
cpu_time1
=
cpu
[
'cpu_time'
]
/
1000000000.
# print('CPU '+str(i)+' Time: '+str(cpu['cpu_time'] / 1000000000.))
time
.
sleep
(
N
)
cpu_stats2
=
dom
.
getCPUStats
(
True
)
for
(
i
,
cpu
)
in
enumerate
(
cpu_stats2
):
cpu_time2
=
cpu
[
'cpu_time'
]
/
1000000000.
# print('CPU '+str(i)+' Time: '+str(cpu['cpu_time'] / 1000000000.))
cpu_usage
=
100
*
(
cpu_time2
-
cpu_time1
)
/
N
print
(
cpu_usage
)
if
(
cpu_usage
>
60.0
):
print
(
'Overload detected'
)
dom1
=
conn
.
lookupByName
(
'server2'
)
flag
=
dom1
.
isActive
()
f
=
open
(
'server2.xml'
,
'r'
)
xmlconfig
=
" "
.
join
(
f
.
readlines
())
ind
+=
1
# print(xmlconfig)
# t1 = None
if
(
flag
==
False
):
dom1
=
conn
.
defineXML
(
xmlconfig
)
if
dom1
==
None
:
print
(
'Failed to define a domain from an XML definition.'
,
file
=
sys
.
stderr
)
exit
(
1
)
if
dom1
.
create
()
<
0
:
print
(
'Can not boot guest domain.'
,
file
=
sys
.
stderr
)
exit
(
1
)
print
(
'Guest '
+
dom1
.
name
()
+
' has booted'
,
file
=
sys
.
stderr
)
# while(dom1.isActive() == False):
# continue
for
lease
in
conn
.
networkLookupByName
(
"default"
)
.
DHCPLeases
():
if
lease
[
'ipaddr'
]
not
in
config
.
new_server_ips
:
config
.
new_server_ips
.
append
(
lease
[
'ipaddr'
])
t1
=
threading
.
Thread
(
target
=
establish_conn
,
args
=
(
lease
[
'ipaddr'
],
9001
))
t1
.
start
()
else
:
if
((
dom1
.
isActive
()
==
True
)
and
(
ind
>=
3
)):
t1
.
join
()
f1
=
open
(
'server_ips.txt'
,
'w'
)
for
i
in
range
(
len
(
config
.
new_server_ips
)):
f1
.
write
(
config
.
new_server_ips
[
i
]
+
'
\n
'
)
f1
.
close
()
print
(
config
.
new_server_ips
)
conn
.
close
()
conn
.
close
()
exit
(
0
)
exit
(
0
)
\ No newline at end of file
server.py
0 → 100644
View file @
1f49a832
import
socket
from
threading
import
Thread
from
socketserver
import
ThreadingMixIn
import
concurrent.futures
import
urllib.request
import
random
import
time
import
sys
TCP_IP
=
sys
.
argv
[
1
]
TCP_PORT
=
9001
BUFFER_SIZE
=
1024
tcpsock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
tcpsock
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_REUSEADDR
,
1
)
tcpsock
.
bind
((
TCP_IP
,
TCP_PORT
))
# threads = []
def
calc_pow
(
num
,
raise_to
):
return
num
**
raise_to
def
process_req
(
conn
,
ip
,
port
):
request
=
conn
.
recv
(
1024
)
print
(
request
)
request
=
request
.
decode
(
'utf-8'
)
num
,
raise_to
=
request
.
split
(
','
)
num
=
int
(
num
)
raise_to
=
int
(
raise_to
)
result
=
calc_pow
(
num
,
raise_to
)
result
=
str
(
result
)
conn
.
send
(
result
.
encode
(
'ascii'
))
conn
.
close
()
return
True
with
concurrent
.
futures
.
ThreadPoolExecutor
(
max_workers
=
2
)
as
executor
:
future_to_pow
=
[]
while
True
:
tcpsock
.
listen
(
5
)
print
(
"Waiting for incoming connections...."
)
(
conn
,
(
ip
,
port
))
=
tcpsock
.
accept
()
future_to_pow
.
append
(
executor
.
submit
(
process_req
,
conn
,
ip
,
port
))
# future_to_sort = [executor.submit(sort_list, l) for l in lol]
if
(
len
(
future_to_pow
)
>=
50
):
for
future
in
concurrent
.
futures
.
as_completed
(
future_to_pow
):
data
=
future
.
result
()
future_to_pow
=
[]
server2.xml
0 → 100755
View file @
1f49a832
<!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:
virsh edit server2
or other application using the libvirt API.
-->
<domain
type=
'kvm'
>
<name>
server2
</name>
<uuid>
bbac0227-34e9-48e8-9d88-4ec8824ebe45
</uuid>
<memory
unit=
'KiB'
>
1048576
</memory>
<currentMemory
unit=
'KiB'
>
1048576
</currentMemory>
<vcpu
placement=
'static'
>
1
</vcpu>
<os>
<type
arch=
'x86_64'
machine=
'pc-i440fx-bionic'
>
hvm
</type>
<boot
dev=
'hd'
/>
</os>
<features>
<acpi/>
<apic/>
<vmport
state=
'off'
/>
</features>
<cpu
mode=
'custom'
match=
'exact'
check=
'partial'
>
<model
fallback=
'allow'
>
Broadwell-noTSX-IBRS
</model>
</cpu>
<clock
offset=
'utc'
>
<timer
name=
'rtc'
tickpolicy=
'catchup'
/>
<timer
name=
'pit'
tickpolicy=
'delay'
/>
<timer
name=
'hpet'
present=
'no'
/>
</clock>
<on_poweroff>
destroy
</on_poweroff>
<on_reboot>
restart
</on_reboot>
<on_crash>
destroy
</on_crash>
<pm>
<suspend-to-mem
enabled=
'no'
/>
<suspend-to-disk
enabled=
'no'
/>
</pm>
<devices>
<emulator>
/usr/bin/kvm-spice
</emulator>
<disk
type=
'file'
device=
'disk'
>
<driver
name=
'qemu'
type=
'qcow2'
/>
<source
file=
'/home/nilesh/iitb/cs695/tpa2/server-pool/server2.qcow2'
/>
<target
dev=
'hda'
bus=
'ide'
/>
<address
type=
'drive'
controller=
'0'
bus=
'0'
target=
'0'
unit=
'0'
/>
</disk>
<disk
type=
'file'
device=
'cdrom'
>
<driver
name=
'qemu'
type=
'raw'
/>
<target
dev=
'hdb'
bus=
'ide'
/>
<readonly/>
<address
type=
'drive'
controller=
'0'
bus=
'0'
target=
'0'
unit=
'1'
/>
</disk>
<controller
type=
'usb'
index=
'0'
model=
'ich9-ehci1'
>
<address
type=
'pci'
domain=
'0x0000'
bus=
'0x00'
slot=
'0x05'
function=
'0x7'
/>
</controller>
<controller
type=
'usb'
index=
'0'
model=
'ich9-uhci1'
>
<master
startport=
'0'
/>
<address
type=
'pci'
domain=
'0x0000'
bus=
'0x00'
slot=
'0x05'
function=
'0x0'
multifunction=
'on'
/>
</controller>
<controller
type=
'usb'
index=
'0'
model=
'ich9-uhci2'
>
<master
startport=
'2'
/>
<address
type=
'pci'
domain=
'0x0000'
bus=
'0x00'
slot=
'0x05'
function=
'0x1'
/>
</controller>
<controller
type=
'usb'
index=
'0'
model=
'ich9-uhci3'
>
<master
startport=
'4'
/>
<address
type=
'pci'
domain=
'0x0000'
bus=
'0x00'
slot=
'0x05'
function=
'0x2'
/>
</controller>
<controller
type=
'pci'
index=
'0'
model=
'pci-root'
/>
<controller
type=
'ide'
index=
'0'
>
<address
type=
'pci'
domain=
'0x0000'
bus=
'0x00'
slot=
'0x01'
function=
'0x1'
/>
</controller>
<controller
type=
'virtio-serial'
index=
'0'
>
<address
type=
'pci'
domain=
'0x0000'
bus=
'0x00'
slot=
'0x06'
function=
'0x0'
/>
</controller>
<filesystem
type=
'mount'
accessmode=
'mapped'
>
<source
dir=
'/home/nilesh/iitb/cs695/tpa2/share'
/>
<target
dir=
'sharepoint'
/>
<address
type=
'pci'
domain=
'0x0000'
bus=
'0x00'
slot=
'0x08'
function=
'0x0'
/>
</filesystem>
<interface
type=
'network'
>
<mac
address=
'52:54:00:2f:dd:36'
/>
<source
network=
'default'
/>
<model
type=
'rtl8139'
/>
<address
type=
'pci'
domain=
'0x0000'
bus=
'0x00'
slot=
'0x03'
function=
'0x0'
/>
</interface>
<serial
type=
'pty'
>
<target
type=
'isa-serial'
port=
'0'
>
<model
name=
'isa-serial'
/>
</target>
</serial>
<console
type=
'pty'
>
<target
type=
'serial'
port=
'0'
/>
</console>
<channel
type=
'spicevmc'
>
<target
type=
'virtio'
name=
'com.redhat.spice.0'
/>
<address
type=
'virtio-serial'
controller=
'0'
bus=
'0'
port=
'1'
/>
</channel>
<input
type=
'mouse'
bus=
'ps2'
/>
<input
type=
'keyboard'
bus=
'ps2'
/>
<graphics
type=
'spice'
autoport=
'yes'
>
<listen
type=
'address'
/>
<image
compression=
'off'
/>
</graphics>
<sound
model=
'ich6'
>
<address
type=
'pci'
domain=
'0x0000'
bus=
'0x00'
slot=
'0x04'
function=
'0x0'
/>
</sound>
<video>
<model
type=
'qxl'
ram=
'65536'
vram=
'65536'
vgamem=
'16384'
heads=
'1'
primary=
'yes'
/>
<address
type=
'pci'
domain=
'0x0000'
bus=
'0x00'
slot=
'0x02'
function=
'0x0'
/>
</video>
<redirdev
bus=
'usb'
type=
'spicevmc'
>
<address
type=
'usb'
bus=
'0'
port=
'1'
/>
</redirdev>
<redirdev
bus=
'usb'
type=
'spicevmc'
>
<address
type=
'usb'
bus=
'0'
port=
'2'
/>
</redirdev>
<memballoon
model=
'virtio'
>
<address
type=
'pci'
domain=
'0x0000'
bus=
'0x00'
slot=
'0x07'
function=
'0x0'
/>
</memballoon>
</devices>
</domain>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment