diff --git a/doc/index.rbx b/doc/index.rbx index 6227145..1096f51 100755 --- a/doc/index.rbx +++ b/doc/index.rbx @@ -6,10 +6,27 @@ require '/usr/local/lib/ruby/gems/1.9.1/gems/sbsm-1.1.4/lib/sbsm/request' require 'util/oddbconfig' +def drb_server_threads + threads = 0 + status = File.expand_path('../doc/resources/downloads/status', File.dirname(__FILE__)) + if File.exist?(status) + open(status) do |file| + if file.gets =~ /threads:\s+(\d+)/ + threads = $1.to_i + end + end + end + threads +end + DRb.start_service('druby://localhost:0') begin - SBSM::Request.new(ODDB::SERVER_URI).process + if drb_server_threads < 30 + SBSM::Request.new(ODDB::SERVER_URI).process + else + SBSM::Request.new(ODDB::SECOND_URI).process + end rescue Exception => e $stderr << "ODDB-Client-Error: " << e.message << "\n" $stderr << e.class << "\n" diff --git a/src/util/oddbapp.rb b/src/util/oddbapp.rb index c860ec4..0c4d54e 100644 --- a/src/util/oddbapp.rb +++ b/src/util/oddbapp.rb @@ -1,6 +1,6 @@ #!/usr/bin/env ruby # encoding: utf-8 -# OddbApp -- oddb.org -- 21.02.2012 -- mhatakeyama@ywesee.com +# OddbApp -- oddb.org -- 28.02.2012 -- mhatakeyama@ywesee.com # OddbApp -- oddb.org -- 21.06.2010 -- hwyss@ywesee.com require 'yaml' @@ -1318,6 +1318,28 @@ class OddbPrevalence end end end + def check_second_server + if @second_server_pid + pids = [] + IO.popen("ps aux|grep -i oddb") {|io| + while line = io.gets + pids << line.split[1] + end + } + pids.include?(@second_server_pid.to_s) + end + end + def start_second_server + unless check_second_server + command = File.expand_path('../../bin/oddbd2', File.dirname(__FILE__)) + @second_server_pid = spawn('/usr/local/bin/ruby', command) + end + end + attr_reader :second_server_pid + def kill_second_server + Process.kill('KILL', @second_server_pid) + @second_server_pid = nil + end private def create_unknown_galenic_group unless(@galenic_groups.is_a?(Hash) && @galenic_groups.size > 0) @@ -1364,7 +1386,7 @@ module ODDB puts "reset" reset() puts "reset: #{Time.now - start}" - log_size + log_size opts[:second_server] puts "system initialized" puts "initialized: #{Time.now - start}" end @@ -1910,7 +1932,7 @@ module ODDB raise end - def log_size + def log_size(second_server) @size_logger = Thread.new { time = Time.now bytes = 0 @@ -1928,6 +1950,10 @@ module ODDB if threads > 150 exit end + # Create a new process if more than xx threads are created + if threads > 20 and !second_server and !@system.check_second_server + @system.start_second_server + end lastbytes = bytes bytes = File.read("/proc/#{$$}/stat").split(' ').at(22).to_i mbytes = bytes / (2**20) @@ -1941,8 +1967,12 @@ module ODDB gc << 'S' if sessions < lastsessions gc << 'T' if threads < lastthreads gc << 'M' if bytes < lastbytes - path = File.expand_path('../../doc/resources/downloads/status', - File.dirname(__FILE__)) + file = unless second_server + "../../doc/resources/downloads/status" + else + "../../doc/resources/downloads/status2" + end + path = File.expand_path(file, File.dirname(__FILE__)) lines = File.readlines(path)[0,100] rescue [] lines.unshift sprintf(format, alarm, time.strftime('%Y-%m-%d %H:%M:%S'), @@ -1955,7 +1985,7 @@ module ODDB puts e.message $stdout.flush end - sleep 5 + sleep 5 } } end diff --git a/src/util/oddbconfig.rb b/src/util/oddbconfig.rb index dbbbf19..538a0fa 100644 --- a/src/util/oddbconfig.rb +++ b/src/util/oddbconfig.rb @@ -1,6 +1,6 @@ #!/usr/bin/env ruby # encoding: utf-8 -# OddbConfig -- oddb.org -- 11.01.2012 -- mhatakeyama@ywesee.com +# OddbConfig -- oddb.org -- 28.02.2012 -- mhatakeyama@ywesee.com # OddbConfig -- oddb.org -- 09.04.2003 -- hwyss@ywesee.com # Do not require any Application-Internals in this file @@ -15,6 +15,7 @@ module ODDB MAIL_TO = ['hwyss@ywesee.com'] SMTP_FROM = 'zdavatz@ywesee.com' SERVER_URI = "druby://localhost:10000" + SECOND_URI = "druby://localhost:22222" FIPARSE_URI = "druby://localhost:10002" FIPDF_URI = "druby://localhost:10003" DOCPARSE_URI = "druby://localhost:10004"