Thursday, August 08, 2013

Ruby 1.9.3 (Rails 3) Ruby 2.0 (Rails 4) Performance test and improvements

Using Mac OS and Webrick in local environment
time -p bundle exec rake environment
real 6.69
user 4.76
sys 0.79

export RUBY_GC_MALLOC_LIMIT=1000000000
export RUBY_FREE_MIN=500000
export RUBY_HEAP_MIN_SLOTS=40000

AFTER we set the above exports , check the below performance
time -p bundle exec rake environment
real 5.36
user 3.19
sys 1.05

Also tested in request to response scenario using apache bench with 100 requests
Ruby 1.9.3 (Rails 3)
------------------------------------------------------------------------------------------
ab -n 100 -c 1 http://localhost:3000/
------------------------------------------------------------------------------------------
BEFORE FLAGS SET  (ruby-1.9.3-p194 [ x86_64 ])
------------------------------
Server Software:        WEBrick/1.3.1
Server Hostname:        127.0.0.1
Server Port:            3000

Document Path:          /
Document Length:        96050 bytes

Concurrency Level:      1
Time taken for tests:   391.883 seconds
Complete requests:      100
Failed requests:        13
   (Connect: 0, Receive: 0, Length: 13, Exceptions: 0)
Write errors:           0
Total transferred:      9698686 bytes
HTML transferred:       9604985 bytes
Requests per second:    0.26 [#/sec] (mean)
Time per request:       3918.831 [ms] (mean)
Time per request:       3918.831 [ms] (mean, across all concurrent requests)
Transfer rate:          24.17 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:     2963 3585 583.6   3430    5625
Processing:     0  334 2625.5      1   26154
Waiting:        0  333 2625.5      0   26153
Total:       2963 3919 2905.2   3430   31529

Percentage of the requests served within a certain time (ms)
  50%   3430
  66%   3532
  75%   3623
  80%   3710
  90%   4407
  95%   6346
  98%   7244
  99%  31529
 100%  31529 (longest request)
---------------------------------------------------------------
AFTER FLAGS SET  (ruby-1.9.3-p194 [ x86_64 ])
---------------------------------------------------------------
export RUBY_GC_MALLOC_LIMIT=1000000000
export RUBY_FREE_MIN=500000
export RUBY_HEAP_MIN_SLOTS=40000

Server Software:        WEBrick/1.3.1
Server Hostname:        127.0.0.1
Server Port:            3000

Document Path:          /
Document Length:        96050 bytes

Concurrency Level:      1
Time taken for tests:   368.903 seconds
Complete requests:      100
Failed requests:        14
   (Connect: 0, Receive: 0, Length: 14, Exceptions: 0)
Write errors:           0
Total transferred:      9714323 bytes
HTML transferred:       9620622 bytes
Requests per second:    0.27 [#/sec] (mean)
Time per request:       3689.025 [ms] (mean)
Time per request:       3689.025 [ms] (mean, across all concurrent requests)
Transfer rate:          25.72 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:     2563 3388 634.5   3395    5351
Processing:     0  301 2692.0      0   26860
Waiting:        0  301 2692.0      0   26859
Total:       2563 3689 2973.1   3397   32211

Percentage of the requests served within a certain time (ms)
  50%   3397
  66%   3656
  75%   3753
  80%   3809
  90%   3928
  95%   5208
  98%   6949
  99%  32211
 100%  32211 (longest request)
----------------------------------------------------

Ruby 2.0 (Rails 4)
-------------------------------------------------------------------------------------------------------
 ab -n 100 -c 1 http://127.0.0.1:3000/
------------------------------------------------------------------------------------------------------
Server Software:        WEBrick/1.3.1
Server Hostname:        127.0.0.1
Server Port:            3000

Document Path:          /?locale=uk
Document Length:        20815 bytes

Concurrency Level:      1
Time taken for tests:   181.485 seconds
Complete requests:      100
Failed requests:        5
   (Connect: 0, Receive: 0, Length: 5, Exceptions: 0)
Write errors:           0
Total transferred:      2185395 bytes
HTML transferred:       2081495 bytes
Requests per second:    0.55 [#/sec] (mean)
Time per request:       1814.851 [ms] (mean)
Time per request:       1814.851 [ms] (mean, across all concurrent requests)
Transfer rate:          11.76 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       37 1590 658.0   1678    5320
Processing:     0  225 918.2      0    8042
Waiting:        0  225 917.9      0    8041
Total:       1585 1815 818.9   1679    8079

Percentage of the requests served within a certain time (ms)
  50%   1679
  66%   1685
  75%   1690
  80%   1694
  90%   1749
  95%   1995
  98%   6240
  99%   8079
 100%   8079 (longest request)
-------------------------------------------------------------------------------------------------
AFTER FLAG SET (Ruby 2.0 (Rails 4)
export RUBY_GC_MALLOC_LIMIT=1000000000
export RUBY_FREE_MIN=500000
export RUBY_HEAP_MIN_SLOTS=40000
----------
Server Software:        WEBrick/1.3.1
Server Hostname:        127.0.0.1
Server Port:            3000

Document Path:          /?locale=uk
Document Length:        20815 bytes

Concurrency Level:      1
Time taken for tests:   172.496 seconds
Complete requests:      100
Failed requests:        12
   (Connect: 0, Receive: 0, Length: 12, Exceptions: 0)
Write errors:           0
Total transferred:      2185386 bytes
HTML transferred:       2081486 bytes
Requests per second:    0.58 [#/sec] (mean)
Time per request:       1724.962 [ms] (mean)
Time per request:       1724.962 [ms] (mean, across all concurrent requests)
Transfer rate:          12.37 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       36  350 695.0     40    3408
Processing:     0 1374 737.0   1564    3935
Waiting:        0 1374 736.6   1563    3934
Total:       1582 1725 406.2   1607    3973

Percentage of the requests served within a certain time (ms)
  50%   1607
  66%   1617
  75%   1640
  80%   1651
  90%   1909
  95%   3031
  98%   3408
  99%   3973
 100%   3973 (longest request)

Tuesday, August 06, 2013

Upgrading tips for Ruby 2.0 & Rails 4 from Ruby 1.9.3 & Rails 3

Ruby  2.0
1. mostly compatible with Ruby 1.9.3 version
3. more refinements and code related features;
4. Asynchronous exception handling API
5. More built in libraries
6. Debugging support(DTrace,TracePoint)
7. Performace enhancements like GC optimization and better method dispatch
8. Customize VM ENV variables

Rails 4.0
0.Test coverage is should be good before starting an upgrade.
1. By default thread safe: so have to use gems which are thread safe
2. better utf-8 support
3. better with unicorn like servers
4. Rails 4 prefers Ruby 2.0 and requires 1.9.3 or newer.
5. Some ActionController classes moved to ActionDispatch
6.secret_key_base upgraded carefully , cookies signed based on the new secret_key_base in Rails 4.x are not backwards compatible with Rails( Wait for all users to accommodate new token )
7. Better caching (https://gist.github.com/szimek/1669330)
8.Official upgrade link
    http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html
9. buy a book to upgrade rails 4 ?  here is the link : https://leanpub.com/upgradetorails4

Friday, July 19, 2013

Ruby 'and' 'or' vs && , || precedence

Just like in maths :  Order of Operations - BODMAS   or

In general programming languages, && has higher precedence than || operator.

But in Ruby it is not like that as and or  have same order of precedence.

Lets see one example :

"a" || "b" && "c"  will be assumed as  => "a" || ("b" && "c")

output: "a"  ("b", "c" are never called) why as "a" is always true.

here && has higher precedence than ||

Lets see with and or operations

"a" or "b" and "c"  will be assumed as  => ("a"  or "b") and "c"

output: "c" 


Thursday, July 18, 2013

helpful GIT command aliases

[alias]
   st = status -sb
   ci = commit
   br = branch
   df = diff
   lg = log --pretty=format:'%Cred%h%Creset -%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'
   lg = log -p
   co = checkout
   cp = cherry-pick
   tree = log --graph --decorate --pretty=oneline --abbrev-commit --all
   pom = push origin master
   amend = commit --amend -C HEAD
   wdiff = diff --color-words
   standup = log --since yesterday --author jreddy@reddyonrails.com
   rst = reset --hard
   pr = pull --rebase

You can also add aliases like so, and they will get added to your .gitconfig file automatically.
$ git config –-global --edit

Tuesday, April 09, 2013

Error running 'requirements_brew_libs_install libksba' or libgpg-error Ruby 2.0.0 on MAC, brew and RVM


Problem: 
If you have problem installing ruby 2.0.0 on your mac using rvm and brew. And the problem could be timeout error .

rvm install ruby-2.0.0-p0

Installing requirements for osx, might require sudo password.
Already up-to-date.
Installing required packages: libksba....
^CError running 'requirements_brew_libs_install libksba',
please read /Users/XXX/.rvm/log/ruby-2.0.0-p0/package_install_libksba.log

log file :

(curl: (56) Recv failure: Operation timed out)


Solution: 

vi  /usr/local/Library/Formula/libgpg-error.rb
Replace: url 'ftp://ftp.gnupg.org/gcrypt/libgpg-error/libgpg-error-1.9.tar.gz'
with  url 'http://www.mirrorservice.org/sites/ftp.gnupg.org/gcrypt/libgpg-error/libgpg-error-1.11.tar.gz'

same case with libksba

This should works if it complain sha1 stuff replace expected one on ruby code.

Thursday, March 28, 2013

Brew Update issue

$ brew update
error: The following untracked working tree files would be overwritten by merge:
    Library/Formula/libmusicbrainz.rb
Please move or remove them before you can merge.
Aborting
Error: Failure while executing: git pull -q origin refs/heads/master:refs/remotes/origin/master
 
 
Solution: 

rm /usr/local/Library/Formula/libmusicbrainz.rb
brew update

Thursday, January 24, 2013

Rails pg gem '0.14.1' on Mac fails and solution

pg.c: In function ‘Init_pg_ext’:
pg.c:384: error: ‘PQPING_OK’ undeclared (first use in this function)
pg.c:384: error: (Each undeclared identifier is reported only once
pg.c:384: error: for each function it appears in.)
pg.c:386: error: ‘PQPING_REJECT’ undeclared (first use in this function)
pg.c:388: error: ‘PQPING_NO_RESPONSE’ undeclared (first use in this function)
pg.c:390: error: ‘PQPING_NO_ATTEMPT’ undeclared (first use in this function)
make: *** [pg.o] Error 1

Solution:
env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Library/PostgreSQL/9.2/bin/pg_config

EDIT :
If you dont know where your pg_config is. Assume you are on Linux/Mac system, using the command 'find' should help

find / -name pg_config
 
 


How to copy postgresql data from heroku production

Steps to get the copy of heroku deployed application database to localhost .

1 step: Create a backup on heroku production
       
           heroku pgbackups:capture --expire

2 step:  Get the latest back up to local by curl method

           curl -o backup.dump `heroku pgbackups:url`
3 step: Restore to localhost database using the followng comand
  
   pg_restore --verbose --clean --no-acl --no-owner -h localhost -d your_database_name  backup.dump