conexão kinghost - otimização prematura

126
PREMATURE OPTIMIZATION The Root of ALL Evil @akitaonrails

Upload: fabio-akita

Post on 15-Jan-2017

973 views

Category:

Technology


4 download

TRANSCRIPT

Page 1: Conexão Kinghost - Otimização Prematura

PREMATUREOPTIMIZATION

The Root of ALL Evil

@akitaonrails

Page 2: Conexão Kinghost - Otimização Prematura

@akitaonrails

Page 3: Conexão Kinghost - Otimização Prematura
Page 4: Conexão Kinghost - Otimização Prematura
Page 5: Conexão Kinghost - Otimização Prematura
Page 6: Conexão Kinghost - Otimização Prematura
Page 7: Conexão Kinghost - Otimização Prematura

Rubyconf Brasil 2016 – September 23 - 24

Page 8: Conexão Kinghost - Otimização Prematura

Rubyconf Brasil 2016 – September 23 - 24

Page 9: Conexão Kinghost - Otimização Prematura

September

23 - 24 @rubyconfbr

Page 10: Conexão Kinghost - Otimização Prematura

PREMATUREOPTIMIZATION

The Root of ALL Evil

@akitaonrails

Page 11: Conexão Kinghost - Otimização Prematura
Page 12: Conexão Kinghost - Otimização Prematura

“Premature Optimization is the Root of All Evil”

- Don Knuth

Page 13: Conexão Kinghost - Otimização Prematura
Page 14: Conexão Kinghost - Otimização Prematura
Page 15: Conexão Kinghost - Otimização Prematura

SPA e-commerce

Page 16: Conexão Kinghost - Otimização Prematura
Page 17: Conexão Kinghost - Otimização Prematura

SPA e-commerce http://www.loja.com.br/#!/produtos/item-001

Page 18: Conexão Kinghost - Otimização Prematura

SPA e-commerce http://www.loja.com.br/#!/produtos/item-001

http://www.loja.com.br/?_escaped_fragment_=/produtos/item-001

Page 19: Conexão Kinghost - Otimização Prematura

High Level Numbers

Page 20: Conexão Kinghost - Otimização Prematura

Client #1

Page 21: Conexão Kinghost - Otimização Prematura
Page 22: Conexão Kinghost - Otimização Prematura
Page 23: Conexão Kinghost - Otimização Prematura
Page 24: Conexão Kinghost - Otimização Prematura
Page 25: Conexão Kinghost - Otimização Prematura

$ 4,000

Page 26: Conexão Kinghost - Otimização Prematura

$ 4,000 ($ 7 MI/yr revenue - 0.68%)

Page 27: Conexão Kinghost - Otimização Prematura

Client #2

Page 28: Conexão Kinghost - Otimização Prematura
Page 29: Conexão Kinghost - Otimização Prematura
Page 30: Conexão Kinghost - Otimização Prematura
Page 31: Conexão Kinghost - Otimização Prematura

$ 100,000+

Page 32: Conexão Kinghost - Otimização Prematura

$ 100,000+ ($ 800 MI/yr revenue - 0.15%)

Page 33: Conexão Kinghost - Otimização Prematura
Page 34: Conexão Kinghost - Otimização Prematura

• Minimum IT Cost:

Page 35: Conexão Kinghost - Otimização Prematura

• Minimum IT Cost:

• USD 1000 - Cloud Services

Page 36: Conexão Kinghost - Otimização Prematura

• Minimum IT Cost:

• USD 1000 - Cloud Services

• USD 3000 - 1 Developer

Page 37: Conexão Kinghost - Otimização Prematura

• Minimum IT Cost:

• USD 1000 - Cloud Services

• USD 3000 - 1 Developer

• USD 4000 - 1 “Responsible” (Manager, Marketing, etc)

Page 38: Conexão Kinghost - Otimização Prematura

• Minimum IT Cost:

• USD 1000 - Cloud Services

• USD 3000 - 1 Developer

• USD 4000 - 1 “Responsible” (Manager, Marketing, etc)

• Total: USD 8.000/month (USD 96.000/year)

Page 39: Conexão Kinghost - Otimização Prematura

• Minimum IT Cost:

• USD 1000 - Cloud Services

• USD 3000 - 1 Developer

• USD 4000 - 1 “Responsible” (Manager, Marketing, etc)

• Total: USD 8.000/month (USD 96.000/year)

• Minimum Business Requirement:

Page 40: Conexão Kinghost - Otimização Prematura

• Minimum IT Cost:

• USD 1000 - Cloud Services

• USD 3000 - 1 Developer

• USD 4000 - 1 “Responsible” (Manager, Marketing, etc)

• Total: USD 8.000/month (USD 96.000/year)

• Minimum Business Requirement:

• Revenue: > USD 2 MI / year

Page 41: Conexão Kinghost - Otimização Prematura

• Minimum IT Cost:

• USD 1000 - Cloud Services

• USD 3000 - 1 Developer

• USD 4000 - 1 “Responsible” (Manager, Marketing, etc)

• Total: USD 8.000/month (USD 96.000/year)

• Minimum Business Requirement:

• Revenue: > USD 2 MI / year

• IT Cost / Revenue ratio: < 5%

Page 42: Conexão Kinghost - Otimização Prematura
Page 43: Conexão Kinghost - Otimização Prematura

Increase Revenue >

Lower Costs

Page 44: Conexão Kinghost - Otimização Prematura

Open > Proprietary (prefer “Best of Breed”)

Page 45: Conexão Kinghost - Otimização Prematura

Cloud > On-Premise (Infrastructure/Platform as a Service)

Page 46: Conexão Kinghost - Otimização Prematura
Page 47: Conexão Kinghost - Otimização Prematura
Page 48: Conexão Kinghost - Otimização Prematura
Page 49: Conexão Kinghost - Otimização Prematura
Page 50: Conexão Kinghost - Otimização Prematura
Page 51: Conexão Kinghost - Otimização Prematura
Page 52: Conexão Kinghost - Otimização Prematura

SaaS > IaaS (avoid doing yourself)

Page 53: Conexão Kinghost - Otimização Prematura

Databases

Page 54: Conexão Kinghost - Otimização Prematura

E-mail

Page 55: Conexão Kinghost - Otimização Prematura

Performance

Page 56: Conexão Kinghost - Otimização Prematura

Search

Page 57: Conexão Kinghost - Otimização Prematura

Async Jobs

Page 58: Conexão Kinghost - Otimização Prematura

Monitoring

Page 59: Conexão Kinghost - Otimização Prematura

SEO & SEM (should not be Astrology!)

Page 60: Conexão Kinghost - Otimização Prematura
Page 61: Conexão Kinghost - Otimização Prematura

• /do/you/have/friendly/urls?

Page 62: Conexão Kinghost - Otimização Prematura

• /do/you/have/friendly/urls?

• sitemap.xml?

Page 63: Conexão Kinghost - Otimização Prematura

• /do/you/have/friendly/urls?

• sitemap.xml?

• Proper HTTP 301 Redirections?

Page 64: Conexão Kinghost - Otimização Prematura

• /do/you/have/friendly/urls?

• sitemap.xml?

• Proper HTTP 301 Redirections?

• Social Network buttons?

Page 65: Conexão Kinghost - Otimização Prematura

• /do/you/have/friendly/urls?

• sitemap.xml?

• Proper HTTP 301 Redirections?

• Social Network buttons?

• Periodic ORIGINAL CONTENT publishing?

Page 66: Conexão Kinghost - Otimização Prematura

• /do/you/have/friendly/urls?

• sitemap.xml?

• Proper HTTP 301 Redirections?

• Social Network buttons?

• Periodic ORIGINAL CONTENT publishing?

• No duplication duplication of content content?

Page 67: Conexão Kinghost - Otimização Prematura

• /do/you/have/friendly/urls?

• sitemap.xml?

• Proper HTTP 301 Redirections?

• Social Network buttons?

• Periodic ORIGINAL CONTENT publishing?

• No duplication duplication of content content?

• THEN OK!

Page 68: Conexão Kinghost - Otimização Prematura
Page 69: Conexão Kinghost - Otimização Prematura

I.

II.

III.

IV.

V.

VI.

VII.

VIII.

IX.

X.

XI.

XII.

Codebase One codebase tracked in revision control, many deploys

Dependencies Explicitly declare and isolate dependencies

Config Store config in the environment

Backing services Treat backing services as attached resources

Build, release, run Strictly separate build and run stages

Processes Execute the app as one or more stateless processes

Port binding Export services via port binding

Concurrency Scale out via the process model

Disposability Maximize robustness with fast startup and graceful shutdown

Dev/prod parity Keep development, staging, and production as similar as possible

Logs Treat logs as event streams

Admin processes Run admin/management tasks as one-off processes

Page 70: Conexão Kinghost - Otimização Prematura
Page 71: Conexão Kinghost - Otimização Prematura
Page 72: Conexão Kinghost - Otimização Prematura

y = x * 320

Page 73: Conexão Kinghost - Otimização Prematura

y = x * 320

y = (x << 8) + (x << 6)

Page 74: Conexão Kinghost - Otimização Prematura
Page 75: Conexão Kinghost - Otimização Prematura

• NO Test Suite with below 70% coverage

Page 76: Conexão Kinghost - Otimização Prematura

• NO Test Suite with below 70% coverage

• NO CodeClimate below 3.0 rating

Page 77: Conexão Kinghost - Otimização Prematura

• NO Test Suite with below 70% coverage

• NO CodeClimate below 3.0 rating

• NO source code file with hundreds of LOC

Page 78: Conexão Kinghost - Otimização Prematura

• NO Test Suite with below 70% coverage

• NO CodeClimate below 3.0 rating

• NO source code file with hundreds of LOC

• NO COPY AND PASTE EVERYWHERE!!!

Page 79: Conexão Kinghost - Otimização Prematura

• NO Test Suite with below 70% coverage

• NO CodeClimate below 3.0 rating

• NO source code file with hundreds of LOC

• NO COPY AND PASTE EVERYWHERE!!!

• NO functions with more than 1 page down

Page 80: Conexão Kinghost - Otimização Prematura

• NO Test Suite with below 70% coverage

• NO CodeClimate below 3.0 rating

• NO source code file with hundreds of LOC

• NO COPY AND PASTE EVERYWHERE!!!

• NO functions with more than 1 page down

• NO table with dozens of fields

Page 81: Conexão Kinghost - Otimização Prematura

• NO Test Suite with below 70% coverage

• NO CodeClimate below 3.0 rating

• NO source code file with hundreds of LOC

• NO COPY AND PASTE EVERYWHERE!!!

• NO functions with more than 1 page down

• NO table with dozens of fields

• NO hours to clone, setup and deploy!!

Page 82: Conexão Kinghost - Otimização Prematura
Page 83: Conexão Kinghost - Otimização Prematura

Spree: 68k LOC 40k are Specs! (60%)

Page 84: Conexão Kinghost - Otimização Prematura

Magento2: 300k LOC 127k are Specs! (< 30%)

Page 85: Conexão Kinghost - Otimização Prematura
Page 86: Conexão Kinghost - Otimização Prematura

Maintainability

> Performance

Page 87: Conexão Kinghost - Otimização Prematura
Page 88: Conexão Kinghost - Otimização Prematura
Page 89: Conexão Kinghost - Otimização Prematura

PRIORITIES!

Page 90: Conexão Kinghost - Otimização Prematura
Page 91: Conexão Kinghost - Otimização Prematura
Page 92: Conexão Kinghost - Otimização Prematura
Page 93: Conexão Kinghost - Otimização Prematura
Page 94: Conexão Kinghost - Otimização Prematura
Page 95: Conexão Kinghost - Otimização Prematura
Page 96: Conexão Kinghost - Otimização Prematura

• SQL N+1 Queries

Page 97: Conexão Kinghost - Otimização Prematura

• SQL N+1 Queries

• Too much SQL

Page 98: Conexão Kinghost - Otimização Prematura

• SQL N+1 Queries

• Too much SQL

• Too much SQL LIKE instead of Elastic

Page 99: Conexão Kinghost - Otimização Prematura

• SQL N+1 Queries

• Too much SQL

• Too much SQL LIKE instead of Elastic

• Lack of proper SQL indexes

Page 100: Conexão Kinghost - Otimização Prematura

• SQL N+1 Queries

• Too much SQL

• Too much SQL LIKE instead of Elastic

• Lack of proper SQL indexes

• Too much unused code that was not removed

Page 101: Conexão Kinghost - Otimização Prematura

• SQL N+1 Queries

• Too much SQL

• Too much SQL LIKE instead of Elastic

• Lack of proper SQL indexes

• Too much unused code that was not removed

• No CDN or proper HTTP Cache invalidation headers

Page 102: Conexão Kinghost - Otimização Prematura

• SQL N+1 Queries

• Too much SQL

• Too much SQL LIKE instead of Elastic

• Lack of proper SQL indexes

• Too much unused code that was not removed

• No CDN or proper HTTP Cache invalidation headers

• Too much synchronous work that should be async jobs

Page 103: Conexão Kinghost - Otimização Prematura

No Metrics No Optimization

Page 104: Conexão Kinghost - Otimização Prematura
Page 105: Conexão Kinghost - Otimização Prematura

- Alan Kay

Page 106: Conexão Kinghost - Otimização Prematura

“Make it Work

- Alan Kay

Page 107: Conexão Kinghost - Otimização Prematura

“Make it Work Make it Correct

- Alan Kay

Page 108: Conexão Kinghost - Otimização Prematura

“Make it Work Make it Correct Make it Fast

- Alan Kay

Page 109: Conexão Kinghost - Otimização Prematura

“Make it Work Make it Correct Make it Fast Make it Cheap”

- Alan Kay

Page 110: Conexão Kinghost - Otimização Prematura
Page 111: Conexão Kinghost - Otimização Prematura
Page 112: Conexão Kinghost - Otimização Prematura
Page 113: Conexão Kinghost - Otimização Prematura
Page 114: Conexão Kinghost - Otimização Prematura
Page 115: Conexão Kinghost - Otimização Prematura

You != Unicorn (nor Facebook, Google, Amazon, etc)

Page 116: Conexão Kinghost - Otimização Prematura

“Casa de Ferreiro, Espeto de FERRO!”

Page 117: Conexão Kinghost - Otimização Prematura
Page 118: Conexão Kinghost - Otimização Prematura

• Increase Revenue > Lower Costs

Page 119: Conexão Kinghost - Otimização Prematura

• Increase Revenue > Lower Costs

• SaaS > PaaS > IaaS > In-House

Page 120: Conexão Kinghost - Otimização Prematura

• Increase Revenue > Lower Costs

• SaaS > PaaS > IaaS > In-House

• Maintainability > Performance

Page 121: Conexão Kinghost - Otimização Prematura

• Increase Revenue > Lower Costs

• SaaS > PaaS > IaaS > In-House

• Maintainability > Performance

• PRIORITIES!!

Page 122: Conexão Kinghost - Otimização Prematura

• Increase Revenue > Lower Costs

• SaaS > PaaS > IaaS > In-House

• Maintainability > Performance

• PRIORITIES!!

• No Metrics, No Optimization

Page 123: Conexão Kinghost - Otimização Prematura

• Increase Revenue > Lower Costs

• SaaS > PaaS > IaaS > In-House

• Maintainability > Performance

• PRIORITIES!!

• No Metrics, No Optimization

• You != Unicorn

Page 124: Conexão Kinghost - Otimização Prematura

PREMATURE OPTIMIZATION is the Root of all Evil

Page 125: Conexão Kinghost - Otimização Prematura
Page 126: Conexão Kinghost - Otimização Prematura

THANKS!www.codeminer42.com

@akitaonrails