roma 0.8.2 → 0.8.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. data/CHANG +326 -0
  2. data/CHANGELOG +132 -0
  3. data/{README.rdoc → FETCH_HEAD} +0 -0
  4. data/{LICENSE.rdoc → LICENSE} +0 -1
  5. data/README +17 -0
  6. data/Rakefile +33 -18
  7. data/ruby/server/bin/chg_redundancy +10 -0
  8. data/ruby/server/bin/key_access +7 -0
  9. data/ruby/server/bin/key_list +7 -0
  10. data/ruby/server/bin/mkconfig +19 -0
  11. data/{bin → ruby/server/bin}/mkrecent +0 -1
  12. data/{bin → ruby/server/bin}/mkroute +0 -1
  13. data/ruby/server/bin/multi_commander +19 -0
  14. data/ruby/server/bin/recoverlost +10 -0
  15. data/ruby/server/bin/recoverlost_alist +10 -0
  16. data/ruby/server/bin/recoverlost_alist_all +10 -0
  17. data/ruby/server/bin/recoverlost_alist_keys +10 -0
  18. data/{bin/recoverlost → ruby/server/bin/roma_watcher} +1 -2
  19. data/ruby/server/bin/romad +36 -0
  20. data/{bin → ruby/server/bin}/sample_watcher +0 -1
  21. data/{bin → ruby/server/bin}/sample_watcher2 +0 -1
  22. data/{bin/simple_bench → ruby/server/bin/sample_watcher3} +1 -2
  23. data/ruby/server/bin/simple_bench +26 -0
  24. data/{bin → ruby/server/bin}/ssroute +0 -1
  25. data/ruby/server/bin/test-scenario +11 -0
  26. data/{bin → ruby/server/bin}/tribunus +0 -1
  27. data/{lib → ruby/server/lib}/roma/async_process.rb +67 -15
  28. data/{lib → ruby/server/lib}/roma/command/bg_command_receiver.rb +1 -1
  29. data/ruby/server/lib/roma/command/command_definition.rb +422 -0
  30. data/ruby/server/lib/roma/command/mh_command_receiver.rb +127 -0
  31. data/ruby/server/lib/roma/command/receiver.rb +64 -0
  32. data/{lib → ruby/server/lib}/roma/command/rt_command_receiver.rb +6 -1
  33. data/ruby/server/lib/roma/command/sys_command_receiver.rb +609 -0
  34. data/{lib → ruby/server/lib}/roma/command/util_command_receiver.rb +15 -5
  35. data/{lib → ruby/server/lib}/roma/command/vn_command_receiver.rb +12 -4
  36. data/{lib → ruby/server/lib}/roma/command_plugin.rb +0 -0
  37. data/ruby/server/lib/roma/config.rb +84 -0
  38. data/{lib → ruby/server/lib}/roma/event/con_pool.rb +12 -1
  39. data/ruby/server/lib/roma/event/handler.rb +256 -0
  40. data/ruby/server/lib/roma/live_patch-20120302-001.rb +107 -0
  41. data/ruby/server/lib/roma/logging/rlogger.rb +163 -0
  42. data/ruby/server/lib/roma/messaging/con_pool.rb +92 -0
  43. data/{lib → ruby/server/lib}/roma/plugin/plugin_alist.rb +118 -240
  44. data/ruby/server/lib/roma/plugin/plugin_debug.rb +31 -0
  45. data/ruby/server/lib/roma/plugin/plugin_map.rb +177 -0
  46. data/ruby/server/lib/roma/plugin/plugin_mapcount.rb +185 -0
  47. data/{lib/roma/command/st_command_receiver.rb → ruby/server/lib/roma/plugin/plugin_storage.rb} +170 -146
  48. data/ruby/server/lib/roma/plugin/plugin_stub.rb +283 -0
  49. data/{lib → ruby/server/lib}/roma/plugin/plugin_test.rb +0 -0
  50. data/{lib → ruby/server/lib}/roma/romad.rb +221 -94
  51. data/{lib → ruby/server/lib}/roma/routing/cb_rttable.rb +4 -6
  52. data/{lib → ruby/server/lib}/roma/routing/merkle_tree.rb +0 -0
  53. data/ruby/server/lib/roma/routing/routing_data.rb +307 -0
  54. data/{lib → ruby/server/lib}/roma/routing/rttable.rb +4 -0
  55. data/{lib → ruby/server/lib}/roma/stats.rb +19 -3
  56. data/{lib → ruby/server/lib}/roma/storage/basic_storage.rb +25 -26
  57. data/{lib → ruby/server/lib}/roma/storage/dbm_storage.rb +1 -23
  58. data/{lib → ruby/server/lib}/roma/storage/dummy_storage.rb +0 -0
  59. data/{lib → ruby/server/lib}/roma/storage/rh_storage.rb +0 -0
  60. data/{lib → ruby/server/lib}/roma/storage/sqlite3_storage.rb +0 -0
  61. data/{lib → ruby/server/lib}/roma/storage/tc_storage.rb +62 -2
  62. data/ruby/server/lib/roma/tools/chg_redundancy.rb +36 -0
  63. data/ruby/server/lib/roma/tools/key_access.rb +105 -0
  64. data/ruby/server/lib/roma/tools/key_list.rb +94 -0
  65. data/ruby/server/lib/roma/tools/mkconfig.rb +535 -0
  66. data/{lib → ruby/server/lib}/roma/tools/mkrecent.rb +0 -0
  67. data/{lib → ruby/server/lib}/roma/tools/mkroute.rb +0 -0
  68. data/ruby/server/lib/roma/tools/multi_commander.rb +45 -0
  69. data/{lib → ruby/server/lib}/roma/tools/recoverlost.rb +0 -0
  70. data/{lib → ruby/server/lib}/roma/tools/recoverlost_alist.rb +0 -0
  71. data/ruby/server/lib/roma/tools/recoverlost_alist_all.rb +8 -0
  72. data/ruby/server/lib/roma/tools/recoverlost_alist_keys.rb +16 -0
  73. data/ruby/server/lib/roma/tools/recoverlost_lib.rb +349 -0
  74. data/ruby/server/lib/roma/tools/roma_watcher.rb +150 -0
  75. data/ruby/server/lib/roma/tools/roma_watcher_config.yml.example +20 -0
  76. data/{lib → ruby/server/lib}/roma/tools/sample_watcher.rb +3 -1
  77. data/{lib → ruby/server/lib}/roma/tools/sample_watcher2.rb +3 -1
  78. data/ruby/server/lib/roma/tools/sample_watcher3.rb +49 -0
  79. data/{lib → ruby/server/lib}/roma/tools/simple_bench.rb +2 -0
  80. data/ruby/server/lib/roma/tools/simple_bench2.rb +78 -0
  81. data/{lib → ruby/server/lib}/roma/tools/ssroute.rb +0 -0
  82. data/ruby/server/lib/roma/tools/test-scenario.rb +327 -0
  83. data/{lib → ruby/server/lib}/roma/tools/tribunus.rb +0 -0
  84. data/ruby/server/lib/roma/version.rb +4 -0
  85. data/{lib → ruby/server/lib}/roma/write_behind.rb +1 -0
  86. data/ruby/server/test/config4mhash.rb +68 -0
  87. data/ruby/server/test/config4storage_error.rb +69 -0
  88. data/{lib/roma/config.rb → ruby/server/test/config4test.rb} +6 -3
  89. data/{test → ruby/server/test}/rcirb.rb +0 -1
  90. data/{test → ruby/server/test}/roma-test-utils.rb +21 -8
  91. data/{test → ruby/server/test}/run-test.rb +3 -2
  92. data/ruby/server/test/storage_error_storage.rb +37 -0
  93. data/ruby/server/test/t_command_definition.rb +326 -0
  94. data/{test → ruby/server/test}/t_cpdata.rb +9 -3
  95. data/{test → ruby/server/test}/t_listplugin.rb +48 -12
  96. data/ruby/server/test/t_mapcountplugin.rb +231 -0
  97. data/ruby/server/test/t_mapplugin.rb +131 -0
  98. data/ruby/server/test/t_mhash.rb +222 -0
  99. data/ruby/server/test/t_rclient.rb +199 -0
  100. data/{test → ruby/server/test}/t_routing_data.rb +56 -0
  101. data/{test → ruby/server/test}/t_storage.rb +107 -111
  102. data/ruby/server/test/t_storage_error.rb +61 -0
  103. data/ruby/server/test/t_writebehind.rb +374 -0
  104. metadata +150 -82
  105. data/bin/recoverlost_alist +0 -8
  106. data/bin/romad +0 -7
  107. data/lib/roma/command/mh_command_receiver.rb +0 -117
  108. data/lib/roma/command/receiver.rb +0 -287
  109. data/lib/roma/event/handler.rb +0 -159
  110. data/lib/roma/plugin/plugin_debug.rb +0 -19
  111. data/lib/roma/tools/recoverlost_lib.rb +0 -217
  112. data/lib/roma/version.rb +0 -4
  113. data/test/t_rclient.rb +0 -318
  114. data/test/t_writebehind.rb +0 -200
@@ -9,14 +9,14 @@ module Roma
9
9
  con = get_connection(nid)
10
10
  con.send(cmd)
11
11
  res = con.gets
12
- if res
13
- res.chomp!
12
+ if res == nil
13
+ @rttable.proc_failed(nid)
14
+ return nil
15
+ elsif res.start_with?("ERROR") == false
14
16
  @rttable.proc_succeed(nid)
15
17
  return_connection(nid, con)
16
- else
17
- @rttable.proc_failed(nid)
18
18
  end
19
- res
19
+ res.chomp
20
20
  rescue => e
21
21
  @rttable.proc_failed(nid)
22
22
  @log.error("#{e}\n#{$@}")
@@ -61,6 +61,16 @@ module Roma
61
61
  nil
62
62
  end
63
63
 
64
+ # change to actual time for a memcached's expire time value
65
+ def chg_time_expt(expt)
66
+ if expt == 0
67
+ expt = 0x7fffffff
68
+ elsif expt < 2592000
69
+ expt += Time.now.to_i
70
+ end
71
+ expt
72
+ end
73
+
64
74
  end # module UtilCommandReceiver
65
75
 
66
76
  end # module Command
@@ -50,7 +50,8 @@ module Roma
50
50
  vlen, = vlen_bin.unpack('N')
51
51
  if vlen != 0
52
52
  v = read_bytes(vlen, 100)
53
-
53
+
54
+ createhash(s[1]) unless @storages[s[1]]
54
55
  if @storages[s[1]].load_stream_dump(vn, last, clk, expt, k, v)
55
56
  count += 1
56
57
  # @log.debug("#{__method__}:[#{vn} #{last} #{clk} #{expt} #{k}] was stored.")
@@ -59,6 +60,7 @@ module Roma
59
60
  # @log.warn("#{__method__}:[#{vn} #{last} #{clk} #{expt} #{k}] was rejected.")
60
61
  end
61
62
  else
63
+ createhash(s[1]) unless @storages[s[1]]
62
64
  if @storages[s[1]].load_stream_dump(vn, last, clk, expt, k, nil)
63
65
  # @log.debug("#{__method__}:[#{vn} #{last} #{clk} #{expt} #{k}] was stored.")
64
66
  count += 1
@@ -70,8 +72,16 @@ module Roma
70
72
  }
71
73
  send_data("STORED\r\n")
72
74
  @log.debug("#{__method__}:#{s[2]} #{count} keys loaded. #{rcount} keys rejected.")
75
+ rescue Storage::StorageException => e
76
+ @log.error("#{e.inspect} #{$@}")
77
+ close_connection
78
+ if Config.const_defined?(:STORAGE_EXCEPTION_ACTION) &&
79
+ Config::STORAGE_EXCEPTION_ACTION == :shutdown
80
+ @log.error("Romad will stop")
81
+ @stop_event_loop = true
82
+ end
73
83
  rescue => e
74
- @log.error("#{e}\n#{$@}")
84
+ @log.error("#{e} #{$@}")
75
85
  ensure
76
86
  @stats.run_receive_a_vnode = false
77
87
  end
@@ -85,13 +95,11 @@ module Roma
85
95
  send_data("CLIENT_ERROR usage:reqpushv vnode-id node-id primary-flag(true/false)\r\n")
86
96
  return
87
97
  end
88
-
89
98
  if @stats.run_iterate_storage == true
90
99
  @log.warn("reqpushv rejected:#{s}")
91
100
  send_data("REJECTED\r\n")
92
101
  return
93
102
  end
94
-
95
103
  Roma::AsyncProcess::queue.push(Roma::AsyncMessage.new('reqpushv',[s[1],s[2],s[3]]))
96
104
  send_data("PUSHED\r\n")
97
105
  rescue =>e
File without changes
@@ -0,0 +1,84 @@
1
+ require 'roma/storage/rh_storage'
2
+
3
+ module Roma
4
+
5
+ module Config
6
+ DEFAULT_PORT = 12000
7
+ DEFAULT_NAME = 'ROMA'
8
+
9
+ # :no_action | :auto_assign | :shutdown
10
+ DEFAULT_LOST_ACTION = :auto_assign
11
+
12
+ # failover setting
13
+ # threshold of failover occurrence
14
+ ROUTING_FAIL_CNT_THRESHOLD = 15
15
+ # ROUTING_FAIL_CNT_GAP(sec) doesn't increase the failover counter.
16
+ ROUTING_FAIL_CNT_GAP = 0
17
+
18
+ # log setting
19
+ LOG_SHIFT_AGE = 10
20
+ LOG_SHIFT_SIZE = 1024 * 1024 * 10
21
+ LOG_PATH = '.'
22
+ # :debug | :info | :warn | :error
23
+ LOG_LEVEL = :debug
24
+
25
+ # routing setting
26
+ RTTABLE_PATH = '.'
27
+
28
+ # connection setting
29
+
30
+ # to use a system call of epoll, CONNECTION_USE_EPOLL is to set true
31
+ CONNECTION_USE_EPOLL = true
32
+ # to use a system call of epoll, CONNECTION_DESCRIPTOR_TABLE_SIZE can be setting
33
+ CONNECTION_DESCRIPTOR_TABLE_SIZE = 4096
34
+
35
+ # like a MaxStartups spec in the sshd_config
36
+ # 'start:rate:full'
37
+ CONNECTION_CONTINUOUS_LIMIT = '200:30:300'
38
+ # expired time(sec) for accepted connections
39
+ CONNECTION_EXPTIME = 0
40
+
41
+ # expired time(sec) for an async connection in the connection pool
42
+ # CONNECTION_POOL_EXPTIME should be less than CONNECTION_EXPTIME
43
+ CONNECTION_POOL_EXPTIME = 30
44
+ # max length of the connection pool
45
+ CONNECTION_POOL_MAX = 5
46
+
47
+ # expired time(sec) for an eventmachine's connection in the connection pool
48
+ # CONNECTION_EMPOOL_EXPTIME should be less than CONNECTION_EXPTIME
49
+ CONNECTION_EMPOOL_EXPTIME = 30
50
+ # max length of the eventmachine's connection pool
51
+ CONNECTION_EMPOOL_MAX = 15
52
+
53
+ # storage setting
54
+ STORAGE_CLASS = Roma::Storage::RubyHashStorage
55
+ STORAGE_DIVNUM = 10
56
+ STORAGE_PATH = '.'
57
+ STORAGE_DUMP_PATH = '/tmp'
58
+ STORAGE_OPTION = ''
59
+ # :no_action | :shutdown
60
+ STORAGE_EXCEPTION_ACTION = :no_action
61
+
62
+ # expired time(sec) for deleted keys, expired keys and invalid vnode keys
63
+ # typical value is 5 days
64
+ STORAGE_DELMARK_EXPTIME = 60 * 60 * 24 * 5
65
+
66
+ # data copy setting
67
+ DATACOPY_STREAM_COPY_WAIT_PARAM = 0.001
68
+
69
+ # plugin setting
70
+ PLUGIN_FILES = ['plugin_storage.rb']
71
+
72
+ # write-behind setting
73
+ WRITEBEHIND_PATH = './wb'
74
+ WRITEBEHIND_SHIFT_SIZE = 1024 * 1024 * 10
75
+
76
+ # redundant setting
77
+ # REDUNDANT_ZREDUNDANT_SIZE is a option for a redundancy of compressed data.
78
+ # when the data size is more then REDUNDANT_ZREDUNDANT_SIZE, data compression is done.
79
+ # however, it dose't in case of REDUNDANT_ZREDUNDANT_SIZE is zero.
80
+ REDUNDANT_ZREDUNDANT_SIZE = 0
81
+
82
+ end
83
+
84
+ end
@@ -11,10 +11,12 @@ module Roma
11
11
  attr_writer :fiber
12
12
  attr_reader :connected
13
13
  attr_accessor :ap
14
+ attr_accessor :last_access
14
15
 
15
16
  def post_init
16
17
  @rbuf = ''
17
18
  @connected = true
19
+ @last_access = Time.now
18
20
  end
19
21
 
20
22
  def receive_data(data)
@@ -76,21 +78,30 @@ module Roma
76
78
  include Singleton
77
79
  attr :pool
78
80
  attr_accessor :maxlength
81
+ attr_accessor :expire_time
79
82
 
80
83
  def initialize
81
84
  @pool = {}
82
- @maxlength = 10
85
+ @maxlength = 30
86
+ @expire_time = 30
83
87
  @lock = Mutex.new
84
88
  end
85
89
 
86
90
  def get_connection(ap)
87
91
  ret = @pool[ap].shift if @pool.key?(ap) && @pool[ap].length > 0
92
+ if ret && ret.last_access < Time.now - @expire_time
93
+ ret.close_connection if ret.connected
94
+ ret = nil
95
+ Logging::RLogger.instance.info("EM connection expired at #{ap},remains #{@pool[ap].length}")
96
+ end
88
97
  ret = create_connection(ap) if ret == nil || ret.connected != true
89
98
  ret
90
99
  end
91
100
 
92
101
  def return_connection(ap, con)
93
102
  return if con.connected == false
103
+
104
+ con.last_access = Time.now
94
105
  if @pool.key?(ap) && @pool[ap].length > 0
95
106
  if @pool[ap].length > @maxlength
96
107
  con.close_connection
@@ -0,0 +1,256 @@
1
+ #
2
+ # File: handler.rb
3
+ #
4
+ require 'eventmachine'
5
+ require 'roma/event/con_pool'
6
+ require 'roma/logging/rlogger'
7
+ require 'roma/stats'
8
+ require 'roma/storage/basic_storage'
9
+ require 'socket'
10
+
11
+ module Roma
12
+ module Event
13
+
14
+ class Handler < EventMachine::Connection
15
+ @@ev_list={}
16
+ def self.ev_list; @@ev_list; end
17
+ @@system_commands={}
18
+ def self.system_commands; @@system_commands; end
19
+
20
+ @@ccl_start = 200
21
+ @@ccl_rate = 30
22
+ @@ccl_full = 300
23
+
24
+ def self.get_ccl
25
+ "#{@@ccl_start}:#{@@ccl_rate}:#{@@ccl_full}"
26
+ end
27
+
28
+ def self.set_ccl(ccl)
29
+ if ccl =~ /^(\d+):(\d+):(\d+)$/
30
+ s,r,f = $1.to_i,$2.to_i,$3.to_i
31
+ return false if(s < 0 || f < 0 || r < 0 || r > 100 || s > f)
32
+ @@ccl_start = s
33
+ @@ccl_rate = r
34
+ @@ccl_full = f
35
+ return true
36
+ else
37
+ return false
38
+ end
39
+ end
40
+
41
+ @@connections = {}
42
+ def self.connections; @@connections; end
43
+
44
+ @@connection_expire_time = 60
45
+ def self.connection_expire_time=(t)
46
+ @@connection_expire_time = t
47
+ end
48
+
49
+ def self.connection_expire_time
50
+ @@connection_expire_time
51
+ end
52
+
53
+ attr_accessor :timeout
54
+ attr_reader :connected
55
+ attr_reader :lastcmd
56
+ attr_reader :last_access
57
+ attr_reader :addr, :port
58
+
59
+ def initialize(storages, rttable)
60
+ @rbuf=''
61
+ unless has_event?
62
+ public_methods.each{|m|
63
+ if m.to_s.start_with?('ev_')
64
+ add_event(m.to_s[3..-1],m)
65
+ end
66
+ }
67
+ end
68
+ @th1 = 100
69
+ @close_rate = 70
70
+ @th2 = 200
71
+
72
+ @storages = storages
73
+ @rttable = rttable
74
+ @timeout = 10
75
+ @log = Roma::Logging::RLogger.instance
76
+ @last_access = Time.now
77
+ end
78
+
79
+ def post_init
80
+ @port, @addr = Socket.unpack_sockaddr_in(get_peername)
81
+ @log.info("Connected from #{@addr}:#{@port}. I have #{EM.connection_count} connections.")
82
+ @connected = true
83
+ @last_access = Time.now
84
+ @@connections[self] = @last_access
85
+ @fiber = Fiber.new { dispatcher }
86
+ rescue Exception =>e
87
+ @log.error("#{__FILE__}:#{__LINE__}:#{e.inspect} #{$@}")
88
+ end
89
+
90
+ def receive_data(data)
91
+ @rbuf << data
92
+ @last_access = Time.now
93
+ @fiber.resume
94
+ rescue Exception =>e
95
+ @log.error("#{__FILE__}:#{__LINE__}:#{@addr}:#{@port} #{e.inspect} #{$@}")
96
+ end
97
+
98
+ def unbind
99
+ @connected=false
100
+ begin
101
+ @fiber.resume
102
+ rescue FiberError
103
+ end
104
+ EventMachine::stop_event_loop if @stop_event_loop
105
+ @@connections.delete(self)
106
+ if @enter_time
107
+ # hilatency check
108
+ ps = Time.now - @enter_time
109
+ if ps > @stats.hilatency_warn_time
110
+ @log.warn("#{@lastcmd} has incompleted, passage of #{ps} seconds")
111
+ end
112
+ end
113
+ @log.info("Disconnected from #{@addr}:#{@port}")
114
+ rescue Exception =>e
115
+ @log.warn("#{__FILE__}:#{__LINE__}:#{@addr}:#{@port} #{e.inspect} #{$@}")
116
+ end
117
+
118
+ protected
119
+
120
+ def has_event?
121
+ @@ev_list.length!=0
122
+ end
123
+
124
+ def add_event(c,m)
125
+ @@ev_list[c]=m
126
+ end
127
+
128
+ def exit
129
+ EventMachine::stop_event_loop
130
+ end
131
+
132
+ private
133
+
134
+ def get_connection(ap)
135
+ con=Roma::Event::EMConPool::instance.get_connection(ap)
136
+ con.fiber=@fiber
137
+ con
138
+ end
139
+
140
+ def return_connection(ap,con)
141
+ Roma::Event::EMConPool.instance.return_connection(ap,con)
142
+ end
143
+
144
+ def dispatcher
145
+ @stats = Roma::Stats.instance
146
+ while(@connected) do
147
+ @enter_time = nil
148
+ next unless s=gets
149
+ @enter_time = Time.now
150
+ s=s.chomp.split(/ /)
151
+ if s[0] && @@ev_list.key?(s[0].downcase)
152
+ send(@@ev_list[s[0].downcase],s)
153
+ @lastcmd=s
154
+ next if @@system_commands.key?(s[0].downcase)
155
+ elsif s.length==0
156
+ next
157
+ elsif s[0]=='!!'
158
+ send(@@ev_list[@lastcmd[0].downcase],@lastcmd)
159
+ next if @@system_commands.key?(@lastcmd[0].downcase)
160
+ else
161
+ @log.warn("command error:#{s}")
162
+ send_data("ERROR\r\n")
163
+ close_connection_after_writing
164
+ end
165
+
166
+ # hilatency check
167
+ ps = Time.now - @enter_time
168
+ if ps > @stats.hilatency_warn_time
169
+ @log.warn("hilatency occurred in #{@lastcmd} put in a #{ps} seconds")
170
+ end
171
+
172
+ d = EM.connection_count - @@ccl_start
173
+ if d > 0 &&
174
+ rand(100) < @@ccl_rate + (100 - @@ccl_rate) * d / (@@ccl_full - @@ccl_start)
175
+ send_data("ERROR\r\n")
176
+ close_connection_after_writing
177
+ @log.warn("Connection count > #{@@ccl_start}:closed")
178
+ end
179
+ end
180
+ rescue Storage::StorageException => e
181
+ @log.error("#{e.inspect} #{s} #{$@}")
182
+ send_data("SERVER_ERROR #{e} in storage engine\r\n")
183
+ close_connection_after_writing
184
+ if Config.const_defined?(:STORAGE_EXCEPTION_ACTION) &&
185
+ Config::STORAGE_EXCEPTION_ACTION == :shutdown
186
+ @log.error("Romad will stop")
187
+ @stop_event_loop = true
188
+ end
189
+ rescue Exception =>e
190
+ @log.warn("#{__FILE__}:#{__LINE__}:#{@addr}:#{@port} #{e} #{$@}")
191
+ close_connection
192
+ end
193
+
194
+ def pop(size)
195
+ return '' if size == 0
196
+ if @rbuf.size >= size
197
+ r = @rbuf[0..size-1]
198
+ @rbuf = @rbuf[size..-1]
199
+ r
200
+ else
201
+ nil
202
+ end
203
+ end
204
+
205
+ def read_bytes(size, mult = 1)
206
+ t=Time.now.to_i
207
+ while(@connected) do
208
+ d = pop(size)
209
+ if d
210
+ return d
211
+ else
212
+ remain = size - @rbuf.size
213
+ Fiber.yield(remain)
214
+ if Time.now.to_i - t > @timeout * mult
215
+ @log.warn("#{__FILE__}:#{__LINE__}:#{@addr}:#{@port} read_bytes time out");
216
+ close_connection
217
+ return nil
218
+ end
219
+ end
220
+ end
221
+ nil
222
+ end
223
+
224
+ def gets
225
+ while(@connected) do
226
+ if idx=@rbuf.index("\n")
227
+ return pop(idx+1)
228
+ else
229
+ Fiber.yield(@rbuf.size)
230
+ end
231
+ end
232
+ nil
233
+ end
234
+
235
+ def detach_socket
236
+ @connected = false
237
+ Socket::for_fd(detach)
238
+ end
239
+
240
+ def conn_get_stat
241
+ ret = {}
242
+ ret["connection.count"] = EM.connection_count
243
+ ret["connection.continuous_limit"] = Handler.get_ccl
244
+ ret["connection.accepted_connection_expire_time"] = Handler.connection_expire_time
245
+ ret["connection.handler_instance_count"] = Handler.connections.length
246
+ ret["connection.pool_maxlength"] = Messaging::ConPool.instance.maxlength
247
+ ret["connection.pool_expire_time"] = Messaging::ConPool.instance.expire_time
248
+ ret["connection.EMpool_maxlength"] = Event::EMConPool::instance.maxlength
249
+ ret["connection.EMpool_expire_time"] = Event::EMConPool.instance.expire_time
250
+ ret
251
+ end
252
+
253
+ end # class Handler < EventMachine::Connection
254
+
255
+ end # module Event
256
+ end # module Roma