Otimizando tempo de build: performance da suíte de testes

58
Optimizing build time Performance running tests Jônatas Paganini @jonatasdp

Transcript of Otimizando tempo de build: performance da suíte de testes

Page 1: Otimizando tempo de build: performance da suíte de testes

Optimizing build timePerformance running tests

Jônatas Paganini @jonatasdp

Page 2: Otimizando tempo de build: performance da suíte de testes

test suite

Page 3: Otimizando tempo de build: performance da suíte de testes

RSpec

Page 4: Otimizando tempo de build: performance da suíte de testes

12K

assertions

Page 5: Otimizando tempo de build: performance da suíte de testes

~25’

Build time / 3 machines

Page 6: Otimizando tempo de build: performance da suíte de testes

>100’

in localhost

Page 7: Otimizando tempo de build: performance da suíte de testes

MONOLITHIC APP

Page 8: Otimizando tempo de build: performance da suíte de testes

NOW

Page 9: Otimizando tempo de build: performance da suíte de testes

~13’

Build time / 4 machines

Page 10: Otimizando tempo de build: performance da suíte de testes

?

Page 11: Otimizando tempo de build: performance da suíte de testes

Little Changes on

factories

Page 12: Otimizando tempo de build: performance da suíte de testes

girl ?factory

Page 13: Otimizando tempo de build: performance da suíte de testes

Avoid callbacksCallbacks can be lazy and

unuseful running all the time

Page 14: Otimizando tempo de build: performance da suíte de testes

Model#skip_callback

To avoid run the the hook each factory

Page 15: Otimizando tempo de build: performance da suíte de testes

Coverage ?

Page 16: Otimizando tempo de build: performance da suíte de testes

after(:create)

To run it in a specific factory

Page 17: Otimizando tempo de build: performance da suíte de testes

Profiling Associations

Page 18: Otimizando tempo de build: performance da suíte de testes

Specializing

factories

Page 19: Otimizando tempo de build: performance da suíte de testes

Specialized factories

Page 20: Otimizando tempo de build: performance da suíte de testes

Associations Results

Page 21: Otimizando tempo de build: performance da suíte de testes

Use lazy AssociationsAssociations naturally invokes their own factories.

Page 22: Otimizando tempo de build: performance da suíte de testes

Avoid factory: for associationsAssociations naturally invokes their own factories.

Page 23: Otimizando tempo de build: performance da suíte de testes

association &block

Page 24: Otimizando tempo de build: performance da suíte de testes

association &block

Page 25: Otimizando tempo de build: performance da suíte de testes

quick wins

Page 26: Otimizando tempo de build: performance da suíte de testes

Use build_stubbedInstead of create

Page 27: Otimizando tempo de build: performance da suíte de testes

hack sign_inAvoid touch database each login

Page 28: Otimizando tempo de build: performance da suíte de testes

Configure RSpec

Page 29: Otimizando tempo de build: performance da suíte de testes

sign_in build_stubbed

Page 30: Otimizando tempo de build: performance da suíte de testes

Use stub to avoid

inflate associations

Page 31: Otimizando tempo de build: performance da suíte de testes
Page 32: Otimizando tempo de build: performance da suíte de testes
Page 33: Otimizando tempo de build: performance da suíte de testes

build Instead of create

Page 34: Otimizando tempo de build: performance da suíte de testes
Page 35: Otimizando tempo de build: performance da suíte de testes
Page 36: Otimizando tempo de build: performance da suíte de testes
Page 37: Otimizando tempo de build: performance da suíte de testes

CI ImprovementsWe use CircleCI

● Split specs by context● Hack postgres.conf● Postgresql on Memory

Page 38: Otimizando tempo de build: performance da suíte de testes

Split specs by

Context

Page 39: Otimizando tempo de build: performance da suíte de testes

CircleCi divide tests by time NOT

context

Page 40: Otimizando tempo de build: performance da suíte de testes

Split Specs by

DIRECTORY

Page 41: Otimizando tempo de build: performance da suíte de testes

postgres.conf

Page 42: Otimizando tempo de build: performance da suíte de testes

fsync = ’off’

Page 43: Otimizando tempo de build: performance da suíte de testes

full_page_writes = ’off’

Page 44: Otimizando tempo de build: performance da suíte de testes

checkpoint_segments = ’100’checkpoint_timeout = ’45 min’

Page 45: Otimizando tempo de build: performance da suíte de testes

data_directory = ’/tmp/postgres-on-memory’

Page 46: Otimizando tempo de build: performance da suíte de testes

dir=/tmp/postgresql-on-memory

Page 47: Otimizando tempo de build: performance da suíte de testes

dir=/tmp/postgresql-on-memory

mkdir $dir

Page 48: Otimizando tempo de build: performance da suíte de testes

dir=/tmp/postgresql-on-memory

mkdir $dir

mount -o size=200M,mode=0666 tmpfs $dir

Page 49: Otimizando tempo de build: performance da suíte de testes

dir=/tmp/postgresql-on-memory

mkdir $dir

mount -o size=200M,mode=0666 tmpfs $dir

chown postgres:postgres $dir

Page 50: Otimizando tempo de build: performance da suíte de testes

dir=/tmp/postgresql-on-memory

mkdir $dir

mount -o size=200M,mode=0666 tmpfs $dir

chown postgres:postgres $dir

sudo su - postgres -c \

'/usr/lib/postgresql/9.4/bin/initdb \

--encoding=UTF8 --pgdata=$dir

Page 51: Otimizando tempo de build: performance da suíte de testes

NEXT LEVEL<what> run <when>

Page 52: Otimizando tempo de build: performance da suíte de testes

hardcore scenarios

Split Specs

Page 53: Otimizando tempo de build: performance da suíte de testes

Nightly Build

Page 54: Otimizando tempo de build: performance da suíte de testes

if [ -n "${RUN_NIGHTLY_BUILD}" ];

rspec spec/features --tag "~smoke"

Page 55: Otimizando tempo de build: performance da suíte de testes

if [ -n "${RUN_NIGHTLY_BUILD}" ];

rspec spec/features --tag "~smoke"

if [ -z "${RUN_NIGHTLY_BUILD}" ];

rspec spec/features --tag "smoke"

Page 57: Otimizando tempo de build: performance da suíte de testes

Conclusion

● Avoid touch database● Avoid callbacks no sense● Avoid things you don’t need● Write specialized factories● Rate (classify) your test● Benchmark all isolated steps

It’s all about responsibilities

Page 58: Otimizando tempo de build: performance da suíte de testes

Thanks!@jonatasdp

http://ideia.me

http://shipit.resultadosdigitais.com.br