Skip to content

Commit d7f259b

Browse files
committed
Added code for comparison between x86_64 with arm64 (graviton2) lambda functions
1 parent bb9939c commit d7f259b

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed
42.7 KB
Loading

xgboost-inference-arm64-docker-lambda/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This project contains source code and supporting files for a serverless applicat
88
- train-code - Code for training XGBoost model based on breast cancer dataset.
99
- events - Invocation events that you can use to invoke the function.
1010
- template.yaml - A template that defines the application's AWS resources.
11+
- invoke_x86_64_arm64_lambdas.py - Code to invoke x86_64 and Arm64 (Graviton2) Lambda Functions and compare performance.
1112

1213
The application uses several AWS resources, including Lambda functions. These resources are defined in the `template.yaml` file in this project. You can update the template to add AWS resources through the same deployment process that updates your application code.
1314

@@ -63,6 +64,20 @@ xgboost-inference-arm64-docker-lambda$ sam local invoke XGBoostInferenceArm64Fun
6364

6465
![arm64 Architecture](../img/xgboost_arm_64_arch_view.png)
6566

67+
## Compare performance of x86_64 Lambda Function with Arm64 (Graviton2) one
68+
69+
You can achieve up to 34% better price/performance with AWS Lambda Functions powered by AWS Graviton2 processor.
70+
71+
To test the performance improvements of the XGBoost x86_64 Lambda Function with an Arm64 (Graviton2) one yourself, please execute the following steps:
72+
1. Deploy the XGBoost x86_64 Lambda Function, as described [here](../xgboost-inference-docker-lambda/)
73+
2. Open `invoke_x86_64_arm64_lambdas.py` file.
74+
3. Replace `<XGBoost_x86_64_Lambda_ARN>` with XGBoost x86_64 Lambda Function ARN.
75+
4. Replace `<XGBoost_arm64_Lambda_ARN>` with XGBoost Arm64 (Graviton2) Lambda Function ARN.
76+
5. Run the following command: `python invoke_x86_64_arm64_lambdas.py`
77+
78+
![xgboost x86_64 vs. arm64 improvement](../img/xgboost_x86_64_arm64_improvement.png)
79+
80+
**We can see that the Arm64 (Graviton2) Lambda Function has performance improvements of 36% over the x86_64 one!**
6681

6782
## Testing your Lambda function in the Cloud
6883

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import boto3
2+
import json
3+
import base64
4+
import re
5+
import sys
6+
7+
client = boto3.client('lambda')
8+
9+
f= open('./events/event.json')
10+
json_input = json.load(f)
11+
12+
13+
def call_XGBoost_x86_64_Lambda():
14+
response = client.invoke(
15+
FunctionName='<XGBoost_x86_64_Lambda_ARN>',
16+
InvocationType='RequestResponse',
17+
LogType='Tail',
18+
Payload=json.dumps(json_input)
19+
)
20+
return(find_duration(response))
21+
22+
23+
def call_XGBoost_arm64_Lambda():
24+
response = client.invoke(
25+
FunctionName='<XGBoost_arm64_Lambda_ARN>',
26+
InvocationType='RequestResponse',
27+
LogType='Tail',
28+
Payload=json.dumps(json_input)
29+
)
30+
31+
return(find_duration(response))
32+
33+
34+
def find_duration(response):
35+
log_result = base64.b64decode(response['LogResult']).decode('utf-8')
36+
result = re.findall(r'Duration: (\d+\.\d+) ms', log_result)
37+
return (float(result[0]))
38+
39+
# Warm the two Lambda Functions first
40+
print("Warming x86_64 and arm64 Lambda Functions")
41+
call_XGBoost_x86_64_Lambda()
42+
call_XGBoost_arm64_Lambda()
43+
44+
print("Warming x86_64 and arm64 Lambda Functions - Done")
45+
print("Sending events to x86_64 and arm64 Lambda Functions")
46+
47+
counter=1
48+
num_calls=100
49+
total_duration_x86_64=0
50+
total_duration_arm64=0
51+
52+
while counter < num_calls:
53+
duration_x86_64 = call_XGBoost_x86_64_Lambda()
54+
# print(f'call_XGBoost_x86_64_Lambda duration: {duration_x86_64}')
55+
total_duration_x86_64 = total_duration_x86_64 + duration_x86_64
56+
57+
duration_arm64 = call_XGBoost_arm64_Lambda()
58+
# print(f'call_XGBoost_arm64_Lambda duration: {duration_arm64}')
59+
total_duration_arm64 = total_duration_arm64 + duration_arm64
60+
61+
sys.stdout.write(('=' * counter) + ('' * (num_calls - counter)) + ("\r [ %d" % counter + "% ] "))
62+
sys.stdout.flush()
63+
64+
counter = counter + 1
65+
66+
print("\nSending events to x86_64 and arm64 Lambda Functions - Done")
67+
68+
avg_duration_x86_64 = total_duration_x86_64/num_calls
69+
avg_duration_arm64 = total_duration_arm64/num_calls
70+
improvement_percentage= "{:.0%}".format(1 - (avg_duration_arm64 / avg_duration_x86_64))
71+
72+
print('Average duration x86_64: {:.2f} ms'.format(total_duration_x86_64/num_calls))
73+
print('Average duration arm64: {:.2f} ms'.format(total_duration_arm64/num_calls))
74+
print(f'*** Improvement of arm64 (Graviton2) over x86_64: {improvement_percentage} ***')

0 commit comments

Comments
 (0)