Thursday, December 18, 2014

Security issues with git : upted required for Git clients

Even though the issue may not affect Linux users, if you are a
hosting service whose users may fetch from your service to Windows
or Mac OS X machines, you are strongly encouraged to update to
protect such users who use existing versions of Git.
 
source :  
 
 http://article.gmane.org/gmane.linux.kernel/1853266
 
 Updated versions on Github are here :
 
 GitHub for Windows and GitHub for Mac 
 
 
 

Thursday, November 06, 2014

making underscore.js dependency to angular js


var app = angular.module('app', ['underscore']);
app.controller('AppController', ['$scope', '_', function ($scope, _) {
  initialize = function () {
    _.keys($scope);
  }
  initialize();
}]);

underscore.factory('_', function () {
  return window._;
});

Thursday, May 08, 2014

Ruby 2.1.0 some useful changes

return in lambda
def yield_me
 yield
end

def run
  yield_me(&lambda {return "call from lambda"})
  "call from run method"
end

run   #=> "call from run method"
The example above would have returned "call from lambda" in  Ruby  previous ruby versions
---------------------------------------------------------------------------------------------------------------
#singleton_class?
class Test
  singleton_class?     #=> false
  class << self
    singleton_class?   #=> true
  end
end

Object#singleton_method
class Test
  def self.one
  end

  def two
  end
end

# returns class method
Test.singleton_method(:one)    #=> #
# doesn't return instance method
Test.singleton_method(:two)   #=> #-----------------------------------------------------------------------------------------------------------------
Method#original_name
To return the un-aliased name.
class Example
  def foo
    "foo"
  end
  alias bar foo
end

example = Example.new
example.method(:foo).original_name            #=> :foo
example.method(:bar).original_name            #=> :foo
Example.instance_method(:bar).original_name   #=> :foo




For more changes please visit here: 

https://github.com/ruby/ruby/blob/v2_1_0/NEWS

Friday, March 28, 2014

Ruby 2.1 and Garbage Collection issue and memory bloats in production unicorn and Phusion passenger

Are you working with Unicorn and getting memory leak issues with ruby 2.1 . A better explained scenario on memory allocation on heap with huge strings ,array and hashes in Ruby 2.1 by this author himself here :

 http://www.atdot.net/~ko1/activities/rubyconf2013-ko1_pub.pdf 

Whats the problem?

in his blog :
http://www.omniref.com/blog/blog/2014/03/27/ruby-garbage-collection-still-not-ready-for-production/

Well not sure about unicorn solution but Aman Gupta has a solution for Phusion Passenger.
as announced an Out-Of-Band garbage collector for Ruby 2.1.

Here is the Phusion Passenger blog on that one and usage. 



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" 


Ruby On Rails Casts

Loading...