Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

Glen Mailer

Slide 3

Slide 3 text

A short
 audience survey

Slide 4

Slide 4 text

Set the Scene
 (as of September 2013)

Slide 5

Slide 5 text

The Codebase

Slide 6

Slide 6 text

First commit April 2010
 60k commits since According to git

Slide 7

Slide 7 text

9300 PHP files
 690k lines of code According to cloc

Slide 8

Slide 8 text

10 releases a week
 35 active committers
 10 concurrent streams
 1 deployable

Slide 9

Slide 9 text

The Platform

Slide 10

Slide 10 text

8 Test Environments
 1 Staging Environment
 2 Live Environments

Slide 11

Slide 11 text

74 Live PHP boxes

Slide 12

Slide 12 text

1300 req/s peak
 500k uniques/week

Slide 13

Slide 13 text

Why Upgrade?

Slide 14

Slide 14 text

Using basically the same PHP version as the first commit with security patches

Slide 15

Slide 15 text

PHP 5.3 is dead

Slide 16

Slide 16 text

Bug fixes
 Performance

Slide 17

Slide 17 text

New Features! short array syntax traits $this in closures yield finally

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

Bug #64827
 GC causes segfaults

Slide 20

Slide 20 text

The Plan

Slide 21

Slide 21 text

Upgrade a dev box Support 5.3 and 5.5 Pass all tests Upgrade 1 Test env Upgrade CI Upgrade Test & Staging Incrementally Upgrade Live

Slide 22

Slide 22 text

Vagrant
 Chef
 Unit Tests
 Acceptance Tests

Slide 23

Slide 23 text

Hack hack hack...

Slide 24

Slide 24 text

3 days later

Slide 25

Slide 25 text

What changed?

Slide 26

Slide 26 text

APC
 becomes
 OPcache and APCu

Slide 27

Slide 27 text

Check for new function, fall back to old one if (function_exists('opcache_reset')) { opcache_reset(); } else { apc_clear_cache(); }

Slide 28

Slide 28 text

“The PHP api will retain compatibility with APC, as will common configuration options, providing a drop in replacement.” APCu

Slide 29

Slide 29 text

Not a drop in replacement

Slide 30

Slide 30 text

APCu 4.0.1
 APCu 4.0.2
 master is closer still

Slide 31

Slide 31 text

No more
 mysql_

Slide 32

Slide 32 text

It will not be missed

Slide 33

Slide 33 text

preg_replace /e
 becomes
 preg_replace_callback

Slide 34

Slide 34 text

(string) array()
 Now raises a warning Still returns “Array”

Slide 35

Slide 35 text

"Type-checked" function function inc($int) { if (!is_int($int)) { throw new InvalidArgumentException( 'Expected int, got: ' . $int ); } return $int + 1; }

Slide 36

Slide 36 text

Unit test for type-checked function /** * @dataprovider provideIncInvalid */ function testIncRejectsInvalid($a) { try { inc($a); $this->fail('Expected exception'); } catch (InvalidArgumentException $ex) {} } function provideIncInvalid() { return array( null, true, "string", array() ); }

Slide 37

Slide 37 text

Simplest fix throw new InvalidArgumentException( 'Expected int, got: ' . json_encode($int) );

Slide 38

Slide 38 text

$a = "string”;
 $a['index'];
 Now raises a warning

Slide 39

Slide 39 text

// protected $a;
 ++$this->a
 Now raises a warning

Slide 40

Slide 40 text

Progress

Slide 41

Slide 41 text

Upgrade a dev box
 Support 5.3 and 5.5
 Pass all tests
 Upgrade 1 Test env
 Upgrade CI
 Upgrade Test & Staging
 Incrementally Upgrade Live

Slide 42

Slide 42 text

Upgrade a dev box
 Support 5.3 and 5.5
 Pass all tests
 Upgrade 1 Test env
 Upgrade CI
 Upgrade Test & Staging
 Incrementally Upgrade Live

Slide 43

Slide 43 text

PHPNW 2013

Slide 44

Slide 44 text

The Rollout

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

APCu Failures
 APCu #49: Segfaults
 APCu #19: deadlock

Slide 50

Slide 50 text

Forwards
 or
 Backwards

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

Segfaults - 100 point Moving Average 7.2/s 6.0/s 4.8/s 3.6/s 2.4/s 1.2/s Oct Nov Dec Jan

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

Shared Memory?
 I'm out.

Slide 55

Slide 55 text

Can we
 leverage OPCache?

Slide 56

Slide 56 text

The Barwell Cache

Slide 57

Slide 57 text

function barwell_store($key, $value) { $path = BARWELL_BASE . '/' . md5($key); file_put_contents( $path, '

Slide 58

Slide 58 text

function barwell_store_obj($key, $value) { $path = BARWELL_BASE . '/' . md5($key); file_put_contents( $path, '

Slide 59

Slide 59 text

Are you mad?

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

No content

Slide 62

Slide 62 text

Probably.

Slide 63

Slide 63 text

Take a moment.
 Stop.
 Think.

Slide 64

Slide 64 text

What is the problem we're trying to solve?

Slide 65

Slide 65 text

Fast k/v access
 for hot paths

Slide 66

Slide 66 text

How fast do we really need to be?

Slide 67

Slide 67 text

Move almost everything over to memcached

Slide 68

Slide 68 text

Autoload Map
 Environment Config
 Weird Zend Reflection

Slide 69

Slide 69 text

function simple_store($key, $value) { file_put_contents( path($key), serialize($value)); } function simple_fetch($key) { return unserialize( file_get_contents(path($key))); }

Slide 70

Slide 70 text

The
 Aftermath

Slide 71

Slide 71 text

Performance

Slide 72

Slide 72 text

Average Response Time in ms

Slide 73

Slide 73 text

Average Memory Use in MB

Slide 74

Slide 74 text

Average Response Time in ms
 on one API endpoint with minimal external calling

Slide 75

Slide 75 text

New Features

Slide 76

Slide 76 text

17 Traits
 +
 4 in tests

Slide 77

Slide 77 text

2 uses of
 finally

Slide 78

Slide 78 text

37 uses of
 yield

Slide 79

Slide 79 text

New array syntax?

Slide 80

Slide 80 text

A few snowflake boxes are still on 5.3

Slide 81

Slide 81 text

Have bumped minor version a couple of times since

Slide 82

Slide 82 text

Began upgrading
 to 5.6 this week

Slide 83

Slide 83 text

Takeaways

Slide 84

Slide 84 text

Use configuration management tools

Slide 85

Slide 85 text

Frequently upgrade things in small increments

Slide 86

Slide 86 text

Shared memory is inherently complicated

Slide 87

Slide 87 text

Monitor absolutely everything

Slide 88

Slide 88 text

When you think you're doing something crazy
 
 You might be right

Slide 89

Slide 89 text

Understand why you're doing something

Slide 90

Slide 90 text

Fin.

Slide 91

Slide 91 text

@glenathan https://joind.in/11801