Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dfaast
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Santhosh Kumar
dfaast
Commits
060229ff
Commit
060229ff
authored
May 03, 2024
by
SIVAPRASAD S
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update function.py
parent
37e5ba7f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
10 deletions
+24
-10
src/example2/function.py
src/example2/function.py
+24
-10
No files found.
src/example2/function.py
View file @
060229ff
...
...
@@ -89,9 +89,21 @@ def start_memory_allocator(memory_size):
# Create a new process for memory allocation
memory_process
=
multiprocessing
.
Process
(
target
=
allocate_memory
,
args
=
(
memory_size
,))
memory_process
.
start
()
use_allocated_memory
()
return
jsonify
({
'message'
:
f
'Memory allocated with size {memory_size}'
}),
200
@
app
.
route
(
'/use_memory'
,
methods
=
[
'GET'
])
def
use_allocated_memory
():
global
memory_block
if
memory_block
is
None
:
return
jsonify
({
'error'
:
'Memory not allocated yet'
}),
400
# Use the allocated memory block
data
=
b
'Hello, world!'
*
(
len
(
memory_block
)
//
len
(
b
'Hello, world!'
))
memory_block
[
0
:
len
(
data
)]
=
data
return
jsonify
({
'message'
:
'Data written to allocated memory successfully'
}),
200
@
app
.
route
(
"/"
)
def
hello
():
time_invoked
=
time
.
time
()
...
...
@@ -99,7 +111,9 @@ def hello():
# Increment request counter
function_requests_total
.
inc
()
time
.
sleep
(
0.1
)
for
i
in
range
(
1000000
):
for
j
in
range
(
10000
)
service_time
=
time
.
time
()
-
time_invoked
...
...
@@ -171,15 +185,15 @@ def metrics():
network_bytes_sent
.
inc
(
network_stats
.
bytes_sent
)
network_bytes_recv
.
inc
(
network_stats
.
bytes_recv
)
output
=
""
output
+=
"Number of Requests: "
+
str
(
no_of_requests
)
+
"
\n
"
output
+=
"Request Rate: "
+
str
(
request_rate
)
+
"
\n
"
output
+=
"Service Time: "
+
str
(
service_time
)
+
"
\n
"
output
+=
"CPU Utilization: "
+
str
(
cpu_utilization
)
+
"
\n
"
output
+=
"Bytes Sent: "
+
str
(
bytes_sent
)
+
"
\n
"
output
+=
"Bytes Received: "
+
str
(
bytes_received
)
+
"
\n
"
print
(
"Number of Requests: "
,
no_of_requests
)
print
(
"Request_rate: "
,
request_rate
)
print
(
"Service Time: "
,
service_time
)
print
(
"CPU utilization: "
,
cpu_utilization
)
print
(
"Bytes send: "
,
bytes_sent
)
print
(
"Bytes received: "
,
bytes_received
)
return
generate_latest
(
registry
),
200
,
{
"Content-Type"
:
CONTENT_TYPE_LATEST
}
return
output
,
200
,
{
"Content-Type"
:
CONTENT_TYPE_LATEST
}
if
__name__
==
"__main__"
:
...
...
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