Skip to content

Instantly share code, notes, and snippets.

Avatar

Kenn Ejima kenn

  • San Francisco
View GitHub Profile
View memstats.rb
#!/usr/bin/env ruby
#------------------------------------------------------------------------------
# Aggregate Print useful information from /proc/[pid]/smaps
#
# pss - Roughly the amount of memory that is "really" being used by the pid
# swap - Amount of swap this process is currently using
#
# Reference:
# http://www.mjmwired.net/kernel/Documentation/filesystems/proc.txt#361
@kenn
kenn / gist:5228906
Last active Feb 15, 2016
DigitalOcean per-core pricing
View gist:5228906

CPU Price Performance: DigitalOcean vs Linode

On DigitalOcean, as you go up the plan, you get higher per-core price as well.

https://www.digitalocean.com/pricing

$5 1 core     - $5/core
$10 1 core    - $10/core
View gist:7071032
SELECT * FROM
(SELECT id FROM sort_keys ORDER BY sort_key) INNER JOIN main_table ON sort_keys.id = main_table.id
WHERE ... OFFSET 0 LIMIT 10
@kenn
kenn / gist:7061067
Last active Dec 25, 2015
Validating MinHash's errors
View gist:7061067
require 'digest'
a = (0..100000).map{|i| Digest::SHA1.hexdigest(i.to_s).hex }
a.map.with_index{|i,idx| i > a[idx-1] }.group_by{|i| i }.map{|k,v| [k,v.size] }
# => [[true, 499235], [false, 500766]]
View gist:5937325
# Undo require 'active_support/core_ext/object/to_json'
require 'yajl'
[Object, Array, Hash].each do |klass|
klass.class_eval <<-RUBY, __FILE__, __LINE__
def jsonize(options = nil)
::Yajl::Encoder.encode(self)
end
RUBY
end
View gist:5436279
E, [2013-04-22T15:04:52.652797 #8734] ERROR -- : listen loop error: closed stream (IOError)
E, [2013-04-22T15:04:52.652852 #8734] ERROR -- : /usr/local/rvm/gems/ruby-2.0.0-p0/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:652:in `select'
E, [2013-04-22T15:04:52.652886 #8734] ERROR -- : /usr/local/rvm/gems/ruby-2.0.0-p0/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:652:in `worker_loop'
E, [2013-04-22T15:04:52.652918 #8734] ERROR -- : /usr/local/rvm/gems/ruby-2.0.0-p0/gems/newrelic_rpm-3.6.0.83/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb:22:in `call'
E, [2013-04-22T15:04:52.652950 #8734] ERROR -- : /usr/local/rvm/gems/ruby-2.0.0-p0/gems/newrelic_rpm-3.6.0.83/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb:22:in `block (4 levels) in <top (required)>'
E, [2013-04-22T15:04:52.652981 #8734] ERROR -- : /usr/local/rvm/gems/ruby-2.0.0-p0/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:500:in `spawn_missing_workers'
E, [2013-04-22T15:04:52.653013 #8734] ERROR -- : /usr/local/rvm/gems/ruby
View gist:5191853
# hdparm -tf /dev/xvda
/dev/xvda:
Timing buffered disk reads: 714 MB in 3.01 seconds = 237.55 MB/sec
# bonnie++ -b -u root
Version 1.96 ------Sequential Output------ --Sequential Input- --Random-
Concurrency 1 -Per Chr- --Block-- -Rewrite- -Per Chr- --Block-- --Seeks--
Machine Size K/sec %CP K/sec %CP K/sec %CP K/sec %CP K/sec %CP /sec %CP
View gist:5191215
# hdparm -tf /dev/xvda
/dev/xvda:
Timing buffered disk reads: 638 MB in 3.03 seconds = 210.52 MB/sec
# bonnie++ -b -u root
Version 1.96 ------Sequential Output------ --Sequential Input- --Random-
Concurrency 1 -Per Chr- --Block-- -Rewrite- -Per Chr- --Block-- --Seeks--
Machine Size K/sec %CP K/sec %CP K/sec %CP K/sec %CP K/sec %CP /sec %CP
@kenn
kenn / gist:5105175
Last active Dec 14, 2015
Unicorn memory usage improvement with Ruby 2.0.0
View gist:5105175

Unicorn memory usage improvement with Ruby 2.0.0

Here's a preliminary experiment to see how much memory is saved with the new copy-on-write friendly (bitmap marking) GC.

Calculated by memstats.rb https://gist.github.com/kenn/5105061 on Debian x86_64.

Master process:

# ./memstats.rb 20547
@kenn
kenn / gist:4742470
Last active Dec 12, 2015
DigitalOcean 512 with Virtio: Disk I/O benchmark using bonnie++
View gist:4742470
# hdparm -tf /dev/vda
/dev/vda:
Timing buffered disk reads: 2102 MB in 3.00 seconds = 700.08 MB/sec
# bonnie++ -b -u root
Version 1.96 ------Sequential Output------ --Sequential Input- --Random-
Concurrency 1 -Per Chr- --Block-- -Rewrite- -Per Chr- --Block-- --Seeks--
Machine Size K/sec %CP K/sec %CP K/sec %CP K/sec %CP K/sec %CP /sec %CP