Skip to content

Instantly share code, notes, and snippets.

View arp's full-sized avatar

Artur Pyrogovskyi arp

View GitHub Profile
@arp
arp / allocation_map.rb
Created May 31, 2013 11:28
Ruby 1.9 (MRI): list allocated objects by locations in the source files where objects were allocated.
# Ruby has #source_location method that returns code location where a method was declared.
# What Ruby lacks is alike functionality that could show where an object was created.
# Below is a very rough solution that may help with tracing object allocations
# by storing the first entry in the caller list during object initialization phase.
# It doesn't work for built-in classes like Fixnum and for classes that don't invoke #initialize()
# like the ones derived from ActiveRecord::Base, but can be potentially tailored to address
# at least the latter case by overriding ActiveRecord::Base.new in addition to overriding #initialize()
class BasicObject
attr_reader :allocated_at
@arp
arp / allocation_map.rb
Created May 31, 2013 11:28
Ruby 1.9 (MRI): list allocated objects by locations in the source files where objects were allocated.
# Ruby has #source_location method that returns code location where a method was declared.
# What Ruby lacks is alike functionality that could show where an object was created.
# Below is a very rough solution that may help with tracing object allocations
# by storing the first entry in the caller list during object initialization phase.
# It doesn't work for built-in classes like Fixnum and for classes that don't invoke #initialize()
# like the ones derived from ActiveRecord::Base, but can be potentially tailored to address
# at least the latter case by overriding ActiveRecord::Base.new in addition to overriding #initialize()
class BasicObject
attr_reader :allocated_at
@arp
arp / allocation_map.rb
Created May 31, 2013 11:27
Ruby 1.9 (MRI): list allocated objects by locations in the source files where objects were allocated.
# Ruby has #source_location method that returns code location where a method was declared.
# What Ruby lacks is alike functionality that could show where an object was created.
# Below is a very rough solution that may help with tracing object allocations
# by storing the first entry in the caller list during object initialization phase.
# It doesn't work for built-in classes like Fixnum and for classes that don't invoke #initialize()
# like the ones derived from ActiveRecord::Base, but can be potentially tailored to address
# at least the latter case by overriding ActiveRecord::Base.new in addition to overriding #initialize()
class BasicObject
attr_reader :allocated_at
@arp
arp / memory_leaker.rb
Last active December 14, 2015 09:09
A script that tries to eat up 2GB of RAM every second. Can be used to test if memory usage alerts work correctly.
#!/usr/bin/env ruby
#
# This script tries to eat up 2GB of RAM every second
# It can be used to test if memory usage alerts work correctly
GB_PER_STEP = 2
str = ''
ate = 0
puts "Hey, you do have too much free RAM! Don't worry as we'll fix this very soon."
@arp
arp / gist:3636434
Created September 5, 2012 13:22 — forked from wardbekker/gist:3636361
R15B02 install script
require 'formula'
class ErlangManuals < Formula
url 'http://erlang.org/download/otp_doc_man_R15B02.tar.gz'
end
class ErlangHtmls < Formula
url 'http://erlang.org/download/otp_doc_html_R15B02.tar.gz'
end
@arp
arp / memflood.rb
Created August 28, 2012 00:57
Memcached flood
#!/usr/bin/env ruby
#
# A simple tool for testing Memcached's evictions functionality.
#
# It saves TOTAL_BYTES of data in chunks of CHUNK_BYTES size.
# Well-behaving Memcached server should start evicting old data
# unless it's configured to return error on memory exhaustion.
#
require 'rubygems'
@arp
arp / multi-threaded-http-client-rails.rb
Created April 28, 2012 11:21
Multi-threaded HTTP requests that help utilize multiple CPU cores in Rails by requerying the app itself
# This way we re-query the app itself in order to avoid sequential execution for CPU-intensive tasks
# that can (and should) be executed in parallel.
#
# Pros: decent scalability can be achieved by assigning path=some.load.balancer.com (i.e. Amazon ELB)
# and putting a bunch of multicore machines behind it.
#
# Cons: we lose some fraction of time on JSON encoding/decoding and HTTP traffic.
# Load-balanced fault-tolerant DRb could be a better choice, but would require more work and provide only
# minor performance improvement in situation where JSON/HTTP aren't the main CPU consumers.
@arp
arp / gist:1179750
Created August 30, 2011 00:03
cucumber-chef 1.0.3 "Get System Log" in AWS Management Console (ami-339ca947)
Xen Minimal OS!
start_info: 0xb10000(VA)
nr_pages: 0x6a400
shared_inf: 0xbef32000(MA)
pt_base: 0xb13000(VA)
nr_pt_frames: 0x9
mfn_list: 0x967000(VA)
mod_start: 0x0(VA)
mod_len: 0
flags: 0x0
@arp
arp / redis_test.txt
Created June 27, 2011 23:59
Goliath Benchmarks
### machine1$ ruby redis_test.rb -c conf.rb
### machine2$ ab -n 10000 -c 100 http://***.compute-1.amazonaws.com:9000/
### ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]
### Redis server version 2.2.11 (00000000:0)
### goliath (0.9.1), em-synchrony (0.3.0.beta.1), eventmachine (1.0.0.beta.3)
### Redis pool size: 10
### GC: enabled