Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bulk push of jobs #58

Open
danwa5 opened this issue Jun 9, 2021 · 1 comment
Open

Bulk push of jobs #58

danwa5 opened this issue Jun 9, 2021 · 1 comment

Comments

@danwa5
Copy link

danwa5 commented Jun 9, 2021

I like to make a feature request for add support for pushing a large batch of jobs to the Faktory server, something similar to what Sidekiq offers with #push_bulk.

The network latency of enqueueing a job individually is starting to add up when dealing with a large data set.

Sample code

markers = ids.each_slice(10).to_a

markers.each do |m|
  SomeWorker.perform_async(m[0], m[-1])
end

Is there a workaround for something like this for the time being?

@mperham
Copy link
Contributor

mperham commented Jun 9, 2021

The only workaround today is to use a pool of connections and threads. Faktory does not offer a PUSH operation which takes multiple payloads. Here's sample code using 10 threads to push in parallel:

require 'faktory'
require 'thread'
require 'securerandom'

ids = (1..1000).to_a
q = Queue.new 
ids.each_slice(10).to_a.each {|m| q.push([m[0], m[-1]]) }
q.close

threads = []
10.times do |idx|
  job = { "jobtype": "SomeWorker", "queue": "default"  }
  threads << Thread.new do
    c = Faktory::Client.new(debug: true)
    while args = q.pop
      c.push(job.merge("args": q.pop, "jid": SecureRandom.hex(8)))
    end
    c.close
  end
end

threads.each(&:join)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants