Skip to content

Instantly share code, notes, and snippets.

require 'rubygems'
require 'tokyo_tyrant'
TYRANT = TokyoTyrant::Table.new
AMOUNT_RECORDS = 8000
$TYRANT_ID = 0
RECORD = {
"component_version" => "X",
"state" => "Analyze",
require "rubygems"
require "rbench"
def omg_slow
return 1
end
def omg_fast
1
end
# fix memory caching in dev mode
# put this in config/initializers/fix_caching_in_dev.rb
# Hopefully this won't be needed for long, this fixes cache calls (due to class reloading in dev)
# http://blog.bashme.org/2008/07/25/rails-21-model-caching-issue/
if ActiveSupport::Dependencies.mechanism == :load
module ActiveSupport
module Cache
class Store
@actsasflinn
actsasflinn / TokyoTyrant Balancer Benchmark
Created November 15, 2009 06:13
Experimental Tokyo Tyrant Balancer Benchmark
TokyoTyrant Single Node
user system total real
inserting data 0.320000 0.170000 0.490000 ( 1.415912)
reading data 0.310000 0.170000 0.480000 ( 1.394186)
TokyoTyrant Balanced 3 nodes using Ruby C Fast Hash Ring
user system total real
inserting data 0.300000 0.170000 0.470000 ( 1.464022)
reading data 0.350000 0.170000 0.520000 ( 1.489997)
@actsasflinn
actsasflinn / FastHashRing_Benchmark.rb
Created November 15, 2009 06:55
FastHashRing (Ruby C Extension) vs HashRing (pure Ruby)
# Spoiler...
# user system total real
# Hash Ring 4.580000 0.040000 4.620000 ( 4.785069)
# Fash Hash Ring 0.080000 0.000000 0.080000 ( 0.087039)
#
require 'benchmark'
require 'rubygems'
require 'faker'
require 'hash_ring'
require 'fast_hash_ring'
scopes[:your_composite_scope_name] = proc{ Scope.new(your.combined.scopes.here, {}) }
def self.your_composite_scope_name(*args)
scopes[:your_composite_scope_name].call(self, *args)
end
# nginx with memcache module... after a request the connection to memcached closes, what gives?
http {
upstream memcache {
server 127.0.0.1:11211;
keepalive 1024 single; # with this or without http://mdounin.ru/hg/ngx_http_upstream_keepalive/
}
server {
listen 80;
@actsasflinn
actsasflinn / msgpack_benchmark.rb
Created January 30, 2010 05:07
Message Pack vs similar utilities
=begin
Message Pack vs similar utilities
ruby 1.8.7 (2010-04-19 patchlevel 253) [i686-darwin10.0.0], MBARI 0x6770, Ruby Enterprise Edition 2010.02
Packing
user system total real
pack: bert 18.320000 0.770000 19.090000 ( 19.101583)
pack: bson_ext 0.850000 0.030000 0.880000 ( 0.878398)
pack: json_ext 2.540000 0.040000 2.580000 ( 2.582495)
@actsasflinn
actsasflinn / tcadb_misc_iterrec_iterout_for_bdb.patch
Created March 30, 2010 00:46
Tokyo Cabinet patch adds iterrec and iterout to tcadbmisc
--- tcadb.c.orig 2010-03-11 09:55:29.000000000 -0500
+++ tcadb.c 2010-03-13 15:34:13.000000000 -0500
@@ -2423,6 +2423,25 @@ TCLIST *tcadbmisc(TCADB *adb, const char
tclistdel(rv);
rv = NULL;
}
+ } else if(!strcmp(name, "iterrec")){
+ rv = tclistnew2(1);
+ int ksiz;
+ const char *kbuf = tcbdbcurkey3(adb->cur, &ksiz);
@actsasflinn
actsasflinn / macosx_snow_leopard_socket_fix.patch
Created March 30, 2010 01:04
Tokyo Tyrant patch fix unix sockets on Mac OSX Snow Leopard
--- ttutil.c.orig 2010-03-13 00:33:29.000000000 -0500
+++ ttutil.c 2010-03-13 00:34:05.000000000 -0500
@@ -127,7 +127,7 @@ int ttopensockunix(const char *path){
struct sockaddr_un saun;
memset(&saun, 0, sizeof(saun));
saun.sun_family = AF_UNIX;
- snprintf(saun.sun_path, SOCKPATHBUFSIZ, "%s", path);
+ strncpy(saun.sun_path, path, sizeof(saun.sun_path)-1);
int fd = socket(PF_UNIX, SOCK_STREAM, 0);
if(fd == -1) return -1;