115
scaling compiled applications Joe Damato @joedamato

scaling compiled applications - highload 2013

  • Upload
    ice799

  • View
    142

  • Download
    1

Embed Size (px)

DESCRIPTION

my talk from highload++ 2013 -- talking about scaling compiled applications but from the point of view of scaling up from supporting 1 platform to supporting MANY platforms. in other words: given an application that supports ubuntu 10.04, what sort of systems, tips, and tricks are needed to help scale support to other ubuntus, redhats, centos, windows, etc.

Citation preview

Page 1: scaling compiled applications - highload 2013

scaling compiled applications

Joe Damato@joedamato

Page 2: scaling compiled applications - highload 2013

about me•Joe Damato

•San Francisco, CA

•i like:

•systems programming

•debugging

•performance analysis

Page 3: scaling compiled applications - highload 2013

@joedamato

Page 4: scaling compiled applications - highload 2013

timetobleed.com

Page 5: scaling compiled applications - highload 2013

sassanosystems.com

Page 6: scaling compiled applications - highload 2013
Page 7: scaling compiled applications - highload 2013
Page 8: scaling compiled applications - highload 2013
Page 9: scaling compiled applications - highload 2013
Page 10: scaling compiled applications - highload 2013
Page 11: scaling compiled applications - highload 2013
Page 12: scaling compiled applications - highload 2013
Page 13: scaling compiled applications - highload 2013
Page 14: scaling compiled applications - highload 2013
Page 15: scaling compiled applications - highload 2013
Page 16: scaling compiled applications - highload 2013
Page 17: scaling compiled applications - highload 2013
Page 18: scaling compiled applications - highload 2013

http://jenkins-ci.org/

Page 19: scaling compiled applications - highload 2013
Page 20: scaling compiled applications - highload 2013
Page 21: scaling compiled applications - highload 2013

Repeatable builds•the most important thing for compiled software

•set up a build server

•with jenkins (or another type of software)

•backup your built objects

•copying them to s3 is not a horrible idea

•regardless of source control system or branching strategy, ensure you can always rebuild any version of your software

Page 22: scaling compiled applications - highload 2013
Page 23: scaling compiled applications - highload 2013

Jenkins problems

•git plugin didn’t work on windows (maybe fixed?)

•branch building is painful, jenkins API can help

•getting windows build agent working is painful

Page 24: scaling compiled applications - highload 2013
Page 25: scaling compiled applications - highload 2013
Page 26: scaling compiled applications - highload 2013

why?

почему?

Page 27: scaling compiled applications - highload 2013
Page 28: scaling compiled applications - highload 2013
Page 29: scaling compiled applications - highload 2013

tools for...•RPMs

•DEBs

•Everything else

•windows installers (MSIs)

•other linux/unix like OS’s

•etc

Page 30: scaling compiled applications - highload 2013

chroot ??

Page 31: scaling compiled applications - highload 2013

chroot: an operation that changes the apparent root directory for the current running process [...].

A program that is run in such a modified environment cannot name (and therefore normally not access) files outside the designated directory tree.

(from wikipedia)

Page 32: scaling compiled applications - highload 2013
Page 33: scaling compiled applications - highload 2013
Page 34: scaling compiled applications - highload 2013
Page 35: scaling compiled applications - highload 2013
Page 36: scaling compiled applications - highload 2013

RPM

https://fedorahosted.org/mock/

mock

Page 37: scaling compiled applications - highload 2013

DEB

https://wiki.ubuntu.com/PbuilderHowto

pbuilder

Page 38: scaling compiled applications - highload 2013

Everything else

•KVM

•Amazon EC2

•other virtualization

Page 39: scaling compiled applications - highload 2013

KVM EC2

Page 40: scaling compiled applications - highload 2013

KVM

•Create a base image on disk

•Clone base image

•Boot the cloned image

•Do the build and copy built object out.

•Delete cloned image when done

•Base image is still pristine and can be reused.

Page 41: scaling compiled applications - highload 2013
Page 42: scaling compiled applications - highload 2013
Page 43: scaling compiled applications - highload 2013

Create builds in cleanroom

•Avoid contaminating builds with artifacts from previous builds.

•chroots help

•use mock or pbuilder for RPMs and DEBs

•KVM, EC2, or equivalent for everything else

•Always create pristine base images and do builds in a copy.

•Use SSDs

Page 44: scaling compiled applications - highload 2013
Page 45: scaling compiled applications - highload 2013

Tool problems

•git-buildpackage can’t set changelog distribution field

•signing key setup is really painful (especially for RPMs)

•deb naming scheme for packages is quite painful

•all tools are undocumented and very hard to actually use

•recent versions of KVM provided by ubuntu fail to boot VMs sometimes

Page 46: scaling compiled applications - highload 2013
Page 47: scaling compiled applications - highload 2013
Page 48: scaling compiled applications - highload 2013

two types of linking....

• dynamic linking

• static linking

Page 49: scaling compiled applications - highload 2013

static linking

•calls to functions in library are resolved at compile time.

•code from the library is copied into the resulting binary.

Page 50: scaling compiled applications - highload 2013

dynamic linking

•calls to functions are resolved at runtime.

•code for a library lives in it’s own object:

•libblah.so.4

•libblah.dll

Page 51: scaling compiled applications - highload 2013
Page 52: scaling compiled applications - highload 2013

http://www.akkadia.org/drepper/no_static_linking.html

Page 53: scaling compiled applications - highload 2013
Page 54: scaling compiled applications - highload 2013

why?

почему?

Page 55: scaling compiled applications - highload 2013
Page 56: scaling compiled applications - highload 2013
Page 57: scaling compiled applications - highload 2013
Page 58: scaling compiled applications - highload 2013

static linking•figure out which libraries your app needs

•pick a supported major release, if possible

•build and package this library

•link it statically against your binary during build

•you now have fewer stones to turn over when debugging

Page 59: scaling compiled applications - highload 2013
Page 60: scaling compiled applications - highload 2013

static linking•you will need to track your upstream deps

•you will probably want to package your upstream deps

•you can then point your chroots and build envs at private deb, rpm, etc repos in your internal infrastructure

•merging upstream changes in becomes its own project

Page 61: scaling compiled applications - highload 2013
Page 62: scaling compiled applications - highload 2013
Page 63: scaling compiled applications - highload 2013
Page 64: scaling compiled applications - highload 2013
Page 65: scaling compiled applications - highload 2013

why?

почему?

Page 66: scaling compiled applications - highload 2013
Page 67: scaling compiled applications - highload 2013
Page 68: scaling compiled applications - highload 2013
Page 69: scaling compiled applications - highload 2013
Page 70: scaling compiled applications - highload 2013
Page 71: scaling compiled applications - highload 2013
Page 72: scaling compiled applications - highload 2013
Page 73: scaling compiled applications - highload 2013
Page 74: scaling compiled applications - highload 2013

Use filessrc/

redhat5/

some_internal_thing.c

ubuntu1204/

some_internal_thing.c

debian6/

some_internal_thing.c

Page 75: scaling compiled applications - highload 2013

Use the build systemDetermine which

file to build at compile time.

Page 76: scaling compiled applications - highload 2013
Page 77: scaling compiled applications - highload 2013
Page 78: scaling compiled applications - highload 2013

Use modules

•break up ifdef soup into separate files

•use the build system to compile the right file at build time

•this seems obvious but many C libraries and programs are full of crazy ifdef soup.

Page 79: scaling compiled applications - highload 2013
Page 80: scaling compiled applications - highload 2013

Use modules

•very easy to fall down a rabbit hole breaking things apart

•can make the build process more complicated and harder to debug

Page 81: scaling compiled applications - highload 2013
Page 82: scaling compiled applications - highload 2013
Page 83: scaling compiled applications - highload 2013

why?

почему?

Page 84: scaling compiled applications - highload 2013
Page 85: scaling compiled applications - highload 2013

Capture debug symbols

•DEB and RPM can both output debug packages that contain debug symbols.

•output these packages.

•store these and make backups.

•(or just don’t strip your binary)

Page 86: scaling compiled applications - highload 2013
Page 87: scaling compiled applications - highload 2013

Use google-coredumper•you can use google-coredumper to catch

segfaults, bus errors, and other bad things.

•you can output a coredump when this happens.

•you can use this coredump and your debug symbols to figure out what is going on.

Page 88: scaling compiled applications - highload 2013

Plan for failure•Have a backup plan

•Capture debug symbols during your automated build process.

•Store them somewhere safe (and make backups).

•Capture coredumps (if possible).

•Use coredumps and debug symbols to figure out what happened.

Page 89: scaling compiled applications - highload 2013
Page 90: scaling compiled applications - highload 2013

Plan for failure

•can significantly increase complexity

•google coredumper can’t help if your kernel is buggy

•some linux distributions don’t allow ptrace

•google coredumper only supports linux

Page 91: scaling compiled applications - highload 2013
Page 92: scaling compiled applications - highload 2013
Page 93: scaling compiled applications - highload 2013
Page 94: scaling compiled applications - highload 2013
Page 95: scaling compiled applications - highload 2013
Page 96: scaling compiled applications - highload 2013

http://jenkins-ci.org/

Page 97: scaling compiled applications - highload 2013
Page 98: scaling compiled applications - highload 2013
Page 99: scaling compiled applications - highload 2013

Check things like...

•Is the binary actually statically linked?

•Does it get copied to the right path?

•Are the right config files autogenerated?

•Does the version string the program outputs match the package version?

•....

Page 100: scaling compiled applications - highload 2013

You also need...correctness testing.

Page 101: scaling compiled applications - highload 2013

RSpec is useful for this.

Page 102: scaling compiled applications - highload 2013

Automated Testing•It will be impossible to build and test every

change on every supported platform.

•Use your build server to do this for you.

•Test things like:

•installing/uninstalling the object

•object is actually statically linked

•correctness testing (RSpec can be useful)

Page 103: scaling compiled applications - highload 2013
Page 104: scaling compiled applications - highload 2013

Automated testing

•Fine line between not enough and too much

•Windows can be painful, but cygwin can help with scripting

•Easy to forget about testing the actual package install/removal

•Can be difficult to get working with branch builds

Page 105: scaling compiled applications - highload 2013

To summarize...

Page 106: scaling compiled applications - highload 2013
Page 107: scaling compiled applications - highload 2013
Page 108: scaling compiled applications - highload 2013
Page 109: scaling compiled applications - highload 2013
Page 110: scaling compiled applications - highload 2013
Page 111: scaling compiled applications - highload 2013
Page 112: scaling compiled applications - highload 2013
Page 113: scaling compiled applications - highload 2013

sassanosystems.com

@joedamato

Page 114: scaling compiled applications - highload 2013

спасибо

Page 115: scaling compiled applications - highload 2013

?