Skip to content

Commit 56c15de

Browse files
NikitaNikita
authored andcommitted
[Zero Iteration] add control measuring thread in measurer
1 parent 6b6ca76 commit 56c15de

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

main.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ def work
112112
end
113113

114114
File.write('result.json', "#{report.to_json}\n")
115-
116-
puts "MEMORY USAGE: #{(`ps -o rss= -p #{Process.pid}`.to_i / 1024)} MB" if is_print_memory_usage
117115
end
118116

119117
def parse_user(user)

measurer.rb

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
11
require_relative 'main'
22

33
class Measurer
4-
def call
5-
Main.new(options: { count_lines: 15_000, is_print_memory_usage: true }).call
4+
MEMORY_USAGE_LIMIT_MB = 70
5+
CHECK_USAGE_INTERVAL_SEC = 1
6+
7+
def initialize
8+
9+
def call = [memory_measurer_thread, work_thread].map(&:join)
10+
11+
private
12+
13+
attr_reader :count_lines
14+
15+
def work_thread = Thread.new { Main.new.call }
16+
17+
def memory_measurer_thread = Thread.new do
18+
sleep CHECK_USAGE_INTERVAL_SEC
19+
current_memory_usage_mb = `ps -o rss= -p #{Process.pid}`.to_i / 1024
20+
if current_memory_usage_mb > MEMORY_USAGE_LIMIT_MB
21+
puts "MEMORY USAGE: #{current_memory_usage_mb} MB, BUT LIMIT: #{MEMORY_USAGE_LIMIT_MB}"
22+
exit
23+
end
624
end
725
end
826

9-
# Zero iteration:
10-
# 15_000 lines: 103 MB
27+
# Zero iteration: 103 MB

0 commit comments

Comments
 (0)