Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ group :development, :testing do
gem 'rspec', '~> 3.0'
gem 'mime-types', '~> 1.25'
gem 'httparty'
gem 'yajl-ruby', require: 'yajl', platforms: :mri
gem 'celluloid', platforms: :mri
end

group :development do
Expand Down
155 changes: 155 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,158 @@ namespace :docs do
system "yardoc -o #{out} --title mongo-#{Mongo::VERSION}"
end
end

require_relative "profile/benchmarking"

# Some require data files, available from the drivers team. See the comments above each task for details."
namespace :benchmark do
desc "Run the driver benchmark tests."

namespace :micro do
desc "Run the common driver micro benchmarking tests"

namespace :flat do
desc "Benchmarking for flat bson documents."

# Requirement: A file in Mongo::Benchmarking::DATA_PATH, called flat_bson.json.
task :encode do
puts "MICRO BENCHMARK:: FLAT:: ENCODE"
Mongo::Benchmarking::Micro.run(:flat, :encode)
end

# Requirement: A file in Mongo::Benchmarking::DATA_PATH, called flat_bson.json.
task :decode do
puts "MICRO BENCHMARK:: FLAT:: DECODE"
Mongo::Benchmarking::Micro.run(:flat, :decode)
end
end

namespace :deep do
desc "Benchmarking for deep bson documents."

# Requirement: A file in Mongo::Benchmarking::DATA_PATH, called deep_bson.json.
task :encode do
puts "MICRO BENCHMARK:: DEEP:: ENCODE"
Mongo::Benchmarking::Micro.run(:deep, :encode)
end

# Requirement: A file in Mongo::Benchmarking::DATA_PATH, called deep_bson.json.
task :decode do
puts "MICRO BENCHMARK:: DEEP:: DECODE"
Mongo::Benchmarking::Micro.run(:deep, :decode)
end
end

namespace :full do
desc "Benchmarking for full bson documents."

# Requirement: A file in Mongo::Benchmarking::DATA_PATH, called full_bson.json.
task :encode do
puts "MICRO BENCHMARK:: FULL:: ENCODE"
Mongo::Benchmarking::Micro.run(:full, :encode)
end

# Requirement: A file in Mongo::Benchmarking::DATA_PATH, called full_bson.json.
task :decode do
puts "MICRO BENCHMARK:: FULL:: DECODE"
Mongo::Benchmarking::Micro.run(:full, :decode)
end
end
end

namespace :single_doc do
desc "Run the common driver single-document benchmarking tests"
task :command do
puts "SINGLE DOC BENCHMARK:: COMMAND"
Mongo::Benchmarking::SingleDoc.run(:command)
end

# Requirement: A file in Mongo::Benchmarking::DATA_PATH, called TWEET.json.
task :find_one do
puts "SINGLE DOC BENCHMARK:: FIND ONE BY ID"
Mongo::Benchmarking::SingleDoc.run(:find_one)
end

# Requirement: A file in Mongo::Benchmarking::DATA_PATH, called SMALL_DOC.json.
task :insert_one_small do
puts "SINGLE DOC BENCHMARK:: INSERT ONE SMALL DOCUMENT"
Mongo::Benchmarking::SingleDoc.run(:insert_one_small)
end

# Requirement: A file in Mongo::Benchmarking::DATA_PATH, called LARGE_DOC.json.
task :insert_one_large do
puts "SINGLE DOC BENCHMARK:: INSERT ONE LARGE DOCUMENT"
Mongo::Benchmarking::SingleDoc.run(:insert_one_large)
end
end

namespace :multi_doc do
desc "Run the common driver multi-document benchmarking tests"

# Requirement: A file in Mongo::Benchmarking::DATA_PATH, called TWEET.json.
task :find_many do
puts "MULTI DOCUMENT BENCHMARK:: FIND MANY"
Mongo::Benchmarking::MultiDoc.run(:find_many)
end

# Requirement: A file in Mongo::Benchmarking::DATA_PATH, called SMALL_DOC.json.
task :bulk_insert_small do
puts "MULTI DOCUMENT BENCHMARK:: BULK INSERT SMALL"
Mongo::Benchmarking::MultiDoc.run(:bulk_insert_small)
end

# Requirement: A file in Mongo::Benchmarking::DATA_PATH, called LARGE_DOC.json.
task :bulk_insert_large do
puts "MULTI DOCUMENT BENCHMARK:: BULK INSERT LARGE"
Mongo::Benchmarking::MultiDoc.run(:bulk_insert_large)
end

# Requirement: A file in Mongo::Benchmarking::DATA_PATH, called GRIDFS_LARGE.
task :gridfs_upload do
puts "MULTI DOCUMENT BENCHMARK:: GRIDFS UPLOAD"
Mongo::Benchmarking::MultiDoc.run(:gridfs_upload)
end

# Requirement: A file in Mongo::Benchmarking::DATA_PATH, called GRIDFS_LARGE.
task :gridfs_download do
puts "MULTI DOCUMENT BENCHMARK:: GRIDFS DOWNLOAD"
Mongo::Benchmarking::MultiDoc.run(:gridfs_download)
end
end

namespace :parallel do
desc "Run the common driver paralell ETL benchmarking tests"

# Requirement: A directory in Mongo::Benchmarking::DATA_PATH, called LDJSON_MULTI,
# with the files used in this task.
task :import do
puts "PARALLEL ETL BENCHMARK:: IMPORT"
Mongo::Benchmarking::Parallel.run(:import)
end

# Requirement: A directory in Mongo::Benchmarking::DATA_PATH, called LDJSON_MULTI,
# with the files used in this task.
# Requirement: Another directory in "#{Mongo::Benchmarking::DATA_PATH}/LDJSON_MULTI"
# called 'output'.
task :export do
puts "PARALLEL ETL BENCHMARK:: EXPORT"
Mongo::Benchmarking::Parallel.run(:export)
end

# Requirement: A directory in Mongo::Benchmarking::DATA_PATH, called GRIDFS_MULTI,
# with the files used in this task.
task :gridfs_upload do
puts "PARALLEL ETL BENCHMARK:: GRIDFS UPLOAD"
Mongo::Benchmarking::Parallel.run(:gridfs_upload)
end

# Requirement: A directory in Mongo::Benchmarking::DATA_PATH, called GRIDFS_MULTI,
# with the files used in this task.
# Requirement: Another directory in "#{Mongo::Benchmarking::DATA_PATH}/GRIDFS_MULTI"
# called 'output'.
task :gridfs_download do
puts "PARALLEL ETL BENCHMARK:: GRIDFS DOWNLOAD"
Mongo::Benchmarking::Parallel.run(:gridfs_download)
end
end
end
128 changes: 128 additions & 0 deletions profile/benchmarking.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# Copyright (C) 2015 MongoDB, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require 'benchmark'
require_relative 'benchmarking/helper'
require_relative 'benchmarking/micro'
require_relative 'benchmarking/single_doc'
require_relative 'benchmarking/multi_doc'
require_relative 'benchmarking/parallel'

module Mongo

# Module with all functionality for running driver benchmark tests.
#
# @since 2.2.3
module Benchmarking

extend self

# The current path.
#
# @return [ String ] The current path.
#
# @since 2.2.3
CURRENT_PATH = File.expand_path(File.dirname(__FILE__)).freeze

# The path to data files used in Benchmarking tests.
#
# @return [ String ] Path to Benchmarking test files.
#
# @since 2.2.3
DATA_PATH = [CURRENT_PATH, 'benchmarking', 'data'].join('/').freeze

# The file containing the single tweet document.
#
# @return [ String ] The file containing the tweet document.
#
# @since 2.2.3
TWEET_DOCUMENT_FILE = [DATA_PATH, 'TWEET.json'].join('/').freeze

# The file containing the single small document.
#
# @return [ String ] The file containing the small document.
#
# @since 2.2.3
SMALL_DOCUMENT_FILE = [DATA_PATH, 'SMALL_DOC.json'].join('/').freeze

# The file containing the single large document.
#
# @return [ String ] The file containing the large document.
#
# @since 2.2.3
LARGE_DOCUMENT_FILE = [DATA_PATH, 'LARGE_DOC.json'].join('/').freeze

# The file to upload when testing GridFS.
#
# @return [ String ] The file containing the GridFS test data.
#
# @since 2.2.3
GRIDFS_FILE = [DATA_PATH, 'GRIDFS_LARGE'].join('/').freeze

# The file path and base name for the LDJSON files.
#
# @return [ String ] The file path and base name for the LDJSON files.
#
# @since 2.2.3
LDJSON_FILE_BASE = [DATA_PATH, 'LDJSON_MULTI', 'LDJSON'].join('/').freeze

# The file path and base name for the outputted LDJSON files.
#
# @return [ String ] The file path and base name for the outputted LDJSON files.
#
# @since 2.2.3
LDJSON_FILE_OUTPUT_BASE = [DATA_PATH, 'LDJSON_MULTI', 'output', 'LDJSON'].join('/').freeze

# The file path and base name for the GRIDFS files to upload.
#
# @return [ String ] The file path and base name for the GRIDFS files to upload.
#
# @since 2.2.3
GRIDFS_MULTI_BASE = [DATA_PATH, 'GRIDFS_MULTI', 'file'].join('/').freeze

# The file path and base name for the outputted GRIDFS downloaded files.
#
# @return [ String ] The file path and base name for the outputted GRIDFS downloaded files.
#
# @since 2.2.3
GRIDFS_MULTI_OUTPUT_BASE = [DATA_PATH, 'GRIDFS_MULTI', 'output', 'file-output'].join('/').freeze

# The default number of test repetitions.
#
# @return [ Integer ] The number of test repetitions.
#
# @since 2.2.3
TEST_REPETITIONS = 100.freeze

# The number of default warmup repetitions of the test to do before
# recording times.
#
# @return [ Integer ] The default number of warmup repetitions.
#
# @since 2.2.3
WARMUP_REPETITIONS = 10.freeze

def tweet_document
Benchmarking.load_file(TWEET_DOCUMENT_FILE).first
end

def small_document
Benchmarking.load_file(SMALL_DOCUMENT_FILE).first
end

def large_document
Benchmarking.load_file(LARGE_DOCUMENT_FILE).first
end
end
end
59 changes: 59 additions & 0 deletions profile/benchmarking/helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
module Mongo

# Helper functions used by benchmarking tasks
module Benchmarking

extend self

# Load a json file and represent each document as a Hash.
#
# @example Load a file.
# Benchmarking.load_file(file_name)
#
# @param [ String ] The file name.
#
# @return [ Array ] A list of extended-json documents.
#
# @since 2.2.3
def load_file(file_name)
File.open(file_name, "r") do |f|
f.each_line.collect do |line|
parse_json(line)
end
end
end

# Load a json document as a Hash and convert BSON-specific types.
# Replace the _id field as an BSON::ObjectId if it's represented as '$oid'.
#
# @example Parse a json document.
# Benchmarking.parse_json(document)
#
# @param [ Hash ] The json document.
#
# @return [ Hash ] An extended-json document.
#
# @since 2.2.3
def parse_json(document)
JSON.parse(document).tap do |doc|
if doc['_id'] && doc['_id']['$oid']
doc['_id'] = BSON::ObjectId.from_string(doc['_id']['$oid'])
end
end
end

# Get the median of values in a list.
#
# @example Get the median.
# Benchmarking.median(values)
#
# @param [ Array ] The values to get the median of.
#
# @return [ Numeric ] The median of the list.
#
# @since 2.2.3
def median(values)
values.sort![values.size/2-1]
end
end
end
Loading