Serverless Performance with Headless Chrome

2ad55a66b8325eb097612c069ab76231?s=47 Clay Smith
October 10, 2017

Serverless Performance with Headless Chrome

The number of people running interesting binaries in AWS Lambda is increasing, and with the recent release of Headless Chromium—a version of the Chrome browser that can run without a UI—there have been experiments and different open-source projects of individuals running it inside an AWS Lambda environment. Running a large, memory-intensive piece of software designed for desktops inside a serverless function presents interesting performance challenges, including how to minimize cold start time and how to optimize the right amount of memory for the function.

This talk is about optimizing performance of chromium inside Lambda using multiple data sources, including AWS X-Ray traces and custom metrics. While the talk is focused on headless chrome in AWS Lambda, the performance techniques can be applied to any memory or compute-intensive serverless functions.

2ad55a66b8325eb097612c069ab76231?s=128

Clay Smith

October 10, 2017
Tweet

Transcript

  1. SERVERLESS PERFORMANCE LESSONS WITH HEADLESS CHOME @smithclay ServerlessConf NY, Oct

    2017
  2. SERVERLESS PERF STRATEGY ƛ ƛ is it fast? ƛ ƛ

    is it fast concurrently? ƛ ƛ what's the worst case? why?
  3. AWS Lambda Function index.handler (node.js runtime) ./bin/chromedriver process.exec https://medium.com/clog/running-selenium-and-headless-chrome-on-aws-lambda-fb350458e4df ./bin/headless_chrome

    BIG BROWSER, LITTLE FUNCTION + Simple Selenium Script
  4. AWS LAMBDA: BATTERIES INCLUDED DATA SOURCES Amazon Cloudwatch Logs Amazon

    Cloudwatch Metrics AWS X-Ray Traces
  5. DISTRIBUTED TRACE VISUALIZTION 1200ms 400ms 370ms Service A Service B

    Service C Time
  6. HELLO, COLD START AWS X-Ray Trace: AWS Function invoked from

    the Developer Console
  7. COLD VS WARM START Notice: Function gets called almost immediately

    after the service receives the trigger.
  8. COLD STARTS: MORE ANALYSIS NEEDED Aggregate function latencies from X-Ray

    to understand trends
  9. VISUALIATING TRACES IN AGGREGATE 1) How long does it take

    for my function to initialize? 2) Where is time generally being spent?
  10. FOR THIS FUNCTION, COLD STARTS ARE RARE Over a 24

    hour period, the function rarely experiences cold starts.
  11. AWS LAMBDA: COMMON SETTINGS TO MODIFY Language Runtime "Memory" Dropdown

    Function size (mb)
  12. DURATION: BEFORE AND AFTER INCREASING MEMORY 768mb 1152mb Chromium needed

    more memory!
  13. WRAP UP • Collect data for several days for many

    function runs. • Consider enabling x-ray traces for non-trivial functions • Test scenarios where your function has many concurrent executions (i.e. large spike in the number of requests) • Don't be afraid to increase memory: it might end up costing less. •Measure and share!
  14. THANKS! slides: @smithclay + speakerdeck.com Original blog post: https://blog.newrelic.com/2017/06/20/lambda- functions-xray-traces-custom-serverless-metrics/