Skip to content

Instantly share code, notes, and snippets.

View tmm1's full-sized avatar

Aman Karmani tmm1

View GitHub Profile
@tmm1
tmm1 / emcache.rb
Created February 12, 2009 21:04
em and fibered memcache client
require 'rubygems'
require 'eventmachine'
module EM::Protocols::Memcache
include EM::Protocols::LineText2
include EM::Deferrable
Cstored = 'STORED'.freeze
Cend = 'END'.freeze
if __FILE__ == $0
require 'em/spec'
class TestConnection
include EM::P::Memcache
def send_data data
sent_data << data
end
def sent_data
@sent_data ||= ''
diff --git a/ext/rubymain.cpp b/ext/rubymain.cpp
index 1e0dd6f..4eb7738 100644
--- a/ext/rubymain.cpp
+++ b/ext/rubymain.cpp
@@ -33,24 +33,36 @@ static VALUE EmConnection;
static VALUE Intern_at_signature;
static VALUE Intern_at_timers;
static VALUE Intern_at_conns;
+static VALUE Intern_at_error_handler;
static VALUE Intern_event_callback;
class ReactorLatency < Graph
name 'reactor_latency'
vlabel 'microseconds'
scale 'no'
category 'application'
next_tick 'next_tick latency'
timer 'timer latency'
def self.fetch
@tmm1
tmm1 / em-strace-filter.rb
Created March 1, 2009 05:28
filter strace logs for an epoll em reactor to find latency
#!/usr/bin/env ruby
#
# Use to filter strace output associated with ruby/EM processes running with EM.epoll
# sudo strace -ttTp <ruby process pid> -o ruby.strace
# cat ruby.strace | ./em-strace-filter.rb > filtered.strace
#
require 'time'
begin_time = nil
end_time = nil
@tmm1
tmm1 / a.txt
Created March 4, 2009 02:27
simple heap dumper for ruby 1.8
$ ./miniruby -e 'class T; end; a = 1..1; b = "hi"; c = []; d = Hash.new; e = T.new; p GC.dump_heap'
0x00154750 allocated @ -e:1 is an OBJECT of type: T
0x0015476c allocated @ -e:1 is a HASH which has data
0x00154788 allocated @ -e:1 is an ARRAY of len: 0.
0x001547c0 allocated @ -e:1 is a STRING (ELTS_SHARED) which has len: 2 and val: hi
0x001547dc allocated @ -e:1 is a STRING which has len: 1 and val: T
0x001547f8 allocated @ -e:1 which is a CLASS no name - maybe anon class?
0x00154814 allocated @ -e:1 which is a CLASS named: T inherits from Object
0x00154a98 allocated @ -e:1 is a STRING which has len: 2 and val: hi
0x00154b40 allocated @ -e:1 is an OBJECT of type: Range
class GCTime < Graph
name 'gc_time'
title 'Time spent in GC'
vlabel 'microseconds'
category 'gc'
gc_len 'musec in GC'
def self.fetch
if GC.respond_to? :time
require 'rubygems'
require 'eventmachine'
### EM::run takes over the process
# puts 1
# EM.run{
# require 'mycode'
# }
# puts 3 # this will never happen
@tmm1
tmm1 / gist:80053
Created March 16, 2009 20:27 — forked from raggi/gist:79926
# async_sinatra_example.ru
require 'sinatra'
# Normally Sinatra::Base expects that the completion of a request is
# determined by the block exiting, and returning a value for the body.
#
# In an async environment, we want to tell the webserver that we're not going
# to provide a response now, but some time in the future.
#
# The a* methods provide a method for doing this, by informing the server of
diff --git a/lib/nanite/agent.rb b/lib/nanite/agent.rb
index 8cb8900..87da714 100644
--- a/lib/nanite/agent.rb
+++ b/lib/nanite/agent.rb
@@ -178,17 +178,21 @@ module Nanite
def setup_traps
['INT', 'TERM'].each do |sig|
- trap(sig) do
+ old = trap(sig) do