File tree Expand file tree Collapse file tree 2 files changed +21
-6
lines changed
Expand file tree Collapse file tree 2 files changed +21
-6
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
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
725end
826
9- # Zero iteration:
10- # 15_000 lines: 103 MB
27+ # Zero iteration: 103 MB
You can’t perform that action at this time.
0 commit comments