Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 45 lines (38 sloc) 1.257 kb
c7d6dbb4 » Nick Kallen
2009-04-11 basic structure
1 #!/usr/bin/env ruby
2
c76a1284 » Nick Kallen
2009-04-16 with defer
3 ['rubygems', 'eventmachine', 'activesupport', 'optparse'].each { |dependency| require dependency }
b18fe817 » Nick Kallen
2009-04-17 less stupid threading
4 ['util/statosaurus', 'util/synchronizable', 'util/line_buffered_connection', 'util/in_process_lru_cache'].each { |dependency| require dependency }
28de084c » Nick Kallen
2009-04-16 basic round-robin strategy works
5
6 begin
7 $options = {
32f5b536 » Nick Kallen
2009-04-16 basic async stuff
8 :port => 10001
28de084c » Nick Kallen
2009-04-16 basic round-robin strategy works
9 }
10 OptionParser.new do |opts|
11 opts.on('-p', "--port PORT", Integer) { |port| $options[:port] = port }
12 end.parse!
13 end
17abb8ed » Nick Kallen
2009-04-15 basic benchmarker and stats
14
cf1f5699 » Nick Kallen
2009-04-16 basic load balancing strategies
15 begin
daab1d9b » Nick Kallen
2009-04-16 load balancing and parallelism finally seems to work
16 logfile = File.join(File.dirname(__FILE__), 'log', File.basename(__FILE__, '.rb') + '.log')
c1fec02a » Nick Kallen
2009-04-17 introducing caching
17 $stats = Statosaurus.new(['cache_hit', 'job_user', 'job_sys', 'job_real', 'source_transaction_id'], Logger.new(logfile))
cf1f5699 » Nick Kallen
2009-04-16 basic load balancing strategies
18 end
c7d6dbb4 » Nick Kallen
2009-04-11 basic structure
19
20 module JokeServer
c76a1284 » Nick Kallen
2009-04-16 with defer
21 include LineBufferedConnection
fd7b9e46 » Nick Kallen
2009-04-20 a sensible lru
22
23 def self.cache
24 @cache ||= InProcessLRUCache.new(2)
25 end
275d75a2 » Nick Kallen
2009-04-16 propagating transaction id
26
c76a1284 » Nick Kallen
2009-04-16 with defer
27 def receive_line(line)
17abb8ed » Nick Kallen
2009-04-15 basic benchmarker and stats
28 $stats.transaction do
af694f56 » Nick Kallen
2009-04-16 sticky session optimization
29 data, source_transaction_id = line.split(';')
c1fec02a » Nick Kallen
2009-04-17 introducing caching
30 $stats.set('source_transaction_id', source_transaction_id)
cf1f5699 » Nick Kallen
2009-04-16 basic load balancing strategies
31 $stats.measure('job') do
fd7b9e46 » Nick Kallen
2009-04-20 a sensible lru
32 result = JokeServer.cache.get(data) do
af694f56 » Nick Kallen
2009-04-16 sticky session optimization
33 100000.times { Time.now }
c1fec02a » Nick Kallen
2009-04-17 introducing caching
34 sleep rand
af694f56 » Nick Kallen
2009-04-16 sticky session optimization
35 "KNOCK KNOCK: #{data}\n"
36 end
37 send_data(result)
cf1f5699 » Nick Kallen
2009-04-16 basic load balancing strategies
38 end
17abb8ed » Nick Kallen
2009-04-15 basic benchmarker and stats
39 end
c7d6dbb4 » Nick Kallen
2009-04-11 basic structure
40 end
41 end
42
43 EM.run do
28de084c » Nick Kallen
2009-04-16 basic round-robin strategy works
44 EM.start_server "0.0.0.0", $options[:port], JokeServer
c7d6dbb4 » Nick Kallen
2009-04-11 basic structure
45 end
Something went wrong with that request. Please try again.