Running Unit Test on Serverless Infrastructure Adinata Thayib - - PowerPoint PPT Presentation

running unit test on serverless infrastructure
SMART_READER_LITE
LIVE PREVIEW

Running Unit Test on Serverless Infrastructure Adinata Thayib - - PowerPoint PPT Presentation

Running Unit Test on Serverless Infrastructure Adinata Thayib @dieend source: xkcd.com 85% less Running Unit Test on Serverless Infrastructure Adinata Thayib @dieend About Pocket Gems Mobile Game Company War Dragons & Episode


slide-1
SLIDE 1

Running Unit Test on Serverless Infrastructure

Adinata Thayib @dieend

slide-2
SLIDE 2

source: xkcd.com

slide-3
SLIDE 3
slide-4
SLIDE 4
slide-5
SLIDE 5
slide-6
SLIDE 6

85% less

slide-7
SLIDE 7

Running Unit Test on Serverless Infrastructure

Adinata Thayib @dieend

slide-8
SLIDE 8

About Pocket Gems

  • Mobile Game Company

○ War Dragons & Episode

  • 10 years old (and hiring!)
  • > 4K tests
slide-9
SLIDE 9
slide-10
SLIDE 10

Frustration

slide-11
SLIDE 11

What is the problem?

Running full unit tests suite is slow Is it worth solving?

  • Productivity
  • Deployment Speed
slide-12
SLIDE 12

How to make test suite complete faster?

  • 1. Have fewer unit tests
slide-13
SLIDE 13

How to make test suite complete faster?

  • 1. Have fewer unit tests
  • 2. Divide & Conquer a.k.a Parallelize the unit

tests execution

slide-14
SLIDE 14

How do we parallelize test execution?

  • 1. Run it locally with multiple CPUs
  • 2. Run it in multiple machine
  • 3. Run it in serverless infrastructure
slide-15
SLIDE 15

Running locally with multiple CPUs

Nosetests Multiprocess plugin:

  • Collect tests into a Queue object
  • Configure the child process
  • Start process which poll from the test Queue
slide-16
SLIDE 16

Running locally with multiple CPUs

Collect:

slide-17
SLIDE 17

Running locally with multiple CPUs

Collect:

The plugin can't know (unless you tell it) if a context fixture can be called many times concurrently (is re-entrant),

  • r if it can be shared among tests running in different
  • processes. Therefore, if a context has fixtures, the

default behavior is to dispatch the entire suite to a worker as a unit.

slide-18
SLIDE 18

Running with Multiple Machine

No out of the box python solution. Ruby Alternative (Knapsack Pro - for Ruby and JS). Python WIP

slide-19
SLIDE 19

Running with Multiple Machine

slide-20
SLIDE 20

Running with Multiple Machine

slide-21
SLIDE 21

Designing the solution

Constraint:

  • We won't have engineer resources to manage the worker machine full time

Opportunity:

  • We use GAE: all the tests don't have external fixtures
  • We use GAE: 100% python code and aren't using many binary dependencies

Proposed Solution

  • Use AWS Lambda to remove the necessity on managing worker machine
slide-22
SLIDE 22

Running with serverless infrastructure

slide-23
SLIDE 23

Running with serverless infrastructure

slide-24
SLIDE 24

Running with serverless infrastructure

nosetest plugin with custom selector

slide-25
SLIDE 25

Running with serverless infrastructure

Running Test... thread.join() Parse output

slide-26
SLIDE 26

What we learned

slide-27
SLIDE 27

What we learned

1. AWS Lambda Source File Limits 2. Concurrent Executions 3. Network Bandwidth 4. Longest running unit tests is the weakest link 5. Binary Dependencies 6. No re-entrant fixture support

slide-28
SLIDE 28

After 2 years...

slide-29
SLIDE 29

~21min

faster

slide-30
SLIDE 30

> 1000

executions/month

slide-31
SLIDE 31

> 350hr

engineering hours are saved each month

slide-32
SLIDE 32

Assuming engineering hour cost $50/month (Bay Area):

Minute saved each execution 21 mins Monthly Execution 1000 execution Hours 350 hr Monthly Saved Engineering Cost ~$17,500

Monthly Impact

slide-33
SLIDE 33

~$120

monthly cost

slide-34
SLIDE 34

> $17K

Saving per months

slide-35
SLIDE 35

Assuming engineering hour cost $50/month (Bay Area): Initial Investment: 4 engineering weeks

Monthly Saved Engineering Cost ~$17,500 Monthly Cost ~$(120) Total ~$17,380 Engineering Cost to Build ~$8,000 Break Even Point < 1 month

slide-36
SLIDE 36

>70

engineers adopted it

slide-37
SLIDE 37

Frustration

Others might have the same frustration with you. You might solve everyone's problem.

slide-38
SLIDE 38

Channel Discussion: #talk-unit-test-serverless Send me a tweet: @dieend

Q&A

slide-39
SLIDE 39

Thank you

Channel Discussion: #talk-unit-test-serverless Send me a tweet: @dieend