adapto 0.1.3__tar.gz → 0.1.4__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: adapto
3
- Version: 0.1.3
3
+ Version: 0.1.4
4
4
  Summary: AI-driven auto-scaling library for dynamic resource allocation.
5
5
  Home-page: https://github.com/hrshlmeht/adapto
6
6
  Author: Harshal Mehta
@@ -0,0 +1,25 @@
1
+ import time
2
+ import logging
3
+ from utils.aws_client import get_aws_client
4
+
5
+ class AWSLambdaMonitor:
6
+ def __init__(self, function_name):
7
+ self.client = get_aws_client("cloudwatch")
8
+ self.function_name = function_name
9
+
10
+ def get_execution_time(self):
11
+ """Fetches the average execution time of the AWS Lambda function."""
12
+ try:
13
+ response = self.client.get_metric_statistics(
14
+ Namespace="AWS/Lambda",
15
+ MetricName="Duration",
16
+ Dimensions=[{"Name": "FunctionName", "Value": self.function_name}],
17
+ StartTime=time.time() - 3600,
18
+ EndTime=time.time(),
19
+ Period=300,
20
+ Statistics=["Average"]
21
+ )
22
+ return response["Datapoints"][-1]["Average"] if response["Datapoints"] else None
23
+ except Exception as e:
24
+ logging.error(f"Error fetching Lambda execution time: {e}")
25
+ return None
@@ -0,0 +1,48 @@
1
+ import logging
2
+ from utils.aws_client import get_aws_client
3
+ from adapto.config.settings import EXECUTION_TIME_THRESHOLD, LAMBDA_MEMORY_STEP, MIN_MEMORY, MAX_MEMORY
4
+ from adapto.aws_lambda_monitor import AWSLambdaMonitor
5
+
6
+
7
+ class AWSLambdaScaler:
8
+ def __init__(self, function_name):
9
+ self.client = get_aws_client("lambda")
10
+ self.monitor = AWSLambdaMonitor(function_name)
11
+ self.function_name = function_name
12
+
13
+ def get_current_memory(self):
14
+ """Retrieves the current memory allocation of the Lambda function."""
15
+ try:
16
+ response = self.client.get_function_configuration(FunctionName=self.function_name)
17
+ return response["MemorySize"]
18
+ except Exception as e:
19
+ logging.error(f"Error fetching Lambda memory configuration: {e}")
20
+ return None
21
+
22
+ def scale_lambda_memory(self):
23
+ """Adjusts Lambda memory allocation based on execution time."""
24
+ execution_time = self.monitor.get_execution_time()
25
+ if execution_time is None:
26
+ return
27
+
28
+ current_memory = self.get_current_memory()
29
+ if current_memory is None:
30
+ return
31
+
32
+ if execution_time > EXECUTION_TIME_THRESHOLD and current_memory < MAX_MEMORY:
33
+ new_memory = min(current_memory + LAMBDA_MEMORY_STEP, MAX_MEMORY)
34
+ self.update_lambda_memory(new_memory)
35
+ elif execution_time < EXECUTION_TIME_THRESHOLD * 0.6 and current_memory > MIN_MEMORY:
36
+ new_memory = max(current_memory - LAMBDA_MEMORY_STEP, MIN_MEMORY)
37
+ self.update_lambda_memory(new_memory)
38
+
39
+ def update_lambda_memory(self, new_memory):
40
+ """Updates the Lambda memory configuration."""
41
+ try:
42
+ self.client.update_function_configuration(
43
+ FunctionName=self.function_name,
44
+ MemorySize=new_memory
45
+ )
46
+ logging.info(f"Updated Lambda {self.function_name} memory to {new_memory}MB")
47
+ except Exception as e:
48
+ logging.error(f"Error updating Lambda memory: {e}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: adapto
3
- Version: 0.1.3
3
+ Version: 0.1.4
4
4
  Summary: AI-driven auto-scaling library for dynamic resource allocation.
5
5
  Home-page: https://github.com/hrshlmeht/adapto
6
6
  Author: Harshal Mehta
@@ -2,6 +2,8 @@ LICENSE
2
2
  README.md
3
3
  setup.py
4
4
  adapto/__init__.py
5
+ adapto/aws_lambda_monitor.py
6
+ adapto/aws_lambda_scaler.py
5
7
  adapto/predictor.py
6
8
  adapto/scaler.py
7
9
  adapto/utils.py
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='adapto',
5
- version='0.1.3',
5
+ version='0.1.4',
6
6
  packages=find_packages(),
7
7
  install_requires=['psutil', 'numpy'],
8
8
  description='AI-driven auto-scaling library for dynamic resource allocation.',
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes