Module: TestingMemory
- Defined in:
- lib/testing_memory/testing_memory.rb
Overview
Runs a memory test:
-
Run content server or backup server
-
Generate files.
-
Monitor files.
-
Index files.
-
Report memory of proces at different phasestimes
Examples:
testing_server --conf_file=~/.bbfs/etc/backup_testing_memory.yml --server_to_test=backup
testing_server --conf_file=~/.bbfs/etc/content_testing_memory.yml --server_to_test=content
Class Method Summary collapse
- .check_memory_loop ⇒ Object
- .generate_mem_report ⇒ Object
- .init_log4r ⇒ Object
- .run_backup_memory_server ⇒ Object
- .run_content_memory_server ⇒ Object
- .send_email(report) ⇒ Object
Class Method Details
.check_memory_loop ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/testing_memory/testing_memory.rb', line 110 def check_memory_loop start_time = Time.now $testing_memory_log.info(Params['testing_title']) total_files = Params['total_created_directories']*Params['total_files_in_dir'] $testing_memory_log.info("Start check all files:#{total_files} are indexed") Params..each { |msg| $testing_memory_log.info(msg) } email_report = generate_mem_report # memory loop loop { sleep(Params['memory_count_delay']) email_report += generate_mem_report email_report += "indexed files:#{$indexed_file_count}\n" $testing_memory_log.info("indexed files:#{$indexed_file_count}") puts("indexed files:#{$indexed_file_count}") #puts("symobles size:#{Symbol.all_symbols.size}") if total_files == $indexed_file_count stop_time = Time.now email_report += "\nAt this point all files are indexed. No mem changes should occur\n" $testing_memory_log.info("Total indexing time = #{stop_time.to_i - start_time.to_i}[S]") $testing_memory_log.info("\nAt this point all files are indexed. No mem changes should occur\n") loop { sleep(Params['memory_count_delay']) email_report += generate_mem_report } #send_email("Final report:#{email_report}\nprocess memory:#{memory_of_process}\n") end } end |
.generate_mem_report ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/testing_memory/testing_memory.rb', line 142 def generate_mem_report # Generate memory report current_objects_counters = {} count = ObjectSpace.each_object(String).count current_objects_counters['String'] = count count = ObjectSpace.each_object(ContentData::ContentData).count current_objects_counters['ContentData'] = count dir_count = ObjectSpace.each_object(FileMonitoring::DirStat).count current_objects_counters['DirStat'] = dir_count file_count = ObjectSpace.each_object(FileMonitoring::FileStat).count current_objects_counters['FileStat'] = file_count # Generate report and update global counters report = "" current_objects_counters.each_key { |type| report += "Type:#{type} count:#{current_objects_counters[type]} \n" } unless Gem::win_platform? memory_of_process = `ps -o rss= -p #{Process.pid}`.to_i / 1000 else memory_of_process = `tasklist /FI \"PID eq #{Process.pid}\" /NH /FO \"CSV\"`.split(',')[4] end final_report = "Time:#{Time.now}. Process memory:#{memory_of_process}[M]\nCount report:\n#{report}" puts "Process memory:#{memory_of_process}[M]" $testing_memory_log.info(final_report) final_report end |
.init_log4r ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/testing_memory/testing_memory.rb', line 28 def init_log4r #init log4r log_path = Params['testing_log_path'] unless log_path raise("pls specify testing log path through param:'testing_log_path'") end log_dir = File.dirname(log_path) FileUtils.mkdir_p(log_dir) unless File.exists?(log_dir) $testing_memory_log = Log4r::Logger.new 'BBFS testing server log' $testing_memory_log.trace = true formatter = Log4r::PatternFormatter.new(:pattern => "[%d] [%m]") #file setup file_config = { "filename" => Params['testing_log_path'], "trunc" => true } file_outputter = Log4r::FileOutputter.new("testing_log", file_config) file_outputter.level = Log4r::INFO file_outputter.formatter = formatter $testing_memory_log.outputters << file_outputter end |
.run_backup_memory_server ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/testing_memory/testing_memory.rb', line 81 def run_backup_memory_server $testing_memory_active = true # this activates debug messages to console Log.info('Testing server started') #Init log init_log4r $testing_memory_log.info('Testing server started') #create files if Params['generate_files'] total_files = Params['total_created_directories']*Params['total_files_in_dir'] $testing_memory_log.info("Creating #{total_files} files") fg = FileGenerator::FileGenerator.new fg.run $testing_memory_log.info('Finished creating files') end # run backup Thread.new do ContentServer.run_backup_server end # run memory report cycles check_memory_loop raise("code should never reach here") end |
.run_content_memory_server ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/testing_memory/testing_memory.rb', line 51 def run_content_memory_server $testing_memory_active = true # this activates debug messages to console Log.info('Testing server started') #Init log init_log4r $testing_memory_log.info('Testing server started') #create files if Params['generate_files'] total_files = Params['total_created_directories']*Params['total_files_in_dir'] $testing_memory_log.info("Creating #{total_files} files") fg = FileGenerator::FileGenerator.new fg.run $testing_memory_log.info('Finished creating files') end # run backup Thread.new do ContentServer.run_content_server end # run memory report cycles check_memory_loop raise("code should never reach here") end |
.send_email(report) ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/testing_memory/testing_memory.rb', line 171 def send_email(report) msg =<<EOF #{report} EOF Email.send_email(Params['from_email'], Params['from_email_password'], Params['to_email'], 'Memory server update', msg) end |