39
Large Scale Ruby Project, Challenges and Pitfalls Karunakar Revuri Castle Rock Research Rails Contributor @karuna_revuri https://github.com/Karunakar

Rubyconf presentation

  • Upload
    krevuri

  • View
    180

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Rubyconf presentation

Large Scale Ruby Project, Challenges and Pitfalls

● Karunakar Revuri● Castle Rock Research● Rails Contributor● @karuna_revuri● https://github.com/Karunakar

Page 2: Rubyconf presentation

Ruby Project

● Code

● Tests

● Performance

Page 3: Rubyconf presentation

Test Driven Development

Page 4: Rubyconf presentation

● My_code has_many units and functionals

● Thoughtbot-shoulda

Good

Page 5: Rubyconf presentation

Bad

● Test suite is taking more than 45 mins

Page 6: Rubyconf presentation

Why?

● Many tests

● Bad Tests

● Unnecessary objects

● Unnecessary tests

● Tests with assert true

● Tests with !assert failure

● Big tests

● Random failure tests

Page 7: Rubyconf presentation

Solution

● Cleanup

● Mock your objects when needed

● Run tests in parallel

Page 8: Rubyconf presentation

DEMO

Page 9: Rubyconf presentation

Behavior Driven Development

FRAMEWORK ● Cucumber-capybara GOODMyCode has many scenarios BAD● Cucumber is slow because of selenium

Page 10: Rubyconf presentation

Selenium

● Running selenium with cucumber can eat up lot of time.

● Build time reached more than 3 hours

Page 11: Rubyconf presentation

Solutions

● @rack_test

● Parallel processes

Page 12: Rubyconf presentation

BORG

A Distributed Test Suite Runner for Rails -- Hemant Kumar and Karunakar

● Eventmachine is fast, simple eventmachine processing lib

● Redis is advanced key value storage

Page 13: Rubyconf presentation

How BORG works?

Cruise Machine

Developer Machine-1

Developer Machine-2

Developer Machine-3Redis

Server

Borg Server

Page 14: Rubyconf presentation

BORG Supports

● Shoulda on MRI with rails

● Cucumber on MRI with rails

● Rake::Test on MRI with rails

● Rspec on MRI with rails

Works with 1.8.7 and 1.9.1, 1.9.2 with rails2x and 3x

https://github.com/Karunakar/borg

https://github.com/gnufied/borg

Page 15: Rubyconf presentation

GOOD and BAD

GOOD

● Fast build

● Devs spend less time waiting to checkin

BAD

● Developer machines

● Test Splitting

Page 16: Rubyconf presentation

Code Coverage Tools

● Simple Cov 1.9● Rcov 1.8

Page 17: Rubyconf presentation

Continuous Integration

● Continuous processes of applying quality● Reduce the time to deliver● Build

Page 18: Rubyconf presentation

Continuous Integration

● Continuous processes of applying quality● Reduce the time to deliver● Build

Page 19: Rubyconf presentation
Page 20: Rubyconf presentation

Code Quality

● Pair programming

● Code review

Page 21: Rubyconf presentation

Pairing Environment

Page 22: Rubyconf presentation

Advantages

● Code is clean

● Bugs are less

● More than one will be familiar with code

● Sharing the knowledge is easy

● Good Learning curve

● Maintaining the code quality

Page 23: Rubyconf presentation

Disadvantages

● Active vs Passive

● Communication between the pairs

Solutions

Switch the pairs frequently

Page 24: Rubyconf presentation

Code Reviews

● Code review helps spread information about a project

between team members

● Allows people to suggest ideas and help clarify code

● Its a good time to implement some small refactoring, as

soon as problems are found

● Works best with small groups

Page 25: Rubyconf presentation

Statistical Code Analysis

Statistics of code without actually executing code

Page 26: Rubyconf presentation

rake stats

Page 27: Rubyconf presentation

Code Smell using REEK

● Duplicate Code

● Long Method

● Large Class

● Simulated Polymorphism

Page 28: Rubyconf presentation

Performance Improvements

● Internal quality

● External quality (External quality is end user happiness)

Page 29: Rubyconf presentation

Performance Tools

● Bullet

● Rails indexes

● NewRelic

● Oink

Page 30: Rubyconf presentation

Demo on Bullet

Page 31: Rubyconf presentation

Rails Indexes Demo

Page 32: Rubyconf presentation

Oink

● Memory usage in rails applications

● Memory and active record instantiation information

Page 33: Rubyconf presentation

Oink

2012-03-25T03:45:15+00:00 app[web.2]: Oink Action: sessions#new2012-03-25T03:45:15+00:00 app[web.2]: Memory usage: 500408 | PID: 32012-03-25T03:45:15+00:00 app[web.2]: Instantiation Breakdown: Total: 13 | RegionalOption: 8 | Region: 3 | Country: 2

Page 34: Rubyconf presentation

New Relic

● Performance management tool

● Slow web transactions

● Database hits and queries

● Slow web pages

● What are the reasons

Page 35: Rubyconf presentation

Optimization

● Find with select

● Eager loading

● Use active-reload in development

● Use ActiveRecord to_xml instead of the xml_bulders

● Validations when needed

● Use memcache

● Use query-analyzer in development

Page 36: Rubyconf presentation

Optimization

● Iterators

● Explain command

● Error notifier

Page 37: Rubyconf presentation

Client Side

● Asset pipelining

● Load the js at the end of the file

● Valid HTML / XHTML

Page 38: Rubyconf presentation

Thanks

Page 39: Rubyconf presentation

Questions