Permalink
Browse files

basic structure

  • Loading branch information...
0 parents commit c7d6dbb4400f8e475ff1aa46bf5206dd8a4dacdc Nick Kallen committed Apr 12, 2009
Showing with 110 additions and 0 deletions.
  1. +30 −0 jb
  2. +6 −0 joke_cluster.rb
  3. +15 −0 joke_server.rb
  4. +35 −0 proxy.rb
  5. +24 −0 talk_outline.txt
30 jb
@@ -0,0 +1,30 @@
+#!/usr/bin/env ruby
+
+require 'benchmark'
+require 'rubygems'
+require 'activesupport'
+require 'socket'
+
+count = 10000
+concurrency = 10
+count_per_worker = count / concurrency
+
+host = "0.0.0.0"
+port = 10001
+
+benchmark = Benchmark.measure do
+ threads = []
+ concurrency.times do
+ threads << Thread.new do
+ count_per_worker.times do
+ socket = TCPSocket.new(host, port)
+ socket.print("\n")
+ response = socket.gets
+ end
+ end
+ end
+ threads.each(&:join)
+end
+
+puts "#{benchmark.real}"
+puts "#{benchmark.real / count_per_worker}"
@@ -0,0 +1,6 @@
+count = 10
+
+count.times do |count|
+ port = 1000 + count
+ System.fork("./joke_server.rb -p#{port}")
+end
@@ -0,0 +1,15 @@
+#!/usr/bin/env ruby
+
+require 'rubygems'
+require 'eventmachine'
+
+module JokeServer
+ def receive_data(data)
+ send_data("knock knock\n")
+ # output w3c data with user, sys, and real
+ end
+end
+
+EM.run do
+ EM.start_server "0.0.0.0", 10001, JokeServer
+end
@@ -0,0 +1,35 @@
+#!/usr/bin/env ruby
+
+require 'rubygems'
+require 'eventmachine'
+require 'socket'
+
+class Server
+ def initialize(host, port)
+ @socket = TCPSocket.new(host, port)
+ end
+
+ def forward(data)
+ @socket.print(data)
+ @socket.gets
+ end
+end
+
+module ProxyServer
+ def receive_data(data)
+ send_data(server.forward(data))
+ # output w3c data with user, sys, and real
+ end
+
+ def server
+ # RoundRobinSocketBalancer.new(socket1, socket2, socket3)
+ # RandomSocketBalancer.new(socket1, socket2, socket3)
+ # BusynessSocketBalancer.new(socket1, socket2, socket3)
+ # StickySocketBalancer.new(socket1, socket2, socket3)
+ @server ||= Server.new("0.0.0.0", 10001)
+ end
+end
+
+EM.run do
+ EM.start_server "0.0.0.0", 10000, ProxyServer
+end
@@ -0,0 +1,24 @@
+Theme #1: Distribution, Balance, and Locality
+
+Introduction: A Basic Network Service
+
+# Distribution
+Load Test Service
+Explain concept of IO vs CPU time
+Calculate the optimal # of workers per core
+
+# Load Balancing
+Write a Proxy
+Show Round-Robin, Random, and By-busyness
+
+# Locality
+Cache results in-process
+Fallback to network cache
+Compute
+Proxy without stickyness
+Proxy with stickyness
+
+# Other Balancing Schemes
+Client-side Partitioning
+Peer-to-Peer
+Name Server

0 comments on commit c7d6dbb

Please sign in to comment.