44
Running applications in a production environment Nikola Krgović

Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

  • Upload
    others

  • View
    9

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

Running applications in a production environment

Nikola Krgović

Page 2: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

https://joind.in/talk/64924

Page 3: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

How do most web applications start

• A CMS (Wordpress, Drupal, etc)• A small custom made site• Using Rapid development tools (Frameworks&ORMs)• Agile development : Minimal viable product• Deployed to a single server

Page 4: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

Once the real traffic arrives

• Need for performance• Price constraints force horizontal scalability• High Availability becomes a necessity

Page 5: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

Changes in methodology

• Agile is embraced.• 12-Factor App• Continuous Delivery and testing• Continuous Deployment• DevOps

Page 6: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

Continuous deployment• Continuous delivery (CD or CDE) is a software engineering approach in

which teams produce software in short cycles, ensuring that the software can be reliably released at any time and, when releasing the software, doing

so manually.• Continuous deployment (CD) is a software engineering approach in which

software functionalities are delivered frequently through automated deployments.

Page 7: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

Continuous deployment

• Creates a need for more complex tools• Mandatory Automated testing• Both unit tests and integration tests are necessary

Page 8: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

Continuous deployment

Page 9: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

DevOps• DevOps is a software development methodology that combines software development

(Dev) with information technology operations (Ops). The goal of DevOps is to shorten the systems development life cycle while also delivering features, fixes, and updates frequently in close alignment with business objectives.The DevOps approach is to

include automation and event monitoring at all steps of the software build

• DevOps is a methodology - not a job title. :)

Page 10: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

DevOps

Page 11: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

DevOpsDevOps practices change the life of a developer :

• Configuration management tools to create environment• Deployments are automated : No manual “touch-ups” on the server• No direct access to servers. Code is on shared storage, deployed trough

a “jumpbox” or immutable inside a container• Logs are centralised, and available trough a dedicated app - usually the

ELK stack is used : You need to master RegExp• Application performance monitoring becomes a regular practice

Page 12: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

DevOpsConfiguration Management

• Configuration Deployment tools like Ansible guarantee all environments are setup the same

• Configuration management tools, like Puppet use agents, which add assurance that the environment will remain the same throughout use

• Very little effect on the developers, other then the guarantee that the system will be deployed and maintained in a consistent manner

Page 13: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

DevOps : Monitoring

Page 14: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

DevOps : APM

Page 15: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

DevOps : Kibana

Page 16: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

DevOps : Logs

Page 17: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

Development Environment

12-Factor App :

X. Dev/prod parityKeep development, staging, and production as similar as possible

Page 18: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

Development EnvironmentTypical :

• Developers machine (Virtualbox+Vagrant / MiniKube / OKD*)• Code / CI (GitLab with Test)• Test Systems (“Beta”)• Staging system• Production

*Kubernetes system previously known as OpenShift Origin

Page 19: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

Development Environment

Page 20: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

Development Environment

Page 21: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

High Availability

• Highly available systems have no single point of failure• Well designed HA systems don’t have redundant and “hot-

standby” components : design is “active-active”• Well designed apps can scale horizontally

Page 22: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

High AvailabilityTypical Components

• Load Balancers• Content Delivery Network and Object Storage• Application Servers• Relational Database Management System• Key-Value storage• Queue• Document Storage / Object Storage / NoSQL• Full Test Search• Shared Storage

Page 23: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

High Availability System

Page 24: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

Load BalancersNginX or Haproxy

• Distributes connections to application servers• Checks application severs for health• Terminates TLS connections• Does cookie manipulation• Redirecting if needed• Web Application Firewall

Page 25: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

Load BalancersNginX or Haproxy

• proxy_set_header x-real-ip $remote_addr• proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for• proxy_set_header x-forwarded-proto $scheme

Page 26: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

CDN and Object Storage• Object storage uses an API (usually S3) to store data.• Usually used as-a-service , but can be hosted on-prem.• Simple and easy to use from concurrent locations

• CDN’s offer faster loading times for data• Should be used for all static assets (images, css, js)• Served of a different, cookie-less domain• Require versioning, due to long caching times• When used as-a-service offer a simple way to geo-distribute data and

significantly speed up loading times.

Page 27: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

Application Servers• Application servers must be stateless• Applications can be stateful with shared session storage • Deploy is done via automation• Non-container deployments often use shared storage• If using interpreted systems, like PHP, you need to flush cache

opcache_reset()

Page 28: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

Application Servers• Unix privileges are not an enemy

• SE Linux security contexts and Mandatory Access Control are your friends too

httpd_sys_content_t httpd_sys_rw_content_t

Page 29: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

Application Servers

• A pool of servers is ~100X more powerful then your machine• A pool of servers will have ~10,000X visitors of your machine

• Memory is a very critical resource. Talk about it with Ops!

Page 30: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

Key-Value storage

• Redis is the default choice, use memcached only if you must. • Redis does have high availability options• Almost never disk persistent. Disk is used for cache warmup.• Can be deployed shared or per-instance

• Shared Redis is needed if servers are stateful, for session storage• Per-instance Redis is more performant, but complicates cache invalidation

Page 31: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

Queue

ZeroMQ, RabbitMQ, AWS SNS

• Highly available by design• Centralized and scalable• Provide a simple method of asynchronously processing messages.• Provides a built-in mechanism for retrying• Should be used instead of in-database queues

Page 32: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

Full-Text Search

ElasticSearch or Sphinx

• Usually used in read-only fashion• ElasticSearch has high availability clustering• Sphinx can be made HA with HAProxy• Loading data into FTS needs a separate process

Page 33: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

Document StorageMongoDB

• Not a Relational database• Fully ACID compliant• Great for storing object, poor with relations and “join”-like queries• Has built-in high availability using quorum, initial change is just the connection string

mongodb://s1.example.net:27017,s2.example.net:27017,s3.example.net:27017/

Page 34: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

MongoDB• Not a Relational database• Poor performance relations and “join”-like queries• Queries that require object manipulation can be slow• It is advisable to use readPerf() and send slow queries to

secondary instances

Page 35: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

Relational DatabasesMySQL or PostreSQL

• Used to store relational data• Always design using normal forms (1NF, 2NF, 3NF, BC)• Usually has asynchronous replication• In-app logic usually scales better then in-db, but…

Page 36: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

Relational DatabasesIndexing

• Primary keys are a must• Covering index vs Row read• An index too many• Master vs Slave index

Page 37: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

Relational DatabasesPrivilege Separation

• GRANT SELECT,INSERT,UPDATE,DELETE, CREATE TEMPORARY TABLE ON ‘schema’.* to

‘application_user’@’10.%’;

• Forget about migrations from code

Page 38: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

Relational Databases

Page 39: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

Relational DatabasesAsynchronous replication

• Assume slave will always have ~30s replication lag• High availability can provide connectivity but can’t do a read-

write split • Automated solutions exist (ProxySQL, mysqlnd_ms) but still

require hinting for some cases like SELECT after INSERT

Page 40: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

Relational Databases

Page 41: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

Relational DatabasesORMs as a disaster in production

• ORM can be viewed as a rapid prototyping tool, but that’s it• ORM’s can slow down JOIN’s by orders of magnitude• At very small cases with ~100,00 rows you get:

Bulk inserts were tested at 2x the speed of ORMJoins sometimes go over 10x faster then ORM

Page 42: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

Relational DatabasesOptimizing in production

• Work with DBA’s (or OPS) on indexing• Explain is your friend• Temporary tables can speed things up massively

Page 43: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

Conclusions• Keep the stack as small as possible• Use the right tool for the right job• Don’t use multiple tools for the same job• Always consider that you’ll have millions of users• When in doubt scale horizontally

Page 44: Running applications in a production environmentDevOps Configuration Management • Configuration Deployment tools like Ansible guarantee all environments are setup the same •

Running applications in a production environment

Questions…?