Skip to content

Commit

Permalink
Merge pull request #50 from zendesk/bevans/limit_ultragrep_concurrency
Browse files Browse the repository at this point in the history
Allow configuring a sane upper limit on IO threads
  • Loading branch information
Nebopolis committed May 16, 2017
2 parents f235f78 + a9dc298 commit 26fb7d0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
26 changes: 14 additions & 12 deletions lib/ultragrep.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ def ultragrep(options)
exit 1
end

concurrency_limit = config.fetch('concurrency_limit', ifnone = file_lists.length)
request_printer = options.fetch(:printer)
request_printer.run

Expand All @@ -201,24 +202,25 @@ def ultragrep(options)
regexps += options[:not_regexps].map { |r| "!" + r } if options[:not_regexps]

quoted_regexps = quote_shell_words(regexps)

file_lists.each do |files|
print_search_list(files) if options[:verbose]

children_pipes = files.map do |file|
[worker(file, lua, quoted_regexps, options), file]
end
files.each_slice(concurrency_limit) do |sliced_files|
children_pipes = sliced_files.map do |file|
[worker(file, lua, quoted_regexps, options), file]
end

children_pipes.each do |pipe, _|
request_printer.set_read_up_to(pipe, 0)
end
children_pipes.each do |pipe, _|
request_printer.set_read_up_to(pipe, 0)
end

# each thread here waits for child data and then pushes it to the printer thread.
children_pipes.map do |pipe, filename|
worker_reader(filename, pipe, request_printer, options)
end.each(&:join)
# each thread here waits for child data and then pushes it to the printer thread.
children_pipes.map do |pipe, filename|
worker_reader(filename, pipe, request_printer, options)
end.each(&:join)

Process.waitall
Process.waitall
end
end

request_printer.finish
Expand Down
1 change: 1 addition & 0 deletions ultragrep.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ types:
format: json
glob: /Users/*/storage/logs/hosts/*/*/*/*app*/production.log-*.json
default_type: app
concurrency_limit: 10

0 comments on commit 26fb7d0

Please sign in to comment.