5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/cxf/helpers/threads_helper.rb', line 5
def make_multiple_request(calls)
set_threads_config
payload_to_return = []
now = Time.now
calls = [calls] if !calls.kind_of?(Array) || (calls.kind_of?(Array) && calls.first.kind_of?(String))
if @debug
puts "min_threads_per_pool: #{@min_threads_per_pool}"
puts "max_threads_per_pool: #{@max_threads_per_pool}"
puts "max_threads_queue: #{@max_threads_queue}"
end
pool = Concurrent::ThreadPoolExecutor.new(
min_threads: @min_threads_per_pool,
max_threads: @max_threads_per_pool,
max_queue: @max_threads_queue,
fallback_policy: :caller_runs
)
calls.each_with_index do |call_data, index|
pool.post do
begin
payload_to_return[index] = make_call(call_data)
rescue => e
payload_to_return[index] = e
end
end
end
pool.shutdown
pool.wait_for_termination
if @debug
end_time = Time.now
puts "Time to make all calls: #{end_time - now}"
end
payload_to_return
end
|