itt 2015 - simon stewart - building android apps at speed and scale

50
Building Android Apps At Scale and Speed Simon Stewart @shs96c Software Engineer, Facebook

Upload: istanbul-tech-talks

Post on 13-Jan-2017

233 views

Category:

Engineering


0 download

TRANSCRIPT

Page 1: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Building Android Apps At Scale and Speed

Simon Stewart @shs96c

Software Engineer, Facebook

Page 2: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

One Guiding Principle

Page 3: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

We don't want people waiting on computers

<

Page 4: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

We want computers waiting on people

<

Page 5: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Scalable Source Organisation

Page 6: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Server

Sharing Code Today

Android

c++

iOS

Page 7: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Server

Sharing Code Today

AndroidiOS

c++c++

Page 8: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Server

Sharing Code Today

AndroidiOS

c++ c++c++

Page 9: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Sharing Code Tomorrow

fbsource

c++

Page 10: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

All our source in a single repository (a "monorepo")

Page 11: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Why a monorepo?

Easier: code sharing, versioning, contributing

Simpler: large scale changes

Consistent: uniform tooling

Page 12: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Scalable Source Control

Page 13: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Mercurial

>1M >100KSource control commands

per daycommits per week

Page 14: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Large Repos Are Slow

▪Lots of commits a day

Pulls are slow

Checkouts are slow

▪Years of history

Clones are slow

Requires lots of disk space

Page 15: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

We want computers waiting on people

<

Page 16: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Shallow CheckoutsClone just the latest version

Work locally without complete history

Need more history? Download on demand

HEAD

HEAD-1

HEAD-2

HEAD-3

Page 17: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Sparse CheckoutsWork on just the files you need

Build system integrations knows how to check out more

~/fbsource ios/... common/...

~/fbsource/.hg

Page 18: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

WatchmanOS independent filesystem change notification

Integrates with mercurial

File checking operations scale linearly with number of files changed

Page 19: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Remote FilelogClone and pull just download metadata

Download files when required

Clones and pulls: 10x faster

Page 20: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Large Repos Are Fast

50times faster than git

2000hg improvements

Up to More than

Page 21: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Scalable Builds

Page 22: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Buck▪Next generation build system

▪Designed for modern hardware

▪SSD

▪Plentiful RAM

▪Many cores

▪Automatically parallelizes builds

▪And it's Open Source

Page 23: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale
Page 24: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Build Files

java_binary( name = 'example-binary', deps = [ ':example', ], )

java_library( name = 'example', srcs = glob(['*.java']), deps = [ '//third-party/guava:guava', ], visibility = [ '//javatests/...', ], )

Build file. Typically named BUCK

Page 25: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Build Files

java_binary( name = 'example-binary', deps = [ ':example', ], )

java_library( name = 'example', srcs = glob(['*.java']), deps = [ '//third-party/guava:guava', ], visibility = [ '//javatests/...', ], )

Build file. Typically named BUCK

A build rule of type "java_binary"

Page 26: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Build Files

java_binary( name = 'example-binary', deps = [ ':example', ], )

java_library( name = 'example', srcs = glob(['*.java']), deps = [ '//third-party/guava:guava', ], visibility = [ '//javatests/...', ], )

Build file. Typically named BUCK

A build rule of type "java_binary"

A target defined in the same build file

Page 27: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Build Files

java_binary( name = 'example-binary', deps = [ ':example', ], )

java_library( name = 'example', srcs = glob(['*.java']), deps = [ '//third-party/guava:guava', ], visibility = [ '//javatests/...', ], )

Build file. Typically named BUCK

A build rule of type "java_binary"

A target defined in the same build file

Build rule of type "java_library"

Page 28: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Build Files

java_binary( name = 'example-binary', deps = [ ':example', ], )

java_library( name = 'example', srcs = glob(['*.java']), deps = [ '//third-party/guava:guava', ], visibility = [ '//javatests/...', ], )

Build file. Typically named BUCK

A build rule of type "java_binary"

A target defined in the same build file

A target defined in another build file

Build rule of type "java_library"

Page 29: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Build Files

java_binary( name = 'example-binary', deps = [ ':example', ], )

java_library( name = 'example', srcs = glob(['*.java']), deps = [ '//third-party/guava:guava', ], visibility = [ '//javatests/...', ], )

Build file. Typically named BUCK

A build rule of type "java_binary"

A target defined in the same build file

A target defined in another build file

Build rule of type "java_library"

All targets have visibility

Page 30: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Target and Action Graph

Target Graph: a naive representation of targets defined in build files.

Action Graph: an optimized graph of actions to perform as the build

Page 31: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Language-Aware Smartspublic class Foo {

private String someField;

public void doSomething(int times) {

System.out.println("Wow! " + times);

}

}

Buck calculates the ABI, and keys rebuilds of dependencies off that

Packaging rules that depend on this will always be re-run.

Page 32: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Language-Aware Smartspublic class Foo {

private boolean theCakeIsALie = true;

public void doSomething(int times) {

System.out.println("Wow! " + times);

}

}

Private field changed: ABI remains the same as before

Page 33: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Language-Aware Smartspublic class Foo {

private boolean theCakeIsALie = true;

public void doSomething(int num) {

System.out.println("Wow! " + num);

}

}

Parameter name changed: ABI remains the same as before.

Page 34: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Language-Aware Smartspublic class Foo {

private boolean theCakeIsALie = true;

public void doSomething(String num) {

System.out.println("Wow! " + num);

}

}

Parameter type changed: ABI changes too!

Page 35: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Language-Aware Smartspublic class Foo {

private boolean theCakeIsALie = true;

public void doSomething(String num) {

System.err.println("Wow! " + num);

}

}

Body of method changed: ABI remains the same.

Page 36: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Pervasive Caching• Only 3% of each build is unique.

• Local and distributed caches slash build times.

Page 37: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Exopackage▪Exopackage is an optimization for building and installing development builds of Android apps.

Page 38: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Buck Smarts

Build rule knows all of the inputs that can affect its output

Changes to dx and proguard for faster compilation

Java ABI smarts

Android resource smarts

Daemon to watch file changes

Page 39: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Scalable Continuous Integration

Page 40: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

<10 MinutesFeedback to Developers

>1000test results per second

5 Yearsmachine work per day

Page 41: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Life Cycle of a Diff

Write Code Test Locally Diff and review Sandcastle Land

Page 42: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Sandcastle

RapidHigh-Signal Frequent

Page 43: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Sandcastle Design

Single Master

Master

Worker Worker WorkerWorker

Page 44: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Sandcastle Design

Single Master Distributed Queue

Master

Worker Worker Worker Worker

Worker

Worker

Worker

Worker

Worker

Worker

Distributed Queue

Page 45: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale
Page 46: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Test Runs

Flakiness SpeedCoverage

Page 47: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Landcastle

Land

Target Determinator

Test Test Test

Push

Page 48: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

We don't want people waiting on computers

<

Page 49: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

We want computers waiting on people

<

Page 50: ITT 2015 - Simon Stewart - Building Android Apps at Speed and Scale

Summary

Tool OSS? Link!

Buck Yes https://facebook.github.io/buck/

Mercurial Yes http://mercurial.selenic.com/

Watchman Yes https://facebook.github.io/watchman/

hgwatchman Yes https://bitbucket.org/facebook/hgwatchman

remote filelog Yes https://bitbucket.org/facebook/remotefilelog

Sandcastle No