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

Optimizando Cargas de Trabajo en Lambda

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on.

Optimizando Cargas de Trabajo en Lambda

Avatar for Franchesco romero

Franchesco romero

April 02, 2026
Tweet

More Decks by Franchesco romero

Other Decks in Programming

Transcript

  1. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. Optimizando Cargas de Trabajo Serverless Técnicas para mejorar Rendimiento y Eficiencia Franchesco Romero AWS Community Builder & User Group Leader
  2. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. Intro
  3. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. • Mínima administración de infraestructura • Escala automáticamente • Pago por utilización • Casos de uso ◦ Procesamiento de datos ◦ Web interactiva y backends/APIs ◦ Aplicaciones basadas en eventos ◦ etc Serverless
  4. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Lambda https://blog.stackademic.com/following-are-key-factors-affecting-the-performance-of-serverless-applications-8582b0a33e21
  5. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. Aprovechamiento de Capas Lambda
  6. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. • Las capas le permiten administrar mejor su código de función Lambda al separar su código de función de sus recursos. • Se puede compartir código, librerías y otros componentes con capas en múltiples funciones. Layers
  7. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. • Las extensiones de AWS Lambda se pueden utilizar para integrar funciones de Lambda con sus herramientas preferidas para monitoreo, observabilidad, seguridad y gobernanza. • Además, pueden ejecutar código adicional durante el ciclo de vida de una invocación de función. Extensiones
  8. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Extensiones https://aws.amazon.com/blogs/compute/building-extensions-for-aws-lambda-in-preview/
  9. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. Ajuste Fino de Funciones Lambda
  10. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Técnicas de Optimización
  11. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. • AWS X-Ray ◦ Ayuda a comprender cómo funcionan su aplicación y sus servicios subyacentes y dónde se producen los cuellos de botella. Además, puede usarlo para rastrear solicitudes de principio a fin y obtener un mapa de servicios en su aplicación. Fine-tuning
  12. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. Optimización de Cold Starts
  13. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Ocurren cuando AWS tiene que configurar un nuevo contexto de ejecución para su función, lo que resulta en un tiempo de inicio más largo. • Razones: ◦ Cambio en código ◦ Scale-up ◦ Rebalanceo de AZs ◦ Fallos Cold Starts https://docs.aws.amazon.com/lambda/latest/operatorguide/execution-environments.html
  14. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Cold Starts por runtime https://mikhail.io/serverless/coldstarts/aws/
  15. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. • Funciones activas configurando un evento de CloudWatch (PING) o usando EventBridge que activa la función cada X minutos. • Trade-offs: ▪ Periodico ▪ Mejor configuración? ▪ Confiable? ▪ Posibles cambios en código ▪ No puedo escoger el target Minimizando Cold-Starts
  16. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. • Costo: ◦ Se ejecuta 8640 veces al mes = $0.18 ◦ 10 lambdas: cada una invocada 8640 veces al mes = $14.4 dólares ◦ Total = $14.58 ◦ + costos de Cloudwatch Minimizando Cold-Starts
  17. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. • Provisioned concurrency: ◦ Característica que permite mantener una cantidad específica de entornos de ejecución inicializados y listos para responder Minimizando Cold Starts https://aws.amazon.com/blogs/compute/operating-lambda-performance-optimization-part-1/
  18. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. • Toma en cuenta el escalado: ◦ Utilización ◦ Invocaciones programadas • Costo: ◦ Pago por uso ◦ Recomendable en run-time(s) que normalmente tardan más en inicializarse Minimizando Cold-Starts
  19. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. • Por cada unidad de simultaneidad aprovisionada, hay un mínimo de dos entornos de ejecución preparados en zonas de disponibilidad separadas. • No se puede utilizar con la versión $LATEST. • No funciona con Lambda Edge Minimizando Cold-Starts https://aws.amazon.com/blogs/compute/operating-lambda-performance-optimization-part-1/
  20. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. • SnapStart es un mecanismo de instantáneas y restauración que reduce drásticamente el tiempo de inicio en frío de las funciones de Java en AWS. ◦ Mejora hasta en un 90% ▪ Hasta 10x más rápido ◦ Disponible en: consola, SAM, CDK ▪ No require cambios en codigo ◦ Se utilizará la versión almacenada en caché. SnapStart
  21. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. • LLRT (Low Latency Runtime) es un tiempo de ejecución de JavaScript liviano. • LLRT ofrece un inicio hasta 10 veces más rápido y un costo general hasta 2 veces menor • Escrito en RUST LLTR https://github.com/awslabs/llrt/tree/main
  22. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. Técnicas de Optimización de Costos
  23. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. • Right sizing ◦ AWS Compute Optimizer* ◦ Lambda Insights ◦ DevOps Guru* ◦ AWS Lambda Power Tuning Configuración
  24. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. • AWS Lambda Power Tuning Configuración https://github.com/alexcasalboni/aws-lambda-power-tuning
  25. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. • Graviton2 ◦ 34% Mejor precio/performance ▪ Verificación: AWS Lambda Power Tuning (x86 vs arm64) ◦ Requiere migrar a arm64 ▪ código- lenguajes compilados ▪ Contenedores (build) ▪ Algunas librerías • Saving Plans - hasta 17% de ahorro Configuración
  26. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. • Funciones pequeñas ◦ Eliminar código innecesario ◦ Frameworks más ligeros ◦ Dependencias mínimas • Empaquetado en un único archivo • Runtimes actualizados • Lazy-load Optimizaciones de código
  27. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Optimizaciones de código
  28. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. • Excluir archivos no necesarios ◦ test, build, etc • Minificacion • Reusar conexiones Optimizaciones de código https://www.sosnowski.dev/post/optimizing-aws-lambda
  29. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. • BD Relacionales ◦ RDS Proxy ▪ Agrupación de conexiones ▪ Escalabilidad y disponibilidad ▪ Almacenamiento en caché de consultas Optimizaciones de código https://github.com/aws-samples/serverless-patterns/tree/main/apigw-http-api-lambda-rds-proxy-cdk
  30. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. • Para algunas funciones Lambda ◦ llamadas desde API Gateway, ◦ AppSync ◦ Lambda@Edge llamadas desde CloudFront Caché
  31. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. Mejores Prácticas
  32. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. • En lugar de medir el desempeño con respecto a un número promedio, puede resultar más útil medir los valores atípicos • Utilizando percentiles, se puede identificar la latencia experimentada en el rango p95 o p99, por ejemplo. ▪ Esto muestra el rendimiento para el 5% o el 1% más lento de las solicitudes, respectivamente. Mejores Prácticas
  33. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. • La mejoras de rendimiento están impulsados por el caso de uso. ◦ En cargas de trabajo interactivas, las invocaciones se activan directamente mediante un evento. ◦ Para aplicaciones como aplicaciones web o aplicaciones móviles, el usuario final experimenta directamente el rendimiento de ida y vuelta de las solicitudes. Mejores Prácticas
  34. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. • No usar Lambda, el 100% de las veces: ◦ Orquestramiento - Step Functions ◦ SNS - Filtrado de Mensajes ◦ Amazon Event Bridge - Scheduling Mejores Prácticas
  35. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. Franchesco Romero linkedin.com/in/elchesco Gracias Meetup - Abril