dango 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/dango/framework_base.rb +2 -2
- data/lib/dango/server_framework.rb +70 -83
- data/lib/dango/shared/memory_store.rb +16 -12
- data/lib/dango/version.rb +1 -1
- metadata +2 -2
data/lib/dango/framework_base.rb
CHANGED
@@ -69,9 +69,9 @@ module ErrorMessage
|
|
69
69
|
end
|
70
70
|
|
71
71
|
str = "#{exception_class.class}:#{exception_class.message}\n#{exception_class.backtrace.pretty_inspect}"
|
72
|
-
if code.downcase == "u" || code.downcase == "utf8"
|
72
|
+
if code.to_s.downcase == "u" || code.to_s.downcase == "utf8"
|
73
73
|
str = str.toutf8
|
74
|
-
elsif code.downcase == "s" || code.downcase == "sjis"
|
74
|
+
elsif code.to_s.downcase == "s" || code.to_s.downcase == "sjis"
|
75
75
|
str = str.tosjis
|
76
76
|
end
|
77
77
|
str
|
@@ -108,6 +108,7 @@ class DangoServerFramework
|
|
108
108
|
|
109
109
|
# データ送信用スレッドとQueue
|
110
110
|
@queue_send_notice = Queue.new
|
111
|
+
@mutex_send_notice = Mutex.new
|
111
112
|
Thread.start{ thread_send_notice_queue() }
|
112
113
|
|
113
114
|
# サーバー開始
|
@@ -173,8 +174,10 @@ class DangoServerFramework
|
|
173
174
|
@gserver.audit = true # Turn logging on.
|
174
175
|
@gserver.debug = true # debug
|
175
176
|
|
176
|
-
|
177
|
-
|
177
|
+
if @gserver_log_file.to_s != ""
|
178
|
+
gserver_log_fh = open(@gserver_log_file, "a")
|
179
|
+
@gserver.stdlog = gserver_log_fh
|
180
|
+
end
|
178
181
|
|
179
182
|
GC.disable
|
180
183
|
open(@pid_file, "wb"){|fh| fh.write Process.pid.to_s } # pidをファイルに保存
|
@@ -183,7 +186,8 @@ class DangoServerFramework
|
|
183
186
|
@gserver.start(@server_max_connections, 20) # backlogを20に設定
|
184
187
|
|
185
188
|
rescue Exception
|
186
|
-
|
189
|
+
puts error_message($!)
|
190
|
+
# error_print(error_message($!, 'u'))
|
187
191
|
exit
|
188
192
|
end
|
189
193
|
end
|
@@ -253,14 +257,14 @@ class DangoServerFramework
|
|
253
257
|
def starting()
|
254
258
|
msg = "#{self.class.to_s} #{@server_host}:#{@network_port}/#{@server_max_connections} start"
|
255
259
|
logger.warn msg
|
256
|
-
puts "[#{Time.now_to_s}] #{msg}"
|
260
|
+
puts "[#{Time.now_to_s}] #{msg}" if @gserver_log_file.to_s != ""
|
257
261
|
end
|
258
262
|
|
259
263
|
# gserver終了処理
|
260
264
|
def stopping()
|
261
265
|
msg = "#{self.class.to_s} #{@server_host}:#{@network_port} stop"
|
262
266
|
logger.warn msg
|
263
|
-
puts "[#{Time.now_to_s}] #{msg}"
|
267
|
+
puts "[#{Time.now_to_s}] #{msg}" if @gserver_log_file.to_s != ""
|
264
268
|
end
|
265
269
|
|
266
270
|
# gserverのserveメソッド:スレッド開始処理
|
@@ -391,13 +395,15 @@ EOF
|
|
391
395
|
end
|
392
396
|
|
393
397
|
if ! session[:connected] # まだdango_connectを呼び出していないなら
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
398
|
+
@mutex_proc_thread.synchronize do
|
399
|
+
# 接続直後のsid通知
|
400
|
+
send_obj = {"_sid"=>sid}
|
401
|
+
send_notice("_notice_sid", sid, send_obj)
|
402
|
+
logger.debug "_notice_sid #{sid} "
|
403
|
+
|
404
|
+
dango_connect() # 接続時メソッド呼び出し
|
405
|
+
session[:connected] = true
|
406
|
+
end # mutex_proc_thread
|
401
407
|
end
|
402
408
|
end
|
403
409
|
|
@@ -452,9 +458,9 @@ EOF
|
|
452
458
|
logger.info "#{sock.inspect} #{sid} is closed"
|
453
459
|
sock = nil
|
454
460
|
end
|
455
|
-
end
|
461
|
+
end # mutex_proc_thread
|
456
462
|
|
457
|
-
@session_manager.close_session() # sessionの終了処理
|
463
|
+
@session_manager.close_session(sid) # sessionの終了処理
|
458
464
|
end
|
459
465
|
|
460
466
|
end
|
@@ -524,7 +530,7 @@ EOF
|
|
524
530
|
"DEBUG" => Logger::DEBUG,
|
525
531
|
}
|
526
532
|
log_level_hash.each do |str, const|
|
527
|
-
@log_level = const if str.downcase == @config['server']['log_level'].downcase
|
533
|
+
@log_level = const if str.downcase == @config['server']['log_level'].to_s.downcase
|
528
534
|
end
|
529
535
|
@log_level = @log_level || DefaultLogLevel
|
530
536
|
|
@@ -660,46 +666,49 @@ EOF
|
|
660
666
|
if ! @gserver.stopped? # gserverが起動していれば
|
661
667
|
logger.debug "heart_beat_thread_start "
|
662
668
|
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
# 全員分のチェック
|
667
|
-
socket_list.all_sid.each do |sid|
|
668
|
-
sock = socket_list[sid]
|
669
|
-
|
670
|
-
if ! sock # すでにsocketが無い場合は、スキップ
|
671
|
-
logger.warn "!!!! heart_beat_thread_start:sock is not found. #{sid}:#{sock}"
|
672
|
-
next
|
673
|
-
end
|
669
|
+
@mutex_proc_thread.synchronize do
|
670
|
+
# クライアントから来るハートビートのチェック
|
671
|
+
heart_beat_time_hash = shared[:_heart_beat_time_hash]
|
674
672
|
|
675
|
-
#
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
sock.
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
673
|
+
# 全員分のチェック
|
674
|
+
socket_list.all_sid.each do |sid|
|
675
|
+
sock = socket_list[sid]
|
676
|
+
|
677
|
+
if ! sock # すでにsocketが無い場合は、スキップ
|
678
|
+
logger.warn "!!!! heart_beat_thread_start:sock is not found. #{sid}:#{sock}"
|
679
|
+
next
|
680
|
+
end
|
681
|
+
|
682
|
+
# クライアントから来たハートビートの時間チェックし、古ければsocketを閉じる
|
683
|
+
if heart_beat_time_hash[sid] && heart_beat_time_hash[sid] < Time.now - @heart_beat_receive_wait_sec
|
684
|
+
logger.warn "!!!! heart_beat_thread_start:heart beat old:#{sid}:#{heart_beat_time_hash[sid]}:#{sock}:#{sock.closed?}"
|
685
|
+
# sock.close if !sock.closed?
|
686
|
+
begin
|
687
|
+
sock.close
|
688
|
+
rescue IOError
|
689
|
+
logger.debug "heart_beat_thread_start:maybe already closed. IOError:#{sid}:#{sock}"
|
690
|
+
rescue
|
691
|
+
logger.warn "heart_beat_thread_start:failed close socket:#{error_message($!, 'u')}"
|
692
|
+
end
|
693
|
+
next
|
685
694
|
end
|
686
695
|
end
|
687
|
-
end
|
688
|
-
end
|
696
|
+
end # @mutex_proc_thread
|
697
|
+
end # ! @gserver.stopped?
|
689
698
|
|
690
|
-
# スレッド情報をログに出力
|
691
|
-
if logger.debug?
|
692
|
-
count += 1
|
693
|
-
if count % 100 == 0
|
694
|
-
sids = socket_list.all_sid
|
695
|
-
thr_list = @thr_gr_gserver_serve.list.collect{|th| th.object_id }
|
696
|
-
|
697
|
-
logger.debug "heart_beat_thread_start:sids=#{sids.inspect}"
|
698
|
-
logger.debug "heart_beat_thread_start:thr_list=#{thr_list.inspect}"
|
699
|
-
logger.debug "heart_beat_thread_start:sids-thr_list=#{(sids-thr_list).inspect}"
|
700
|
-
logger.debug "heart_beat_thread_start:thr_list-sids=#{(thr_list-sids).inspect}"
|
701
|
-
end
|
702
|
-
end
|
699
|
+
# # スレッド情報をログに出力
|
700
|
+
# if logger.debug?
|
701
|
+
# count += 1
|
702
|
+
# if count % 100 == 0
|
703
|
+
# sids = socket_list.all_sid
|
704
|
+
# thr_list = @thr_gr_gserver_serve.list.collect{|th| th.object_id }
|
705
|
+
#
|
706
|
+
# logger.debug "heart_beat_thread_start:sids=#{sids.inspect}"
|
707
|
+
# logger.debug "heart_beat_thread_start:thr_list=#{thr_list.inspect}"
|
708
|
+
# logger.debug "heart_beat_thread_start:sids-thr_list=#{(sids-thr_list).inspect}"
|
709
|
+
# logger.debug "heart_beat_thread_start:thr_list-sids=#{(thr_list-sids).inspect}"
|
710
|
+
# end
|
711
|
+
# end
|
703
712
|
|
704
713
|
rescue Exception
|
705
714
|
logger.error "Exception heart_beat_thread_start #{error_message($!, 'u')}"
|
@@ -752,7 +761,9 @@ EOF
|
|
752
761
|
send_id = notice_name.to_s + Time.now.to_f.to_s + rand().to_s
|
753
762
|
send_obj_dup["_id"] = send_id
|
754
763
|
|
755
|
-
@
|
764
|
+
@mutex_send_notice.synchronize do # queue_send_noticeに排他処理
|
765
|
+
@queue_send_notice.push([sid, send_obj_dup, encode_type].deep_dup)
|
766
|
+
end
|
756
767
|
end # end sids.each
|
757
768
|
|
758
769
|
self
|
@@ -768,13 +779,13 @@ EOF
|
|
768
779
|
|
769
780
|
pop_data = @queue_send_notice.pop
|
770
781
|
send_data_list.push(pop_data) # Queueデータ待ち
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
782
|
+
|
783
|
+
@mutex_send_notice.synchronize do # queue_send_noticeに排他処理(sizeとpopの実行の間にpushが起きないように)
|
784
|
+
@queue_send_notice.size.times do
|
785
|
+
# while(! @queue_send_notice.empty?) do # 残りのデータもQueueに入れていく
|
786
|
+
pop_data = @queue_send_notice.pop
|
787
|
+
send_data_list.push(pop_data) # Queueデータ待ち
|
788
|
+
end
|
778
789
|
end
|
779
790
|
|
780
791
|
send_data_sid_list = {}
|
@@ -879,29 +890,5 @@ EOF
|
|
879
890
|
end
|
880
891
|
end
|
881
892
|
|
882
|
-
=begin
|
883
|
-
def flameloop_thread(loop_method, options={})
|
884
|
-
logger.warn "flameloop_thread options:#{options.inspect}"
|
885
|
-
options = options.deep_dup
|
886
|
-
options[:rate] ||= 10
|
887
|
-
|
888
|
-
wait_sec = 1.0 / options[:rate]
|
889
|
-
logger.warn "flameloop_thread wait_sec:#{wait_sec.inspect}"
|
890
|
-
|
891
|
-
th = Thread.new do
|
892
|
-
loop do
|
893
|
-
@mutex_proc_thread.synchronize do
|
894
|
-
begin
|
895
|
-
__send__(loop_method)
|
896
|
-
rescue Exception
|
897
|
-
logger.error "flameloop_thread error:#{error_message($!, 'u')}"
|
898
|
-
end
|
899
|
-
end
|
900
|
-
sleep wait_sec
|
901
|
-
end
|
902
|
-
end
|
903
|
-
end
|
904
|
-
=end
|
905
|
-
|
906
893
|
end
|
907
894
|
|
@@ -11,8 +11,8 @@ module DangoFrameworkModule
|
|
11
11
|
def initialize(config)
|
12
12
|
@config = config
|
13
13
|
@data = {}
|
14
|
-
@mutex = {}
|
15
|
-
@
|
14
|
+
# @mutex = {}
|
15
|
+
@mutex = Mutex.new
|
16
16
|
|
17
17
|
@transact_key = {}
|
18
18
|
@transact_thread = {}
|
@@ -38,11 +38,12 @@ module DangoFrameworkModule
|
|
38
38
|
# 昔のトランザクション処理ロジック
|
39
39
|
def transaction(key)
|
40
40
|
key = key.to_s
|
41
|
-
if !@
|
41
|
+
if !@data.has_key?(key) # 未定義キーならエラー
|
42
42
|
raise(DangoFrameworkException, "Shared key is not exist.")
|
43
43
|
end
|
44
44
|
|
45
|
-
@mutex[key].synchronize do
|
45
|
+
# @mutex[key].synchronize do
|
46
|
+
@mutex.synchronize do
|
46
47
|
# data = yield(@data[key].deep_dup)
|
47
48
|
data = yield(@data[key])
|
48
49
|
@data[key] = data.deep_dup
|
@@ -61,11 +62,12 @@ module DangoFrameworkModule
|
|
61
62
|
# このブロックの中でcommitかrollbackか例外発生を行わなければならない
|
62
63
|
def transaction(key)
|
63
64
|
key = key.to_s
|
64
|
-
if !@
|
65
|
+
if !@data.has_key?(key) # 未定義キーならエラー
|
65
66
|
raise(DangoFrameworkException, "Shared key is not exist.")
|
66
67
|
end
|
67
68
|
|
68
|
-
@mutex[key].synchronize do
|
69
|
+
# @mutex[key].synchronize do
|
70
|
+
@mutex.synchronize do
|
69
71
|
@transact_key[Thread.current] = key # 違うスレッドからcommitできないように
|
70
72
|
|
71
73
|
raise("nested transaction #{key}") if @transact_thread.has_key?(key)
|
@@ -141,14 +143,15 @@ module DangoFrameworkModule
|
|
141
143
|
|
142
144
|
def [](key)
|
143
145
|
key = key.to_s
|
144
|
-
if !@
|
146
|
+
if !@data.has_key?(key) # 未定義キーならエラー
|
145
147
|
return(nil)
|
146
148
|
# raise(DangoFrameworkException, "Shared key is not exist.")
|
147
149
|
end
|
148
150
|
|
149
151
|
# @mutex[key].synchronize do
|
152
|
+
@mutex.synchronize do
|
150
153
|
@data[key].deep_dup
|
151
|
-
|
154
|
+
end
|
152
155
|
end
|
153
156
|
|
154
157
|
def []=(key, value)
|
@@ -161,12 +164,13 @@ module DangoFrameworkModule
|
|
161
164
|
key = key.to_s
|
162
165
|
|
163
166
|
# 未定義なら定義する
|
164
|
-
if !@
|
165
|
-
@mutex[key] = Mutex.new
|
166
|
-
end
|
167
|
+
# if !@data.has_key?(key)
|
168
|
+
# @mutex[key] = Mutex.new
|
169
|
+
# end
|
167
170
|
|
168
171
|
# ロックしてデータを入れる
|
169
|
-
@mutex[key].synchronize do
|
172
|
+
# @mutex[key].synchronize do
|
173
|
+
@mutex.synchronize do
|
170
174
|
@data[key] = value.deep_dup
|
171
175
|
end
|
172
176
|
|
data/lib/dango/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dango
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keisuke Minami
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-09-
|
12
|
+
date: 2008-09-25 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|