File tree Expand file tree Collapse file tree 2 files changed +24
-4
lines changed
Expand file tree Collapse file tree 2 files changed +24
-4
lines changed Original file line number Diff line number Diff 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 )
Original file line number Diff line number Diff line change 11require_relative 'main'
22
33class 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 ( count_lines )
8+ @count_lines = count_lines
9+ end
10+
11+ def call = [ memory_measurer_thread , work_thread ] . map ( &:join )
12+
13+ private
14+
15+ attr_reader :count_lines
16+
17+ def work_thread = Thread . new do
18+ Main . new ( options : { count_lines : } ) . call
19+ end
20+
21+ def memory_measurer_thread = Thread . new do
22+ sleep CHECK_USAGE_INTERVAL_SEC
23+ current_memory_usage_mb = `ps -o rss= -p #{ Process . pid } ` . to_i / 1024
24+ if current_memory_usage_mb > MEMORY_USAGE_LIMIT_MB
25+ puts "MEMORY USAGE: #{ current_memory_usage_mb } MB, BUT LIMIT: #{ MEMORY_USAGE_LIMIT_MB } "
26+ exit
27+ end
628 end
729end
830
You can’t perform that action at this time.
0 commit comments