Slide 1

Slide 1 text

#CLOUDDAY2022 BLAZING FAST SERVERLESS WITH RUST LUCA BIANCHI NEOSPERIENCE @BIANCHILUCA

Slide 2

Slide 2 text

#CLOUDDAY2022 SPONSOR DIAMOND PLATINUM GOLD

Slide 3

Slide 3 text

#CLOUDDAY2022 PARTNER

Slide 4

Slide 4 text

NOME CLIENTE 14/11/23 Who am I? Luca Bianchi, PhD Chief Technology Officer @ Neosperience AWS Hero, passionate about serverless and machine learning github.com/aletheia https://it.linkedin.com/in/lucabianchipavia https://speakerdeck.com/aletheia https://www.ctrlalt.museum/ @bianchiluca

Slide 5

Slide 5 text

NOME CLIENTE 14/11/23 Agenda 1. Customer Data Platform 2. Serverless 3. Optimizing your Lambda function 4. Enter Rust 5. Rust on Lambda 6. Benchmarks 7. Machine Learning on Lambda

Slide 6

Slide 6 text

NOME CLIENTE 14/11/23 Enriching customer records

Slide 7

Slide 7 text

CLOUD DAY 2022 7 Getting the single view of customer Customer Data Platforms are a set of products, architectures and tools developed to allow brands to enhance understanding of their customer base. • Customer record analysis and enrichment with AI • A unified view of customer data • Integration between different data sources A CDP provides • Customer record analysis and enrichment with AI

Slide 8

Slide 8 text

X Cloud Data Platform — events work fl ow analytics dashboard connector events data source connector data lake customer data warehouse customer data view source 01 Source 02 Source …n customer (partial) — NVC ETL customer customer enrichment customer data views

Slide 9

Slide 9 text

CLOUD DAY 2022 7 Customer Enrichment An AI powered component predicting Customer Lifetime Value, Customer Churn, and other meaningful metrics • Real-Time processing • Stream data handling Requirements

Slide 10

Slide 10 text

NOME CLIENTE 14/11/23 Serverless

Slide 11

Slide 11 text

CLOUD DAY 2022 7 What is serverless? “Serverless architecture replaces long-running virtual machines with ephemeral compute power that comes into existence on request and disappears immediately after use. Use of this architecture can mitigate some security concerns such as security patching and SSH access control, and can make much more efficient use of compute resources. These systems cost very little to operate and can have inbuilt scaling features.” — ThoughtWorks, 2016

Slide 12

Slide 12 text

CLOUD DAY 2022 8 Serverless means Servicefull Patrick Debois - 2016 Server VM OS frameworks code your du t some one else duty

Slide 13

Slide 13 text

CLOUD DAY 2022 9 Does speed matter? • Consider a simple e-commerce during Black Friday • On Dec 1, 2020 AWS Lambda pricing slots changed from 100ms down to 1ms • 100K users * 200 invocations per day * 30 days = 600M invocations • Before Dec 1, 2020 every invocation timed at least 100ms, now we can have functions running for ~30ms • 600M * 100ms * 0.0000000167$ = 1000$ • 600M * 30ms * 0.0000000167$ = 300$ yes, it matters a lot!

Slide 14

Slide 14 text

NOME CLIENTE 14/11/23 Optimizing Lambda

Slide 15

Slide 15 text

CLOUD DAY 2022 9 How does a Lambda request work? INIT I REQUEST II REQUEST nth REQUEST INVOKE INVOKE INVOKE … SHUTDOWN

Slide 16

Slide 16 text

CLOUD DAY 2022 9 Timeline of a Lambda function time Download the code Start new execution environment Execute init code Execute handler code INIT INVOKE How to optimize the function? • Small packages • Use Lambda Execution Context • Avoid Fat Lambda • Cache assets • Use parallelism

Slide 17

Slide 17 text

NOME CLIENTE 14/11/23 Enter Rust

Slide 18

Slide 18 text

CLOUD DAY 2022 9 Evolving C++ into a modern language • Designed to be a safe and highly performant language • Statically typed • Compiled • Cross-platform support • Ecosystem

Slide 19

Slide 19 text

CLOUD DAY 2022 9 Rust Ownership Model A set of rules that governs how Rust manages memory. Garbage collector memory management • declare and forget model: variables are declared, then the language runtime takes care • the language has to keep track of variables • once variables are not used anymore, they are recycled • you don’t have to worry about stack and heap allocation Manual memory management • declare the variable, maintain ownership along with your code • create data and pass a reference, retaining ownership • let the recipient borrow it for a while • once the code returns all retained references are released • choose between stack and heap allocation

Slide 20

Slide 20 text

CLOUD DAY 2022 9 Struct and Traits A struct, or structure, is a custom data type that lets you package together and name multiple related values that make up a meaningful group. A trait abstractly defines shared behaviour. For example, we can use trait bounds to specify that a generic type can be any type that has particular behaviour.

Slide 21

Slide 21 text

CLOUD DAY 2022 9 Enum and Pattern Matching Enum allows enumerating all possible variants. Match pattern allow you to compare a value against a set of patterns.

Slide 22

Slide 22 text

CLOUD DAY 2022 9 Option and Result Type Option represents an optional value: every Option is either Some and contains a value or None. Type Result can represent either success/Ok or failure/Err.

Slide 23

Slide 23 text

NOME CLIENTE 14/11/23 Rust on Lambda

Slide 24

Slide 24 text

X AWS SAM AWS Serverless Application Model (SAM) is a CLI tool to handle serverless project creation through CloudFormation transforms. • Start from Rust boilerplate with simple hello-world. • Provides a set of dependencies (crates) useful within AWS and Lambda • Provides a make file to handle code compile task • Ease out deployment tasks • Support for local run through docker

Slide 25

Slide 25 text

X AWS SAM The first step is to run make thus invoking compiler through Makefile. carrgo lambda crate uses Zig tool to compile and cross-compile source code. Available options for AWS Lambda are: • ARM: aarch64-unknown-linux-gnu • X86: x86_64-unknown-linux-gnu

Slide 26

Slide 26 text

X AWS SAM The second and final step is sam deploy which uploads our binary functions code to S3, and starts AWS Cloudformation changesets to script infrastructure. Deployment step can be interactively managed with the —guided option.

Slide 27

Slide 27 text

NOME CLIENTE 14/11/23 Lambda handler

Slide 28

Slide 28 text

X

Slide 29

Slide 29 text

X

Slide 30

Slide 30 text

X

Slide 31

Slide 31 text

X

Slide 32

Slide 32 text

X

Slide 33

Slide 33 text

X

Slide 34

Slide 34 text

X

Slide 35

Slide 35 text

X

Slide 36

Slide 36 text

X

Slide 37

Slide 37 text

NOME CLIENTE 14/11/23 Benchmarks

Slide 38

Slide 38 text

CLOUD DAY 2022 9 AWS Serverless Rust Demo

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

NOME CLIENTE 14/11/23 Machine learning on Lambda

Slide 43

Slide 43 text

CLOUD DAY 2022 X PolaRS • Built on Apache Arrow2 implementation of the Apache Arrow specification, enabling efficient resource use and processing performances • Exposes a complete Python API to manipulate data frames, enforcing parallel execution and efficient cache management • Written in Rust, offering a feature-complete DataFrame library for the ecosystem • ~3x faster than Pandas, with better memory management

Slide 44

Slide 44 text

CLOUD DAY 2022 9 SmartCore • A scikit-learn porting to Rust, with increased speed and data parallelization • A set of tools for numerical computing, optimization, and machine learning

Slide 45

Slide 45 text

CLOUD DAY 2022 X Neural Networks (?) • In the aim to provide a general purpose development language and leverage Rust speed, a direct binding to torch is under development, named tch-rs • Rust bindings for the C++ api of PyTorch. The goal of the tch crate is to provide some thin wrappers around the C++ PyTorch api (a.k.a. libtorch). It aims at staying as close as possible to the original api. • No idiomatic rust bindings on top of this.

Slide 46

Slide 46 text

NOME CLIENTE 14/11/23 Where to go from here?

Slide 47

Slide 47 text

X Rust Language • The Rust Programming Language • Rust for Rustaceans

Slide 48

Slide 48 text

X serverlessland.com A collection of patterns built on AWS SAM to implement best practices on serverless. Patterns are out-of-the-box solutions ready to be instantiated and integrated into existing or new projects.

Slide 49

Slide 49 text

X Rust on AWS A list of tools developed and promoted by AWS to support development of projects through AWS SDK, IDE integration tools, and tutorials.

Slide 50

Slide 50 text

Thank you! 25125 BRESCIA, VIA ORZINUOVI, 20 20137 MILANO, VIA PRIVATA DECEMVIRI, 20 [email protected] WWW.NEOSPERIENCE.COM Github: github.com/aletheia LinkedIn: https://it.linkedin.com/in/lucabianchipavia SpeakerDeck: https://speakerdeck.com/aletheia Twitter: @bianchiluca Luca Bianchi