Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

45
Scaling Drupal on Amazon Web Services Tristan Roddis DrupalCamp Brighton, January 2015

Transcript of Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

Page 1: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

Scaling Drupal on

Amazon Web Services

Tristan Roddis DrupalCamp Brighton, January 2015

Page 2: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

What we created: www.qdl.qa

2

Page 3: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

3

Page 4: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

4

Page 5: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

5

Page 6: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

• Several hundred thousand pages

• Tens of terabytes of data

• Requirement for high throughput

• Requirement for high resilience

6

Page 7: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

What is Drupal?

7

Page 8: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

Let’s scale it!

8

Page 9: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

Let’s not scale it like this!

9

Page 10: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

Centralised database

10

Page 11: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

Centralised filesystem

11

Page 12: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

Avoid single point of failure

12

Page 13: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

AWS TLAs

• EC2 – Elastic Compute Cloud = virtual servers

• RDS – Relational Database Service = database

• ELB – Elastic Load Balancer = distribute requests

13

Page 14: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

Therefore…

14

Page 15: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

RDS has easy redundancy

15

Page 16: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

So now we have

16

Page 17: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

Clustered filesystem: GlusterFS

17

Page 18: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

GlusterFS components

• EBS – Elastic Block Storage

= file storage up to 1Tb

• LVM – Logical Volume Manager

= grow and shrink volumes

• Gluster has storage ‘bricks’

• Cluster appears as single mount point

(NFS, Gluster protocol etc.)

18

Page 19: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

Distribute servers

• Amazon has different Regions and

Availability Zones

19

Page 20: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

Use different Availability Zones

20

Page 21: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

I lied…

21

Page 22: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

Adding Solr and IIPImage…

22

Page 23: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

Additional security

• VPC – Virtual Private Cloud = can create your

own network architecture

• Security Groups = firewall rules

• IAM = Identity and Access Management =

restrict AWS roles

23

Page 24: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

Final setup

24

Page 25: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

Woah – that’s complicated

25

Page 26: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

Server provisioning

• Automate everything!

• Use Ansible (or Chef, Puppet, etc.)

26

“If you have to SSH into your servers,

then your automation has failed.”

— Rich Adams

Page 27: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

27

Page 28: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

Pets vs cattle

28

“When one of them gets sick, you shoot

'em in the head and replace 'em with a

new one.”

—Randy Bias, CEO of Cloudscaling

Page 29: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

Deployment I: Drupal tools

• Drush

• Drush master

• Features

• Strongarm

29

Page 30: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

Deployment II

• Use Fabric (or Ansible, Capistrano, etc.)

• @runs_once decorator for e.g. drush commands.

30

Page 31: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

Load Test

• Jmeter

• Blitz.io or similar

31

Page 32: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

Tune performance

• Tools: Apache Benchmark (ab), Yslow, Google

PageSpeed

• xhprof – remove bottlenecks

• Fix warnings and notices

• Disable database logging

• OpCode cache (Zend Optimizer, APC)

• Minify CSS/JS

• Lazy Loading via AJAX

32

Page 33: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

33

Page 34: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

Add caching

• Varnish

• Redis/memcached for cache tables (can use

Amazon Elasticache)

• CDN (e.g. Amazon Cloudfront)

• Re-run load tests

34

Page 35: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

[auto]scaling

• AMIs = Amazon Machine Image

• Autoscaling policies

• “pets versus cattle” again

• Problem: servers must have latest Drupal code

• Conflict with Fabric 'push‘ technique

• Interim solution: create an AMI after

each deployment

35

Page 36: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

Backup

• AMIs - Amazon Machine Image = snapshot

server images

• ELB snapshots

• S3 – Simple Storage Service = REST storage

• Glacier = long-term storage

• We used:

– Snapshots with RDS

– S3 with versioning, plus Glacier for Drupal

assets and image assets

36

Page 37: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

Monitoring I: Cloudwatch alerts

37

Page 38: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

Monitoring II: log analysis

• SumoLogic to aggregate logs (or Loggly,

Papertrail, etc.)

38

Page 39: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

Monitoring III: notifications

• OpsGenie (or PagerDuty or similar)

39

Page 40: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

Gotchas

• GlusterFS for PHP files – don’t!

• Custom Drupal cache – careful of

uncontrolled growth!

40

Page 41: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

Tips

• Use “termination protection”

• Enable ELB logging

• “Maintenance 200” module

• Create a “down for maintenance” server

41

Page 42: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

Conclusion

• 21 instances

• 6 load balancers

• 67 ELB volumes

• Lot of work to set up, but quick to alter

• Easily coped with launch traffic:

– 21k sessions/day

– peak of 350 concurrent users

42

Page 43: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

Further Reading

• Justin Slattery, "Multiple Region Autoscaling Drupal in Amazon Web Services" http://dev.mlsdigital.net/posts/Cloud-Native-Drupal/

• Rich Adams, "AWS Tips I Wish I'd Known Before I Started" https://wblinks.com/notes/aws-tips-i-wish-id-known-before-i-started/

• Laura Hamilton, "Are your servers pets or cattle?" http://www.lauradhamilton.com/servers-pets-versus-cattle

43

Page 44: Scaling Drupal on Amazon Web Services (DrupalCamp Brighton)

www.cogapp.com/careers