File: import.rb

package info (click to toggle)
ruby-mongo 2.21.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 14,764 kB
  • sloc: ruby: 108,806; makefile: 5; sh: 2
file content (49 lines) | stat: -rw-r--r-- 1,165 bytes parent folder | download
1
2
3
4
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
46
47
48
49
# frozen_string_literal: true

require_relative 'base'
require_relative '../dispatcher'

module Mongo
  module DriverBench
    module Parallel
      module LDJSON
        # "This benchmark tests driver performance importing documents from a
        # set of LDJSON files."
        #
        # @api private
        class Import < Mongo::DriverBench::Parallel::LDJSON::Base
          bench_name 'LDJSON multi-file import'

          private

          # The data source for this benchmark. Each batch is the name of a
          # file to read documents file.
          class DataSource
            def initialize(bench)
              @n = 0
              @bench = bench
            end

            def next
              return nil if @n >= 100

              @bench.file_name_at(@n).tap { @n += 1 }
            end
          end

          def before_task
            super
            prepare_collection
            @dispatcher = Dispatcher.new(DataSource.new(self)) do |file_name|
              insert_docs_from_file(file_name)
            end
          end

          def do_task
            @dispatcher.run
          end
        end
      end
    end
  end
end