Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Cloud Day 2022 -- Serverless RUST

Aletheia
October 27, 2022

Cloud Day 2022 -- Serverless RUST

Adopt Rust language with serverless

Aletheia

October 27, 2022
Tweet

More Decks by Aletheia

Other Decks in Technology

Transcript

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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
  7. CLOUD DAY 2022 8 Serverless means Servicefull Patrick Debois -

    2016 Server VM OS frameworks code your du t some one else duty
  8. 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!
  9. CLOUD DAY 2022 9 How does a Lambda request work?

    INIT I REQUEST II REQUEST nth REQUEST INVOKE INVOKE INVOKE … SHUTDOWN
  10. 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
  11. 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
  12. 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
  13. 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.
  14. 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.
  15. 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.
  16. 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
  17. 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
  18. 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.
  19. X

  20. X

  21. X

  22. X

  23. X

  24. X

  25. X

  26. X

  27. X

  28. 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
  29. 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
  30. 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.
  31. 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.
  32. 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.
  33. 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