This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Server launched: 10 acceptors, 10 workers. | |
Exception in thread "RubyThread-34: /Users/ryan/fun/timeserver/lib/timeserver/server.rb:37" java.nio.channels.IllegalBlockingModeException | |
at java.nio.channels.spi.AbstractSelectableChannel.configureBlocking(AbstractSelectableChannel.java:257) | |
at org.jruby.util.io.SelectBlob.tidyUp(SelectBlob.java:352) | |
at org.jruby.util.io.SelectBlob.goForIt(SelectBlob.java:94) | |
at org.jruby.RubyIO.select_static(RubyIO.java:3398) | |
at org.jruby.RubyIO.select(RubyIO.java:3394) | |
at org.jruby.RubyIO$INVOKER$s$0$3$select.call(RubyIO$INVOKER$s$0$3$select.gen:65535) | |
at org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:69) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Server created with 5 acceptors and 10 workers. | |
Exception in thread "RubyThread-15: server.rb:1" java.lang.NullPointerException | |
at org.jruby.ext.socket.RubyTCPServer.accept(RubyTCPServer.java:180) | |
at org.jruby.ext.socket.RubyTCPServer$i$0$0$accept.call(RubyTCPServer$i$0$0$accept.gen:65535) | |
at org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:133) | |
at server.chained_5_rescue_2$RUBY$SYNTHETICrun_acceptors(server.rb:35) | |
at server.chained_4_rescue_1$RUBY$SYNTHETICrun_acceptors(server.rb:34) | |
at server.block_1$RUBY$run_acceptors(server.rb:33) | |
at server$block_1$RUBY$run_acceptors.call(server$block_1$RUBY$run_acceptors:65535) | |
at org.jruby.runtime.CompiledBlock19.yield(CompiledBlock19.java:163) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'socket' | |
require 'thread' | |
# Example of a "threaded preforking" server using multiple acceptor threads | |
# and a pool of worker threads to service the actual requests. Note | |
# that this is similar to a real preforking server that uses Kernel#fork | |
# to service requests concurrently with a single listener socket. The only | |
# difference is that instead of multiple forked processes, we use multiple | |
# acceptor threads. | |
class Server |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'aws-sdk' | |
module RequestDumper | |
def new(*args, &block) | |
super.extend(DumpRequests) | |
end | |
module DumpRequests | |
def request(*args, &block) | |
puts "SENDING: #{args.first.body}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def process(msg) | |
klass = constantize(msg['class']) | |
invoke_chain(klass.new, msg) | |
@boss.processor_done!(current_actor) | |
end | |
def invoke_chain(worker, msg) | |
chain = Sidekiq::Middleware::Chain.retrieve.dup | |
traverse_chain = lambda do | |
if chain.empty? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
big_hash = 10_000.times.with_object({}) { |i, hash| hash[i] = Array.new(i) } | |
Benchmark.bm do |x| | |
x.report("values.min") { big_hash.values.min } | |
x.report("each_value.min") { big_hash.each_value.min } | |
end | |
__END__ | |
$ ruby speed.rb | |
user system total real |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Using /Users/ryan/.rvm/gems/ruby-1.9.2-p290 | |
[1] pry(main)> class Foo | |
[1] pry(main)* define_method(:hmm, proc { |x,y| p [x,y] }) | |
[1] pry(main)* end | |
=> #<Proc:0x007f8cab911060@(pry):2 (lambda)> | |
[2] pry(main)> Foo.new.hmm(1) | |
ArgumentError: wrong number of arguments (1 for 2) | |
from (pry):2:in `block in <class:Foo>' | |
[3] pry(main)> Foo.new.hmm(1,2) | |
[1, 2] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[1] pry(main)> def foo | |
[1] pry(main)* binding | |
[1] pry(main)* end | |
=> nil | |
[2] pry(main)> b = foo { puts 'hi!' } | |
=> #<Binding:0x007f8b7a0e2ec0> | |
[3] pry(main)> b.eval('Proc.new').call | |
(pry):5: [BUG] Segmentation fault | |
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.0.1] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class M | |
def self.foo | |
puts Z | |
end | |
class Z | |
end | |
end | |
M.foo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'base64' | |
require 'socket' | |
require 'fileutils' | |
# UnixSocketForker is an experiment of inter-process communication using | |
# plain unix sockets to communicate between forked processes and the | |
# parent process. This can also be done via IO.pipe. In this experiment, | |
# the jobs are simply random arrays whose sums are calculated in the forked | |
# worker processes. | |
class UnixSocketForker |