Commit 060229ff authored by SIVAPRASAD S's avatar SIVAPRASAD S

Update function.py

parent 37e5ba7f
...@@ -89,9 +89,21 @@ def start_memory_allocator(memory_size): ...@@ -89,9 +89,21 @@ def start_memory_allocator(memory_size):
# Create a new process for memory allocation # Create a new process for memory allocation
memory_process = multiprocessing.Process(target=allocate_memory, args=(memory_size,)) memory_process = multiprocessing.Process(target=allocate_memory, args=(memory_size,))
memory_process.start() memory_process.start()
use_allocated_memory()
return jsonify({'message': f'Memory allocated with size {memory_size}'}), 200 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("/") @app.route("/")
def hello(): def hello():
time_invoked=time.time() time_invoked=time.time()
...@@ -99,7 +111,9 @@ def hello(): ...@@ -99,7 +111,9 @@ def hello():
# Increment request counter # Increment request counter
function_requests_total.inc() function_requests_total.inc()
time.sleep(0.1) for i in range(1000000):
for j in range(10000)
service_time = time.time() - time_invoked service_time = time.time() - time_invoked
...@@ -171,15 +185,15 @@ def metrics(): ...@@ -171,15 +185,15 @@ def metrics():
network_bytes_sent.inc(network_stats.bytes_sent) network_bytes_sent.inc(network_stats.bytes_sent)
network_bytes_recv.inc(network_stats.bytes_recv) 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) return output, 200, {"Content-Type": CONTENT_TYPE_LATEST}
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}
if __name__ == "__main__": if __name__ == "__main__":
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment