need forbuildspeed agile2012

54
© Reaktor 2012 The Need for (Build) Speed Lasse Koskela (Please go ahead and pre-fill those feedback forms. I appreciate that. It also brings you that much closer to beer.)

Upload: drewz-lin

Post on 22-Jan-2015

148 views

Category:

Documents


2 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Need forbuildspeed agile2012

© Reaktor 2012

The Need for(Build) Speed

Lasse Koskela

(Please go ahead and pre-fill those feedback forms. I appreciate that. It also

brings you that much closer to beer.)

Page 2: Need forbuildspeed agile2012

© Reaktor 2012

Lasse Koskela works as a coach, trainer, consultant and programmer, spending his days helping clients and colleagues at Reaktor create successful software products.

Follow him on Twitter as @lassekoskela

Page 3: Need forbuildspeed agile2012

”© Reaktor 2012

Standing between an audience and their beer is tough so you better talk fast.

~ agile conference proverb

Session Outline1) Impact of build time2) Profiling a build3) Optimizing test code4) Tweaking infrastructure

Page 4: Need forbuildspeed agile2012

© Reaktor 2012

Impact of build time

Page 5: Need forbuildspeed agile2012

© Reaktor 2012

Delayed feedback is bad for you• The faster you know that your software is

(still) working as it should the faster your brain can move on to the next thing.

• The longer you have to wait for feedback the higher the chance of doing rework and context-switching.

Page 6: Need forbuildspeed agile2012

”© Reaktor 2012

http://gojko.net/2009/12/07/improving-testing-practices-at-google/

Delayed feedback costs $$$

[Google] estimated that a bug found during TDD costs $5 to fix, which surges to $50 for tests during a full build and $500 during an integration test. It goes to $5000 during a system test. Fixing bugs earlier would save them an estimated $160M per year.

Page 7: Need forbuildspeed agile2012

© Reaktor 2012

Profiling a build

Page 8: Need forbuildspeed agile2012

© Reaktor 2012

How do we know what’s up?• Shooting in the dark works amazingly well

...if you’re lucky.• The rest of us need to understand what is

making our build slow before reaching for our guns.

Page 9: Need forbuildspeed agile2012

© Reaktor 2012

What exactly do we want to know?• How much time it takes altogether?• Which build activities take up the majority

of that total?• Which of these have potential for

optimization?

Page 10: Need forbuildspeed agile2012

© Reaktor 2012

Demo

Profiling an Apache Ant build with built-in utilities and open source tools

Page 11: Need forbuildspeed agile2012

© Reaktor 2012

Demo

Profiling an Apache Ant build with built-in utilities and open source tools

$ ant -listener net.sf.antcontrib.perf.AntPerformanceListener

Page 12: Need forbuildspeed agile2012

© Reaktor 2012

Demo

Profiling an Apache Ant build with built-in utilities and open source tools

$ ant -listener net.sf.antcontrib.perf.AntPerformanceListener

$ ant -logger org.apache.tools.ant.listener.ProfileLogger

Page 13: Need forbuildspeed agile2012

© Reaktor 2012

Demo

Profiling an Apache Maven build with built-in utilities and open source tools

Page 14: Need forbuildspeed agile2012

© Reaktor 2012

Demo

Profiling an Apache Maven build with built-in utilities and open source tools

<build> <extensions> <extension> <groupId>com.github.lkoskela</groupId> <artifactId>maven-build-utils</artifactId> <version>1.4</version> </extension> </extensions> </build>

Page 15: Need forbuildspeed agile2012

© Reaktor 2012

Optimizing test code

Page 16: Need forbuildspeed agile2012

© Reaktor 2012

Tests can be slow because they...

Page 17: Need forbuildspeed agile2012

© Reaktor 2012

Tests can be slow because they...

do many things.

a)

Page 18: Need forbuildspeed agile2012

© Reaktor 2012

Tests can be slow because they...

do many things.

a)

do slow things.

b)

Page 19: Need forbuildspeed agile2012

© Reaktor 2012

Page 20: Need forbuildspeed agile2012

© Reaktor 2012

Examples ofdoing too much

Tests do setup that isn’t relevant to the test.

Tests build input from unnecessarily raw materials.

Tests do the same thing many times when once is enough.

Tests use a slow real object when a stub would suffice.

Page 21: Need forbuildspeed agile2012

© Reaktor 2012

Examples ofdoing too much

Tests do setup that isn’t relevant to the test.

Tests build input from unnecessarily raw materials.

Tests do the same thing many times when once is enough.

Tests use a slow real object when a stub would suffice.

Page 22: Need forbuildspeed agile2012

© Reaktor 2012

Examples ofdoing too much

Tests do setup that isn’t relevant to the test.

Tests build input from unnecessarily raw materials.

Tests do the same thing many times when once is enough.

Tests use a slow real object when a stub would suffice.

Page 23: Need forbuildspeed agile2012

© Reaktor 2012

Examples ofdoing too much

Tests do setup that isn’t relevant to the test.

Tests build input from unnecessarily raw materials.

Tests do the same thing many times when once is enough.

Tests use a slow real object when a stub would suffice.

Page 24: Need forbuildspeed agile2012

© Reaktor 2012

Examples ofdoing too much

Tests do setup that isn’t relevant to the test.

Tests build input from unnecessarily raw materials.

Tests do the same thing many times when once is enough.

Tests use a slow real object when a stub would suffice.

Page 25: Need forbuildspeed agile2012

© Reaktor 2012

Examples ofdoing too much

Tests do setup that isn’t relevant to the test.

Tests build input from unnecessarily raw materials.

Tests do the same thing many times when once is enough.

Tests use a slow real object when a stub would suffice.

Examples ofslow things

Tests invoke Thread.sleep(...) to wait for task completion.

Components talk to each other over a network protocol.

Tests run against a production-like database.

Tests access afile system.

Page 26: Need forbuildspeed agile2012

© Reaktor 2012

Examples ofdoing too much

Tests do setup that isn’t relevant to the test.

Tests build input from unnecessarily raw materials.

Tests do the same thing many times when once is enough.

Tests use a slow real object when a stub would suffice.

Examples ofslow things

Tests invoke Thread.sleep(...) to wait for task completion.

Components talk to each other over a network protocol.

Tests run against a production-like database.

Tests access afile system.

Page 27: Need forbuildspeed agile2012

© Reaktor 2012

Examples ofdoing too much

Tests do setup that isn’t relevant to the test.

Tests build input from unnecessarily raw materials.

Tests do the same thing many times when once is enough.

Tests use a slow real object when a stub would suffice.

Examples ofslow things

Tests invoke Thread.sleep(...) to wait for task completion.

Components talk to each other over a network protocol.

Tests run against a production-like database.

Tests access afile system.

Page 28: Need forbuildspeed agile2012

© Reaktor 2012

Examples ofdoing too much

Tests do setup that isn’t relevant to the test.

Tests build input from unnecessarily raw materials.

Tests do the same thing many times when once is enough.

Tests use a slow real object when a stub would suffice.

Examples ofslow things

Tests invoke Thread.sleep(...) to wait for task completion.

Components talk to each other over a network protocol.

Tests run against a production-like database.

Tests access afile system.

Page 29: Need forbuildspeed agile2012

© Reaktor 2012

Examples ofdoing too much

Tests do setup that isn’t relevant to the test.

Tests build input from unnecessarily raw materials.

Tests do the same thing many times when once is enough.

Tests use a slow real object when a stub would suffice.

Examples ofslow things

Tests invoke Thread.sleep(...) to wait for task completion.

Components talk to each other over a network protocol.

Tests run against a production-like database.

Tests access afile system.

Page 30: Need forbuildspeed agile2012

© Reaktor 2012

Demo

An example of irrelevant setup that’s inherited through a hierarchy of abstract test classes.

Page 31: Need forbuildspeed agile2012

© Reaktor 2012

Demo

An example of tests wasting valuable time by Thread#sleep’ing too much.

Page 32: Need forbuildspeed agile2012

© Reaktor 2012

Demo

An example of a test that uses a slow(ish) real implementation that talks to the network stack.

Page 33: Need forbuildspeed agile2012

© Reaktor 2012

Tweaking infrastructure

Page 34: Need forbuildspeed agile2012

© Reaktor 2012

Is your build’s bottleneck...

I/OCPU

Page 35: Need forbuildspeed agile2012

© Reaktor 2012

Page 36: Need forbuildspeed agile2012

© Reaktor 2012

Peaking “user time” suggests CPU running hot

Page 37: Need forbuildspeed agile2012

© Reaktor 2012

Page 38: Need forbuildspeed agile2012

© Reaktor 2012

Peaking “idle time” suggests CPU is waiting

Page 39: Need forbuildspeed agile2012

© Reaktor 2012

Page 40: Need forbuildspeed agile2012

© Reaktor 2012

Peaking “system calls” suggests lots of I/O

Page 41: Need forbuildspeed agile2012

© Reaktor 2012

Lifting the CPU bottleneckby using more hardware

Page 42: Need forbuildspeed agile2012

© Reaktor 2012

Lifting the CPU bottleneckby using more hardware

Page 43: Need forbuildspeed agile2012

© Reaktor 2012

Demo

An example of a Maven build that employs multiple CPU cores.

Page 44: Need forbuildspeed agile2012

© Reaktor 2012

Lifting the CPU bottleneckby using better hardware

Page 45: Need forbuildspeed agile2012

© Reaktor 2012

Lifting the CPU bottleneckby using better hardware

Page 46: Need forbuildspeed agile2012

© Reaktor 2012

Lifting the CPU bottleneckby using better hardware

Amazon EC2 Small Instance1.7 GB memory1 virtual core with 1 EC2 compute units

Amazon EC2 Medium Instance3.75 GB memory1 virtual core with 2 EC2 compute units

Page 47: Need forbuildspeed agile2012

© Reaktor 2012

Demo

An example of a Maven build that is run in the cloud on a (more or less) powerful computer.

Page 48: Need forbuildspeed agile2012

© Reaktor 2012

Lifting the I/O bottleneckby using better hardware

Page 49: Need forbuildspeed agile2012

© Reaktor 2012

Lifting the I/O bottleneckby using better hardware

Page 50: Need forbuildspeed agile2012

© Reaktor 2012

Demo

An example of a build that is run from a (more or less) fast disk.

Page 51: Need forbuildspeed agile2012

© Reaktor 2012

Lifting the I/O bottleneckby using more hardware

Page 52: Need forbuildspeed agile2012

© Reaktor 2012

Lifting the I/O bottleneckby using more hardware

Page 53: Need forbuildspeed agile2012

© Reaktor 2012

Summary

Page 54: Need forbuildspeed agile2012

© Reaktor 2012

Please, fill thefeedback form for me.

I’d really appreciate that.TITLE: The Need for (Build) SpeedPRESENTER: Lasse Koskela