115
scaling compiled applications Joe Damato @joedamato

Joe Damato

  • Upload
    ontico

  • View
    334

  • Download
    2

Embed Size (px)

DESCRIPTION

HighLoad++ 2014

Citation preview

Page 1: Joe Damato

scaling compiled applications Joe Damato

@joedamato

Page 2: Joe Damato

about me • Joe Damato

• San Francisco, CA

• i like:

• systems

programming

• debugging

• performance

analysis

Page 3: Joe Damato

@joedamato

Page 4: Joe Damato

timetobleed.com

Page 5: Joe Damato

sassanosystems.c

om

Page 6: Joe Damato
Page 7: Joe Damato
Page 8: Joe Damato
Page 9: Joe Damato
Page 10: Joe Damato
Page 11: Joe Damato
Page 12: Joe Damato
Page 13: Joe Damato
Page 14: Joe Damato
Page 15: Joe Damato
Page 16: Joe Damato
Page 17: Joe Damato
Page 19: Joe Damato
Page 20: Joe Damato
Page 21: Joe Damato

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: Joe Damato
Page 23: Joe Damato

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: Joe Damato
Page 25: Joe Damato
Page 26: Joe Damato

why?

почему?

Page 27: Joe Damato
Page 28: Joe Damato
Page 29: Joe Damato

tools for... • RPMs

• DEBs

• Everything else

• windows installers (MSIs)

• other linux/unix like OS’s

• etc

Page 30: Joe Damato

chroot ??

Page 31: Joe Damato

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: Joe Damato
Page 33: Joe Damato
Page 34: Joe Damato
Page 35: Joe Damato
Page 36: Joe Damato

RPM

https://fedorahosted.org/mock/

mock

Page 37: Joe Damato

DEB

https://wiki.ubuntu.com/PbuilderHowto

pbuilder

Page 38: Joe Damato

Everything else

• KVM

• Amazon EC2

• other virtualization

Page 39: Joe Damato

KVM EC2

Page 40: Joe Damato

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: Joe Damato
Page 42: Joe Damato
Page 43: Joe Damato

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: Joe Damato
Page 45: Joe Damato

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: Joe Damato
Page 47: Joe Damato
Page 48: Joe Damato

two types of

linking....

• dynamic linking

• static linking

Page 49: Joe Damato

static linking

• calls to functions in library are resolved at compile

time.

• code from the library is copied into the resulting

binary.

Page 50: Joe Damato

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: Joe Damato
Page 52: Joe Damato

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

Page 53: Joe Damato
Page 54: Joe Damato

why?

почему?

Page 55: Joe Damato
Page 56: Joe Damato
Page 57: Joe Damato
Page 58: Joe Damato

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: Joe Damato
Page 60: Joe Damato

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: Joe Damato
Page 62: Joe Damato
Page 63: Joe Damato
Page 64: Joe Damato
Page 65: Joe Damato

why?

почему?

Page 66: Joe Damato
Page 67: Joe Damato
Page 68: Joe Damato
Page 69: Joe Damato
Page 70: Joe Damato
Page 71: Joe Damato
Page 72: Joe Damato
Page 73: Joe Damato
Page 74: Joe Damato

Use files • src/

•redhat5/

•some_internal_thing.c

•ubuntu1204/

•some_internal_thing.c

•debian6/

•some_internal_thing.c

Page 75: Joe Damato

Use the build system

Determine which file

to build at compile

time.

Page 76: Joe Damato
Page 77: Joe Damato
Page 78: Joe Damato

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: Joe Damato
Page 80: Joe Damato

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: Joe Damato
Page 82: Joe Damato
Page 83: Joe Damato

why?

почему?

Page 84: Joe Damato
Page 85: Joe Damato

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: Joe Damato
Page 87: Joe Damato

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: Joe Damato

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: Joe Damato
Page 90: Joe Damato

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: Joe Damato
Page 92: Joe Damato
Page 93: Joe Damato
Page 94: Joe Damato
Page 95: Joe Damato
Page 97: Joe Damato
Page 98: Joe Damato
Page 99: Joe Damato

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: Joe Damato

You also need... correctness

testing.

Page 101: Joe Damato

RSpec is useful for

this.

Page 102: Joe Damato

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: Joe Damato
Page 104: Joe Damato

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: Joe Damato

To

summarize...

Page 106: Joe Damato
Page 107: Joe Damato
Page 108: Joe Damato
Page 109: Joe Damato
Page 110: Joe Damato
Page 111: Joe Damato
Page 112: Joe Damato
Page 113: Joe Damato

sassanosystems.c

om

@joedamato

Page 114: Joe Damato

спасиб

о

Page 115: Joe Damato