lib/zold/node/async_entrance.rb in zold-0.16.29 vs lib/zold/node/async_entrance.rb in zold-0.16.30
- old
+ new
@@ -34,16 +34,18 @@
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
# License:: MIT
module Zold
# The entrance
class AsyncEntrance
- def initialize(entrance, dir, log: Log::NULL, threads: [Concurrent.processor_count, 4].max)
+ def initialize(entrance, dir, log: Log::NULL,
+ threads: [Concurrent.processor_count, 8].max, queue_limit: 8)
@entrance = entrance
@dir = File.expand_path(dir)
@log = log
@total = threads
@queue = Queue.new
+ @queue_limit = queue_limit
end
def to_json
@entrance.to_json.merge(
'queue': @queue.size,
@@ -76,10 +78,10 @@
end
end
# Always returns an array with a single ID of the pushed wallet
def push(id, body)
- raise "Queue is too long (#{@queue.size} wallets), try again later" if @queue.size > 256
+ raise "Queue is too long (#{@queue.size} wallets), try again later" if @queue.size > @queue_limit
start = Time.now
loop do
uuid = SecureRandom.uuid
file = File.join(@dir, "#{id}-#{uuid}")
next if File.exist?(file)