Skip to content
This repository has been archived by the owner on Dec 22, 2020. It is now read-only.

Commit

Permalink
parallel import
Browse files Browse the repository at this point in the history
  • Loading branch information
awreece committed Nov 14, 2017
1 parent 1ee7f02 commit 0919a8b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/mosql/streamer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'Parallel'

module MoSQL
class Streamer
include MoSQL::Logging
Expand Down Expand Up @@ -106,7 +108,7 @@ def initial_import
db = @mongo.db(dbname)
collections = db.collections.select { |c| spec.key?(c.name) }

collections.each do |collection|
Parallel.each(collections, in_threads: 8) do |collection|
ns = "#{dbname}.#{collection.name}"
import_collection(ns, collection, spec[collection.name][:meta][:filter])
exit(0) if @done
Expand Down Expand Up @@ -156,7 +158,7 @@ def import_collection(ns, collection, filter)
if count % BATCH == 0
sql_time += upsert_all_batches(batches, ns)
elapsed = Time.now - start
log.info("Imported #{count} rows (#{elapsed}s, #{sql_time}s SQL)...")
log.info("Imported #{count} rows into #{collection} (#{elapsed}s, #{sql_time}s SQL)...")
exit(0) if @done
end
end
Expand Down
1 change: 1 addition & 0 deletions mosql.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Gem::Specification.new do |gem|
gem.add_runtime_dependency "rake"
gem.add_runtime_dependency "log4r"
gem.add_runtime_dependency "json"
gem.add_runtime_dependency "parallel"

gem.add_runtime_dependency "mongoriver", "0.4"

Expand Down

0 comments on commit 0919a8b

Please sign in to comment.