Skip to content

Instantly share code, notes, and snippets.

View funny-falcon's full-sized avatar

Sokolov Yura funny-falcon

View GitHub Profile
@funny-falcon
funny-falcon / remove disk
Created April 6, 2012 09:24
SATA hotswap
echo 1 > /sys/block/sd#/device/delete
@funny-falcon
funny-falcon / perf_and_gc.diff
Created May 4, 2012 08:47
Ruby-1.9.3-p194 performance patch
diff --git a/common.mk b/common.mk
index eb89a2b..59cdfe4 100644
--- a/common.mk
+++ b/common.mk
@@ -630,7 +630,8 @@ file.$(OBJEXT): {$(VPATH)}file.c $(RUBY_H_INCLUDES) {$(VPATH)}io.h \
gc.$(OBJEXT): {$(VPATH)}gc.c $(RUBY_H_INCLUDES) {$(VPATH)}re.h \
{$(VPATH)}regex.h $(ENCODING_H_INCLUDES) $(VM_CORE_H_INCLUDES) \
{$(VPATH)}gc.h {$(VPATH)}io.h {$(VPATH)}eval_intern.h {$(VPATH)}util.h \
- {$(VPATH)}debug.h {$(VPATH)}internal.h {$(VPATH)}constant.h
+ {$(VPATH)}debug.h {$(VPATH)}internal.h {$(VPATH)}constant.h \
@funny-falcon
funny-falcon / fiber_pool.rb
Created May 24, 2012 10:03
Simple fiber pool without extra possibilities
# simple fiber pool for EM::Synchrony (or same)
class FiberPool
def initialize(count)
@queue = EM::Queue.new
@count = count
count.times do
fib = Fiber.new do
fiber_loop(fib)
end
fib.resume
@funny-falcon
funny-falcon / em_patch.rb
Created May 28, 2012 12:21
EM finer grained deffered callbacks
def EM.run_deferred_callbacks
until (@resultqueue ||= []).empty?
result,cback = @resultqueue.pop
cback.call result if cback
end
# Capture the size at the start of this tick...
time = Time.now
size = @next_tick_queue.size
cur_ticks = @next_tick_mutex.synchronize{ @next_tick_queue.slice!(0, size) }
@funny-falcon
funny-falcon / test.rb
Created June 1, 2012 09:16
Script for testing kgio_*writev
require 'kgio'
ip = '127.0.0.1' # better write here real IP address of your network card
prc = fork do
srv = Kgio::TCPServer.new(ip, 8000)
sock = srv.kgio_accept(Kgio::TCPSocket)
count = 0
b = ''
while s = sock.kgio_read(1024*1024, b)
@funny-falcon
funny-falcon / latency.txt
Created June 1, 2012 11:10 — forked from jboner/latency.txt
Latency numbers every programmer should know
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 1 MB sequentially from memory 250,000 ns 0.25 ms
Round trip within same datacenter 500,000 ns 0.5 ms
Read 1 MB sequentially from SSD 1,000,000 ns 1 ms 4X memory
@funny-falcon
funny-falcon / ary-queue.diff
Created June 24, 2012 06:26
Test patch for increasing "array as queue" speed
diff --git a/array.c b/array.c
index 64647c3..76fac8a 100644
--- a/array.c
+++ b/array.c
@@ -255,15 +255,24 @@ rb_ary_modify(VALUE ary)
rb_ary_modify_check(ary);
if (ARY_SHARED_P(ary)) {
long len = RARRAY_LEN(ary);
+ VALUE shared = ARY_SHARED(ary);
if (len <= RARRAY_EMBED_LEN_MAX) {
@funny-falcon
funny-falcon / test 1.9.2
Created June 28, 2012 08:19
Object finalizer broken in ruby 1.9.3
$ ruby -v
ruby 1.9.2p320 (2012-04-20 revision 35421) [x86_64-linux]
$ # Ruby 1.9.2 fails to run finalizer until program exit
$ ruby test_finalizer.rb outter
assigned
deassigned
stop
HI 9472020
$ ruby test_finalizer.rb inner
assigned
@funny-falcon
funny-falcon / test_finalizer.rb
Created July 4, 2012 06:21
Test different kind of finalizers
#GC.stress = true
STDOUT.sync = true
$stdout.sync = true
KIND = ARGV[0] || 'inner'
def finalizer(i)
proc{|id| puts "HI #{i} #{id}"}
end
@funny-falcon
funny-falcon / a copyright
Created July 31, 2012 09:52
Writing a minimalistic web-server using event machine