See if leveldb will preform a little better

parent ce5e774c
......@@ -2,4 +2,4 @@
source 'https://rubygems.org'
gem 'mongo', '~> 2.4'
gem 'leveldb'
GEM
remote: https://rubygems.org/
specs:
bson (4.2.2)
mongo (2.4.3)
bson (>= 4.2.1, < 5.0.0)
fiddler-rb (0.1.2)
leveldb (0.1.9)
fiddler-rb (~> 0.1.1)
PLATFORMS
ruby
DEPENDENCIES
mongo (~> 2.4)
leveldb
BUNDLED WITH
1.16.0
......@@ -2,19 +2,14 @@
# frozen_string_literal: true
require 'digest'
require 'mongo'
require 'leveldb'
@buffersize = 1000
@buffersize = 10000
nthreads = 20
mongo_addr = '127.0.0.1:27017'
mongo_db = 'hashes'
# Connect to mongodb
Mongo::Logger.logger.level = Logger::FATAL
client = Mongo::Client.new([mongo_addr], database: mongo_db)
# Define our collection
@col = client[:hashes]
@md5db = LevelDB::DB.new 'md5.db'
@sha1db = LevelDB::DB.new 'sha1.db'
@sha256db = LevelDB::DB.new 'sha256.db'
# Define our read buffer
@buffer = SizedQueue.new @buffersize
......@@ -50,9 +45,24 @@ def process_buffer(b = [])
submit_results b unless b.size.zero?
end
# Submit calculated hashes to mongodb
# Submit calculated hashes to leveldb
def submit_results(results)
@col.insert_many(results)
# A little progress indication
puts results.first
md5b = @md5db.batch
sha1b = @sha1db.batch
sha256b = @sha256db.batch
results.each do |r|
md5b.put r[:md5], r[:password]
sha1b.put r[:sha1], r[:password]
sha256b.put r[:sha256], r[:password]
end
md5b.write!
sha1b.write!
sha256b.write!
end
# Fill password buffer
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment