sbsm 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/History.txt +4 -0
  2. data/lib/sbsm/request.rb +66 -2
  3. data/lib/version.rb +1 -1
  4. metadata +6 -6
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 1.1.3 / 24.02.2012
2
+
3
+ * Drop crawler requests if drb server threads goes over 50
4
+
1
5
  === 1.1.2 / 22.02.2012
2
6
 
3
7
  * Added # -*- coding: ascii-8bit -*- to flavored_uri_parser.rb
data/lib/sbsm/request.rb CHANGED
@@ -20,7 +20,7 @@
20
20
  # ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Z�rich, Switzerland
21
21
  # hwyss@ywesee.com
22
22
  #
23
- # SBSM::Request -- sbsm -- 21.01.2012 -- mhatakeyama@ywesee.com
23
+ # SBSM::Request -- sbsm -- 24.01.2012 -- mhatakeyama@ywesee.com
24
24
  # SBSM::Request -- sbsm -- hwyss@ywesee.com
25
25
 
26
26
  require 'sbsm/cgi'
@@ -74,13 +74,77 @@ module SBSM
74
74
  @request.unparsed_uri
75
75
  end
76
76
  private
77
+ def lock
78
+ lock_file = '/tmp/sbsm_lock'
79
+ flag_file = '/tmp/sbsm_drop_flag'
80
+ open(lock_file, 'a') do |st|
81
+ st.flock(File::LOCK_EX)
82
+ yield
83
+ st.flock(File::LOCK_UN)
84
+ end
85
+ end
86
+ def drb_server_threads
87
+ threads = 0
88
+ status = '/var/www/oddb.org/doc/resources/downloads/status'
89
+ open(status) do |file|
90
+ if file.gets =~ /threads:\s+(\d+)/
91
+ threads = $1.to_i
92
+ end
93
+ end
94
+ threads
95
+ end
96
+ def drop_flag(flag = nil)
97
+ file = '/tmp/sbsm_drop_flag'
98
+ if flag != nil # write
99
+ lock do
100
+ open(file, 'w') do |f|
101
+ f.print flag.to_s
102
+ end
103
+ end
104
+ else # read
105
+ unless File.exist?(file)
106
+ lock do
107
+ open(file, 'w') do |f|
108
+ f.print false
109
+ flag = false
110
+ end
111
+ end
112
+ else
113
+ open(file, 'r') do |f|
114
+ flag = if f.gets.chomp =~ /true/
115
+ true
116
+ else
117
+ false
118
+ end
119
+ end
120
+ end
121
+ end
122
+ flag
123
+ end
124
+ def check_threads
125
+ time = Time.now.sec.to_i % 5
126
+ if time == 0
127
+ #if drb_server_threads > 50
128
+ if drb_server_threads > 30
129
+ drop_flag true
130
+ else
131
+ drop_flag false
132
+ end
133
+ end
134
+ end
135
+ def is_drop?
136
+ if unparsed_uri =~ /pointer/ or (drop_flag && is_crawler?)
137
+ true
138
+ end
139
+ end
77
140
  def drb_process
78
141
  args = {
79
142
  'database_manager' => CGI::Session::DRbSession,
80
143
  'drbsession_uri' => @drb_uri,
81
144
  'session_path' => '/',
82
145
  }
83
- if unparsed_uri =~ /pointer/
146
+ check_threads
147
+ if is_drop?
84
148
  return
85
149
  end
86
150
  if(is_crawler?)
data/lib/version.rb CHANGED
@@ -1 +1 @@
1
- VERSION = '1.1.2'
1
+ VERSION = '1.1.3'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sbsm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-22 00:00:00.000000000 Z
12
+ date: 2012-02-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdoc
16
- requirement: &17402320 !ruby/object:Gem::Requirement
16
+ requirement: &21162160 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.10'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *17402320
24
+ version_requirements: *21162160
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: hoe
27
- requirement: &17401900 !ruby/object:Gem::Requirement
27
+ requirement: &21161740 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '2.13'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *17401900
35
+ version_requirements: *21161740
36
36
  description: Application framework for state based session management
37
37
  email:
38
38
  - mhatakeyama@ywesee.com, zdavatz@ywesee.com