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

Serverless Performance with Headless Chrome

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.

Clay Smith

October 10, 2017
Tweet

More Decks by Clay Smith

Other Decks in Programming

Transcript

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

    View full-size slide

  2. SERVERLESS PERF STRATEGY
    ƛ ƛ is it fast?
    ƛ ƛ is it fast concurrently?
    ƛ ƛ what's the worst
    case? why?

    View full-size slide

  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

    View full-size slide

  4. AWS LAMBDA: BATTERIES
    INCLUDED DATA SOURCES
    Amazon Cloudwatch Logs
    Amazon Cloudwatch Metrics
    AWS X-Ray Traces

    View full-size slide

  5. DISTRIBUTED TRACE
    VISUALIZTION
    1200ms
    400ms
    370ms
    Service A
    Service B
    Service C
    Time

    View full-size slide

  6. HELLO, COLD START
    AWS X-Ray Trace: AWS Function invoked from the Developer Console

    View full-size slide

  7. COLD VS WARM START
    Notice: Function gets
    called almost
    immediately after the
    service receives the
    trigger.

    View full-size slide

  8. COLD STARTS: MORE
    ANALYSIS NEEDED
    Aggregate function
    latencies from X-Ray to
    understand trends

    View full-size slide

  9. VISUALIATING TRACES IN
    AGGREGATE
    1) How long does it
    take for my function to
    initialize?
    2) Where is time
    generally being spent?

    View full-size slide

  10. FOR THIS FUNCTION, COLD
    STARTS ARE RARE
    Over a 24 hour period,
    the function rarely
    experiences cold
    starts.

    View full-size slide

  11. AWS LAMBDA: COMMON
    SETTINGS TO MODIFY
    Language Runtime
    "Memory" Dropdown
    Function size (mb)

    View full-size slide

  12. DURATION: BEFORE AND
    AFTER INCREASING MEMORY
    768mb
    1152mb
    Chromium needed more memory!

    View full-size slide

  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!

    View full-size slide

  14. THANKS!
    slides: @smithclay + speakerdeck.com
    Original blog post: https://blog.newrelic.com/2017/06/20/lambda-
    functions-xray-traces-custom-serverless-metrics/

    View full-size slide