rubyconf presentation

Post on 25-May-2015

181 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Large Scale Ruby Project, Challenges and Pitfalls

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

Ruby Project

● Code

● Tests

● Performance

Test Driven Development

● My_code has_many units and functionals

● Thoughtbot-shoulda

Good

Bad

● Test suite is taking more than 45 mins

Why?

● Many tests

● Bad Tests

● Unnecessary objects

● Unnecessary tests

● Tests with assert true

● Tests with !assert failure

● Big tests

● Random failure tests

Solution

● Cleanup

● Mock your objects when needed

● Run tests in parallel

DEMO

Behavior Driven Development

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

Selenium

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

● Build time reached more than 3 hours

Solutions

● @rack_test

● Parallel processes

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

How BORG works?

Cruise Machine

Developer Machine-1

Developer Machine-2

Developer Machine-3Redis

Server

Borg Server

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

GOOD and BAD

GOOD

● Fast build

● Devs spend less time waiting to checkin

BAD

● Developer machines

● Test Splitting

Code Coverage Tools

● Simple Cov 1.9● Rcov 1.8

Continuous Integration

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

Continuous Integration

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

Code Quality

● Pair programming

● Code review

Pairing Environment

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

Disadvantages

● Active vs Passive

● Communication between the pairs

Solutions

Switch the pairs frequently

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

Statistical Code Analysis

Statistics of code without actually executing code

rake stats

Code Smell using REEK

● Duplicate Code

● Long Method

● Large Class

● Simulated Polymorphism

Performance Improvements

● Internal quality

● External quality (External quality is end user happiness)

Performance Tools

● Bullet

● Rails indexes

● NewRelic

● Oink

Demo on Bullet

Rails Indexes Demo

Oink

● Memory usage in rails applications

● Memory and active record instantiation information

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

New Relic

● Performance management tool

● Slow web transactions

● Database hits and queries

● Slow web pages

● What are the reasons

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

Optimization

● Iterators

● Explain command

● Error notifier

Client Side

● Asset pipelining

● Load the js at the end of the file

● Valid HTML / XHTML

Thanks

Questions

top related