Skip to content

Instantly share code, notes, and snippets.

View colinsurprenant's full-sized avatar

Colin Surprenant colinsurprenant

View GitHub Profile
@colinsurprenant
colinsurprenant / topology.rb
Created July 29, 2013 18:38
RedStorm JRuby performance options
class SomeTopology < RedStorm::DSL::Topology
configure do
debug false
# I reached optimal perf using one worker per node.
# set num_workers to N where N is the number of nodes in your cluster
num_workers 1 # one-node cluster
set "topology.worker.childopts", "-Djruby.compile.invokedynamic=true -Djruby.jit.threshold=0 -Djruby.jit.max=-1 -Djruby.ji.objectProxyCache=false"
end
@colinsurprenant
colinsurprenant / CallJRuby.java
Last active December 31, 2018 04:59
calling JRuby from Java example
import org.jruby.Ruby;
import org.jruby.runtime.Helpers;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.javasupport.JavaUtil;
import org.jruby.RubyClass;
import org.jruby.RubyModule;
public class CallJRuby {
private static final Ruby __ruby__ = Ruby.getGlobalRuntime();
@colinsurprenant
colinsurprenant / closure_invocation.rb
Created June 26, 2013 17:53
benchmarks for 3 different ways to dynamically invoke a closure in an instance context
require 'benchmark'
class DSL1
def initialize
@i = 1
end
def self.register(&block)
@block = block
@colinsurprenant
colinsurprenant / frame_sharing.rb
Created June 26, 2013 16:36
examples of the closure frame sharing across threads. these are in the context of a class level dsl with a code block registration and its execution from its instance. DSL 1, 2 and 3 all reproduce the problem, DSL 4 works around it but defeats the dsl idea. for the actual bug see https://jira.codehaus.org/browse/JRUBY-7167
# block executed using instance_exec
class DSL1
def self.register(&block)
@block = block
end
def execute(str)
instance_exec(str, &self.class.block)
end
@colinsurprenant
colinsurprenant / ec2_openvpn_setup.md
Last active July 25, 2017 15:35
EC2 and OSX OpenVPN setup

EC2/Ubuntu OpenVPN server config

  • open UDP port 1194 using EC2 security groups
sudo apt-get install openvpn
sudo openvpn —genkey —secret /etc/openvpn/openvpn-key.txt
sudo modprobe iptable_nat
echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward
sudo iptables -t nat -A POSTROUTING -s 10.8.0.1/2 -o eth0 -j MASQUERADE
@colinsurprenant
colinsurprenant / Vagrantfile
Created March 9, 2013 20:45
Vagrant & Chef-Solo configuration for: rbenv with both MRI Ruby 1.9.3 and JRuby 1.7.3 with Bundler gem installed, MySQL, Redis, Nginx, Node.js & npm, Java OpenJDK 1.7, git and the build-essential tools.
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant::Config.run do |config|
config.vm.box = "quantal64_vb428"
config.vm.customize ["modifyvm", :id, "--memory", 512]
config.ssh.forward_agent = true
config.vm.provision :chef_solo do |chef|

Quick bench of MRI Ruby 1.9.3-p392 vs 2.0.0-p0 vs JRuby 1.7.3 for computing 2000000 MD5, SHA-1 & FNV hashes. The goal of this benchmark is mainly to compare the ffi vs c-ext performance.

A MBP with a 3GHz Intel Dual Core i7 and OSX 10.8.2 was used. Rubies managed with rbenv.

  • MD5 & SHA-1 are part of the Ruby stdlib.
  • native FNV is in pure Ruby.
  • ffi FNV is in C and for the exception of the first unwarmed JRuby test, all are using :buffer_in in place of :string & :save_errno => false
  • c-ext FNV is in C and only run in MRI
  • the JRuby warming process is done on every hash test by running it once and then benchmarking the second.
@colinsurprenant
colinsurprenant / fnv_bench.md
Last active December 14, 2015 05:29
quick bench of MRI Ruby 1.9.3-p392 vs JRuby 1.7.3 computing hashes. MD5 & SHA-1 are part of the standard libraries. native FNV is in pure Ruby. ffi and c-ext FNV are in C. Just ran these while refactoring for ffi-compiler & JRuby 1.7.3 my https://github.com/colinsurprenant/bloombroom gem.

JRuby 1.7.3

benchmarking for 1000000 iterations
                         user     system      total        real
MD5:                 1.400000   0.040000   1.440000 (  1.007000)
SHA-1:               1.450000   0.010000   1.460000 (  1.043000)
native FNV A 32:     8.620000   0.050000   8.670000 (  8.197000)
native FNV A 64:    11.950000   0.050000  12.000000 ( 11.717000)
native FNV B 32:     3.290000   0.010000   3.300000 (  3.036000)
native FNV B 64:    11.670000   0.060000  11.730000 ( 11.286000)
@colinsurprenant
colinsurprenant / storm_perf.java
Created July 24, 2012 21:00
Storm performance topology
package storm.starter;
import backtype.storm.Config;
import backtype.storm.StormSubmitter;
import backtype.storm.spout.SpoutOutputCollector;
import backtype.storm.task.TopologyContext;
import backtype.storm.topology.BasicOutputCollector;
import backtype.storm.topology.OutputFieldsDeclarer;
import backtype.storm.topology.TopologyBuilder;
import backtype.storm.topology.base.BaseBasicBolt;
@colinsurprenant
colinsurprenant / Gemfile
Created June 12, 2012 20:43
Raad simple JRuby service example with Sinatra and Puma
source :rubygems
gem 'raad'
gem 'puma'
gem 'sinatra'