Skip to content

Instantly share code, notes, and snippets.

@mrkvm
mrkvm / Gemfile
Created June 11, 2013 17:45 — forked from mirakui/Gemfile
source :gemcutter
gem 'pit'
gem 'sauberia-aws-s3'
@mrkvm
mrkvm / go1.1-http-bench-linux-vs-freebsd.txt
Created May 30, 2013 04:47
Go http benchmark comparison. Linux (old) vs. FreeBSD (new). Note especially the significant slowdown in client/server numbers.
benchmark old ns/op new ns/op delta
BenchmarkHeaderWriteSubset 1925 2241 +16.42%
BenchmarkReadRequestChrome 10393 12791 +23.07%
BenchmarkReadRequestCurl 5424 6398 +17.96%
BenchmarkReadRequestApachebench 5145 6348 +23.38%
BenchmarkReadRequestSiege 7212 8892 +23.29%
BenchmarkReadRequestWrk 3428 4220 +23.10%
BenchmarkClientServer 90999 8016844 +8709.82%
BenchmarkClientServerParallel4 81917 2027296 +2374.82%
BenchmarkClientServerParallel64 76994 200184 +160.00%
@mrkvm
mrkvm / README.md
Last active December 16, 2015 15:09
Simple sqlite stress program to reproduce the following issue: https://github.com/mattn/go-sqlite3/issues/51

Fills a single table and launches several goroutines to do concurrent SELECT operations.

We are running this on a fairly beefy machine with 24 CPUs and can reproduce the issue fairly quickly with the parameters in the test. Output file is also attached with the crash.

Here's our environment:

[root@flash1 sqlitetest]# go version
go version devel +8153882a36e8 Wed Apr 03 11:13:40 2013 -0700 linux/amd64

[root@flash1 sqlitetest]# go env

@mrkvm
mrkvm / trickortreat.rb
Created October 31, 2012 20:48
A ridiculous Halloween-themed example of stats tracking using Redis bitwise operations
require 'redis'
class TrickOrTreatTracker
def initialize
@redis = Redis.new
end
def track_trick(user_id)
key = "trick-#{Time.now.hour}"
@redis.setbit key, user_id, 1
@mrkvm
mrkvm / redis_set_if_not_defined.rb
Created October 29, 2012 21:11
Ruby method to set a Redis key if it's not already defined using a Lua script.
require 'redis'
# Lua script to set a Redis key if it doesn't exist yet.
# Returns result of SET if key is not set, otherwise
# returns the previous value of the key.
SetScript = <<EOF
local val = redis.call('GET', KEYS[1])
if val == false then
return redis.call('SET', KEYS[1], ARGV[1])
end
@mrkvm
mrkvm / multiset.rb
Created October 22, 2012 04:47
Simple Ruby method to do a multi-set on a bunch of Redis keys together.
require 'redis'
# Simple Lua script to set all the given keys to the given values.
# Note the magic of this is that it's done atomically. Yay atomicity!
MultiSetScript = <<EOF
for i = 1, #KEYS do
redis.call('SET', KEYS[i], ARGV[i])
end
EOF
-- Get a key containing JSON in Redis
local key = KEYS[1];
local name = ARGV[1];
local data = redis.call('GET', key);
if not data then
return '';
else
local json = cjson.decode(redis.call('GET', key));
-- Set a key containing JSON in Redis
local key = KEYS[1];
local name = ARGV[1];
local value = ARGV[2];
local data = redis.call('GET', key);
local json;
if not data then
json = {};
-- iterate over Redis hash in Lua.
local results = redis.call("HGETALL", KEYS[1]);
if results ~= 0 then
for key, value in ipairs(results) do
-- do something here
end
end
@mrkvm
mrkvm / redis_examples.txt
Created October 21, 2012 19:00
A very, very simple Redis PUB/SUB example
# Redis PUB/SUB example:
# client 1:
redis 127.0.0.1:6379> subscribe beartalk
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "beartalk"
3) (integer) 1
# ...wait around for message...